Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initBody: function () {
var shape,
el = this.el,
data = this.data,
pos = el.getComputedAttribute('position'),
options = data.shape === 'auto' ? undefined : AFRAME.utils.extend({}, this.data, {
type: mesh2shape.Type[data.shape.toUpperCase()]
});
// Matrix World must be updated at root level, if scale is to be applied – updateMatrixWorld()
// only checks an object's parent, not the rest of the ancestors. Hence, a wrapping entity with
// scale="0.5 0.5 0.5" will be ignored.
// Reference: https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js#L511-L541
// Potential fix: https://github.com/mrdoob/three.js/pull/7019
this.el.object3D.updateMatrixWorld(true);
shape = mesh2shape(this.el.object3D, options);
if (!shape) {
this.el.addEventListener('model-loaded', this.initBody.bind(this));
return;
}
this.body = new CANNON.Body({
quaternion: new CANNON.Quaternion(quat.x, quat.y, quat.z, quat.w),
linearDamping: data.linearDamping,
angularDamping: data.angularDamping,
type: data.type === 'dynamic' ? CANNON.Body.DYNAMIC : CANNON.Body.STATIC,
});
// Matrix World must be updated at root level, if scale is to be applied – updateMatrixWorld()
// only checks an object's parent, not the rest of the ancestors. Hence, a wrapping entity with
// scale="0.5 0.5 0.5" will be ignored.
// Reference: https://github.com/mrdoob/three.js/blob/master/src/core/Object3D.js#L511-L541
// Potential fix: https://github.com/mrdoob/three.js/pull/7019
this.el.object3D.updateMatrixWorld(true);
if(data.shape !== 'none') {
var options = data.shape === 'auto' ? undefined : AFRAME.utils.extend({}, this.data, {
type: mesh2shape.Type[data.shape.toUpperCase()]
});
var shape = mesh2shape(this.el.object3D, options);
if (!shape) {
el.addEventListener('object3dset', this.initBody.bind(this));
return;
}
this.body.addShape(shape, shape.offset, shape.orientation);
// Show wireframe
if (this.system.debug) {
this.shouldUpdateWireframe = true;
}
this.isLoaded = true;