From 500dd298bec37013c34bc70e8b23168729aff554 Mon Sep 17 00:00:00 2001 From: Erno Kuusela Date: Tue, 4 Mar 2014 15:06:01 +0200 Subject: [PATCH] Code ready to handle EC_RigidBody boxes --- src/app.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/app.js b/src/app.js index db94e32..cd7a7f1 100644 --- a/src/app.js +++ b/src/app.js @@ -44,6 +44,10 @@ Application.prototype = { this.dataConnection.scene.componentAdded.add(this.viewer.onComponentAddedOrChanged.bind(this.viewer)); this.dataConnection.scene.componentRemoved.add(this.viewer.onComponentRemoved.bind(this.viewer)); + + this.dataConnection.scene.componentAdded.add( + this.onRigidBodyPossiblyAdded.bind(this)); + // an alternative to hooking per component attributeChanged signals, // would simplify business registering/unregistering handlers in // component lifetime mgmt: @@ -192,3 +196,33 @@ function check() { } } +Application.prototype.onRigidBodyPossiblyAdded = function(entity, component) { + if (! (component instanceof EC_RigidBody)) + return; + + + var onRigidBodyAttributeChanged = function(changedAttr, changeType) { + //console.log("onRigidBodyAddedOrChanged due to attributeChanged ->", changedAttr.ref); + if (component.shapeType !== 0) { + console.log("unhandled shape type " + component.shapeType); + return; + } + var physiCube = component.physiCube; + if (!physiCube) { + component.physiCube = physiCube = new THREE.Mesh( + new THREE.CubeGeometry(1, 1, 1), + this.viewer.wireframeMaterial); + physiCube.mass = 0; + var threeGroup = this.viewer.o3dByEntityId[entity.id]; + threeGroup.add(physiCube); + } + console.log("ok, have cube"); + var boxSize = component.size; + if (!(boxSize.x && boxSize.y && boxSize.z)) + console.log("RigidBody of entitity " + entity.id + ": one or more dimensions are zero"); + physiCube.scale.set(boxSize.x, boxSize.y, boxSize.z); + console.log("box updated"); + }.bind(this); + onRigidBodyAttributeChanged(); + component.attributeChanged.add(onRigidBodyAttributeChanged); +};