Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assignSkeleton(bone) {
if (bone.name === 'root') {
bone.originalUp = new THREE.Vector3(0, 1, 0);
} else {
// bone.posRef is the link between this bone and our BONES array
const index = parseInt(bone.name.split('_')[1], 10);
bone.posRef = index + 1;
bone.originalUp = new THREE.Vector3(0, 1, 0).applyQuaternion(bone.quaternion).normalize();
// save original length for retargeting
bone.originalLength = bone.position.length();
}
// arrow helpers to assist with bone directions
bone.originalForward = new THREE.Vector3(0, 0, 1).transformDirection(bone.matrixWorld);
bone.arrowHelper = new THREE.ArrowHelper(bone.originalForward,
bone.getWorldPosition(new THREE.Vector3()), 0.08, 0xff0000);
bone.arrowHelper.visible = false;
this.scene.add(bone.arrowHelper);
bone.upArrowHelper = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0).transformDirection(bone.matrixWorld),
bone.getWorldPosition(new THREE.Vector3()), 0.08, 0x0000ff,
);
bone.upArrowHelper.visible = false;
this.scene.add(bone.upArrowHelper);
// repeat down the heirarchy
bone.children.forEach((child) => {
this.assignSkeleton(child);
});
}
veuler: null,
pos: null
};
let canFall = false;
const x = data.getInt16(offset + 2, true);
const y = data.getInt16(offset + 4, true);
const z = data.getInt16(offset + 6, true);
// assigned based on type of bone animation (rotation or translation)
if (boneframe.type === 0) { // rotation
boneframe.pos = new THREE.Vector3(0, 0, 0);
boneframe.veuler = new THREE.Vector3(x, y, z);
} else { // translation
boneframe.veuler = new THREE.Vector3(0, 0, 0);
boneframe.pos = new THREE.Vector3(
x * WORLD_SCALE,
y * WORLD_SCALE,
z * WORLD_SCALE
);
canFall = true;
}
return { boneframe, canFall };
}
const vs = new THREE.Vector3();
vs.subVectors(va, vRayStart);
const dot = vs.dot(vTriNormal);
const t = dot / vTriNormal.x;
const vInter = new THREE.Vector3(vRayStart.x, vRayStart.y, vRayStart.z);
vInter.x += t;
// project all points onto plane
const xAxis = new THREE.Vector3();
const yAxis = new THREE.Vector3();
xAxis.subVectors(vb, va);
xAxis.normalize();
yAxis.crossVectors(xAxis, vTriNormal);
// projection onto plane
const p0 = new THREE.Vector3(0.0, 0.0, 0.0);
const p1 = new THREE.Vector3(0.0, 0.0, 0.0);
const p2 = new THREE.Vector3(0.0, 0.0, 0.0);
const p = new THREE.Vector3(0.0, 0.0, 0.0);
p1.set((vb.x - va.x) * xAxis.x + (vb.y - va.y) * xAxis.y + (vb.z - va.z) * xAxis.z,
(vb.x - va.x) * yAxis.x + (vb.y - va.y) * yAxis.y + (vb.z - va.z) * yAxis.z,
0.0);
p2.set((vc.x - va.x) * xAxis.x + (vc.y - va.y) * xAxis.y + (vc.z - va.z) * xAxis.z,
(vc.x - va.x) * yAxis.x + (vc.y - va.y) * yAxis.y + (vc.z - va.z) * yAxis.z,
0.0);
p.set((vInter.x - va.x) * xAxis.x + (vInter.y - va.y) * xAxis.y + (vInter.z - va.z) * xAxis.z,
(vInter.x - va.x) * yAxis.x + (vInter.y - va.y) * yAxis.y + (vInter.z - va.z) * yAxis.z,
0.0);
// check point s in inside triangle a, b, c
private isNormalizedNormalAttribute(normal: BufferAttribute | InterleavedBufferAttribute) {
if (this.cachedData.attributesNormalized.has(normal)) {
return false;
}
const v = new Vector3();
let i = 0;
const il = normal.count;
for (; i < il; i++) {
// 0.0005 is from glTF-validator
if (Math.abs(v.fromArray(normal.array as number[], i * 3).length() - 1.0) > 0.0005) {
return false;
}
}
return true;
}
expect(arrowHelper.position.x,
'Arrow helper position should equal the origin parameter').to.equal(1);
expect(arrowHelper.position.y,
'Arrow helper position should equal the origin parameter').to.equal(2);
expect(arrowHelper.position.z,
'Arrow helper position should equal the origin parameter').to.equal(3);
ReactDOM.render(
, testDiv);
sinon.assert.calledOnce(arrowHelperRef);
expect(arrowHelper.position.x,
'Arrow helper position should update to new origin parameter').to.equal(7);
expect(arrowHelper.position.y,
'Arrow helper position should update to new origin parameter').to.equal(8);
expect(arrowHelper.position.z,
'Arrow helper position should update to new origin parameter').to.equal(9);
});
function makeLight(threeScene, ambience) {
const light = new THREE.DirectionalLight();
light.name = 'light';
light.position.set(-1000, 0, 0);
light.position.applyAxisAngle(
new THREE.Vector3(0, 0, 1),
-(ambience.lightingAlpha * 2 * Math.PI) / 0x1000
);
light.position.applyAxisAngle(
new THREE.Vector3(0, 1, 0),
-(ambience.lightingBeta * 2 * Math.PI) / 0x1000
);
light.updateMatrix();
light.matrixAutoUpdate = false;
threeScene.add(light);
}
function cube(size) {
var h = size.clone().multiplyScalar(0.5);
var geometry = new THREE.Geometry();
var line = new THREE.Line(geometry);
geometry.vertices.push(
new THREE.Vector3(-h.x, -h.y, -h.z),
new THREE.Vector3(-h.x, h.y, -h.z),
new THREE.Vector3(-h.x, h.y, -h.z),
new THREE.Vector3(h.x, h.y, -h.z),
new THREE.Vector3(h.x, h.y, -h.z),
new THREE.Vector3(h.x, -h.y, -h.z),
new THREE.Vector3(h.x, -h.y, -h.z),
new THREE.Vector3(-h.x, -h.y, -h.z),
new THREE.Vector3(-h.x, -h.y, h.z),
new THREE.Vector3(-h.x, h.y, h.z),
new THREE.Vector3(-h.x, h.y, h.z),
new THREE.Vector3(h.x, h.y, h.z),
new THREE.Vector3(h.x, h.y, h.z),
new THREE.Vector3(h.x, -h.y, h.z),
new THREE.Vector3(h.x, -h.y, h.z),
new THREE.Vector3(-h.x, -h.y, h.z),
new THREE.Vector3(-h.x, -h.y, -h.z),
new THREE.Vector3(-h.x, -h.y, h.z),
.then((cube) => {
cube.applyMatrix(new THREE.Matrix4().makeTranslation((element.to[0] - element.from[0]) / 2, (element.to[1] - element.from[1]) / 2, (element.to[2] - element.from[2]) / 2));
cube.applyMatrix(new THREE.Matrix4().makeTranslation(element.from[0], element.from[1], element.from[2]));
if (element.rotation) {
rotateAboutPoint(cube,
new THREE.Vector3(element.rotation.origin[0], element.rotation.origin[1], element.rotation.origin[2]),
new THREE.Vector3(element.rotation.axis === "x" ? 1 : 0, element.rotation.axis === "y" ? 1 : 0, element.rotation.axis === "z" ? 1 : 0),
toRadians(element.rotation.angle));
}
resolve(cube);
})
}));
function getAxes() {
return [
getAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(3, 0, 0), 0xff0000),
getAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 3, 0), 0x00ff00),
getAxis(new THREE.Vector3(0, 0, 0), new THREE.Vector3(0, 0, 3), 0x0000ff),
];
}
constructor(group: SphereColliderGroup, offset: THREE.Vector3, radius: number) {
this.group = group;
this.offset = offset.clone();
this.radius = radius;
this.worldPosition = new THREE.Vector3();
this.update();
}