-
Notifications
You must be signed in to change notification settings - Fork 137
Conversation
…oundShapes" (json blob defining attributes of primitive shapes), that creates a body with those primitives as shapes. Also, update the wireframe code to support this, and fix it to correctly display offsets.
If `type === none` in `body` component, body initialization will be delayed until a `shape` component is added. currently shapes can be added but not removed. debug wireframe updates accordingly.
+1 for this idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition, thanks! 🙂
src/components/body/body.js
Outdated
} | ||
}, | ||
|
||
addShape(shapeData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not using ES6 syntax here yet, so this must be:
addShape: function (shapeData) {
src/components/body/body.js
Outdated
} | ||
|
||
var type = shapeData.shape; | ||
var scale = this.el.object3D.scale; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get world-space scale:
var scale = new THREE.Vector3();
this.el.object3D.getWorldScale( scale );
src/components/body/body.js
Outdated
orientation.y, | ||
orientation.z, | ||
orientation.w | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think wireframe.quaternion.copy(orientation)
should work here, right? unless there was some hitch between the cannonjs and threejs quaternion...
} | ||
|
||
if (orientation) { | ||
orientation.inverse(orientation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a reference to a quaternion still in body.shapeOrientations
, so I think we want to make a copy before inverting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add .clone() where orientation
is set.
orientation = this.body.shapeOrientations[i].clone(),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nevermind that's a threejs method, not a cannonjs one.
src/components/shape/shape.js
Outdated
radiusTop: {type: 'number', default: 1}, | ||
radiusBottom: {type: 'number', default: 1}, | ||
height: {type: 'number', default: 1}, | ||
numSegments: {type: 'int', default: 8} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's prefix these properties:
sphereRadius
boxHalfExtents
cylinderRadiusTop
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not to- I really like that this exactly matches what those properties are called in threejs. (Selfishly I am also writing some tooling upstream of this that I don't want to have to constantly try to remember what the properties are supposed to be called). I would argue that if we want to be more explicit, we should add the other shape components back in (sphere-shape
, box-shape
, cylinder-shape
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a updateSchema
handler a la geometry
that makes the right properties available for the selected shape? That may provide the same clarity of purpose as prefixing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm fine with keeping the names then. But even easier than updateSchema
, we can do this:
radiusTop: { type: 'number', default: 1, if: {shape: ['cylinder']} }
...
src/components/shape/shape.js
Outdated
return 'dynamic-body'; | ||
} else if (el.components.hasOwnProperty('static-body')) { | ||
return'static-body'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would do el.hasAttribute('foo-body')
here instead
src/components/shape/shape.js
Outdated
this.bodyEl = this.bodyEl.parentNode; | ||
type = this._findType(this.bodyEl); | ||
} | ||
this.bodyEl.components[type].addShape(this.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about having the shape
component construct a CANNON.Shape
instance and pass that into components.body.addShape( shape )`?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have to think about that one- I vaguely recall I had a reason not to do that, but that might not be the case anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, feels cleaner IMO but if there's some issue we can leave it alone for now.
remove: function() { | ||
if (this.bodyEl.parentNode) { | ||
console.warn('removing shape component not currently supported'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case where remove
could be called but no parent node exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the parent is removed first we don't need to warn about the shape being removed.
…e rotation of cylinder shapes similar to how mesh2shape does it (rotate by 90 degrees). Fix various bugs.
Nice work, thanks! Will test this out a bit and then cut a new release. |
Published 3.1.0. 🎊 |
It looks like compound colliders break when an orientation property is specified (3.3.0) for any component shape; an alternative is using the constraint functionality to create a complex physics body (rotation seems to work fine for primitive body shapes) but I'm worried about overhead with this methodology. Looking into using wmurphyrd's aframe-physics-extras for this |
Add a
shape
component that when attached to an entity (or child entity) using abody
withshape: none
updates the shapes on the CANNON.Body. This enables an easy way to define abody
made of multiple primitive shapes, which should be a performant alternative to using convex hulls.The updating of the body is delayed until
tick
so that if multipleshape
components are defined, the body is only updated once. Does not currently support removing of shapes.Also updated the wireframe code in
body
to handle shape offsets and orientations correctly, as well as multiple shapes per body.