UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

29 lines (28 loc) 1 kB
"use strict"; import { LineBasicMaterial, BufferGeometry, LineSegments, BufferAttribute } from "three"; import { PhysicsIdAttribute } from "./PhysicsAttribute"; import { physicsWorldFromNodeId } from "./PhysicsWorld"; import { coreObjectClassFactory } from "../geometry/CoreObjectFactory"; export function physicsCreateDebugObject() { return new LineSegments( new BufferGeometry(), new LineBasicMaterial({ color: 16777215, vertexColors: true }) ); } export function updatePhysicsDebugObject(debugObject) { const nodeId = coreObjectClassFactory(debugObject).attribValue(debugObject, PhysicsIdAttribute.DEBUG_WORLD); if (nodeId == null) { return; } const world = physicsWorldFromNodeId(nodeId); if (!world) { return; } const buffers = world.debugRender(); const geometry = debugObject.geometry; geometry.setAttribute("position", new BufferAttribute(buffers.vertices, 3)); geometry.setAttribute("color", new BufferAttribute(buffers.colors, 4)); }