Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook to handle EC_RigidBody boxes using Physijs #41

Merged
merged 1 commit into from
Mar 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed a typo in the log message, i've written this sometimes too :) "entitity"

physiCube.scale.set(boxSize.x, boxSize.y, boxSize.z);
console.log("box updated");
}.bind(this);
onRigidBodyAttributeChanged();
component.attributeChanged.add(onRigidBodyAttributeChanged);
};