Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Ignore the TRS of skinned nodes.
// See https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins (second implementation note)
if (node.skin != undefined) {
return;
}
let position = Vector3.Zero();
let rotation = Quaternion.Identity();
let scaling = Vector3.One();
if (node.matrix) {
const matrix = Matrix.FromArray(node.matrix);
matrix.decompose(scaling, rotation, position);
}
else {
if (node.translation) { position = Vector3.FromArray(node.translation); }
if (node.rotation) { rotation = Quaternion.FromArray(node.rotation); }
if (node.scale) { scaling = Vector3.FromArray(node.scale); }
}
babylonNode.position = position;
babylonNode.rotationQuaternion = rotation;
babylonNode.scaling = scaling;
}
private _getNodeMatrix(node: INode): Matrix {
return node.matrix ?
Matrix.FromArray(node.matrix) :
Matrix.Compose(
node.scale ? Vector3.FromArray(node.scale) : Vector3.One(),
node.rotation ? Quaternion.FromArray(node.rotation) : Quaternion.Identity(),
node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
}
(vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));
(vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + stride));
}
break;
}
case VertexBuffer.ColorKind: {
const size = vertexBuffer.getSize();
for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + size) {
index = x * stride;
if (size === 4) {
(vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index));
(vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + 2 * stride));
(vertexData as Vector4[]).push(Vector4.FromArray(meshAttributeArray, index + stride));
}
else {
(vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index));
(vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + 2 * stride));
(vertexData as Vector3[]).push(Vector3.FromArray(meshAttributeArray, index + stride));
}
}
break;
}
case VertexBuffer.UVKind:
case VertexBuffer.UV2Kind: {
for (let x = submesh.verticesStart; x < submesh.verticesStart + submesh.verticesCount; x = x + 3) {
index = x * stride;
(vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index));
(vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index + 2 * stride));
(vertexData as Vector2[]).push(Vector2.FromArray(meshAttributeArray, index + stride));
}
break;
}
for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {
index = k * stride;
const vertexData = Vector4.FromArray(meshAttributeArray, index);
if (this._convertToRightHandedSystem) {
_GLTFUtilities._GetRightHandedVector4FromRef(vertexData);
}
_GLTFUtilities._NormalizeTangentFromRef(vertexData);
vertexAttributes.push(vertexData.asArray());
}
break;
}
case VertexBuffer.ColorKind: {
for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {
index = k * stride;
const vertexData = stride === 3 ? Vector3.FromArray(meshAttributeArray, index) : Vector4.FromArray(meshAttributeArray, index);
vertexAttributes.push(vertexData.asArray());
}
break;
}
case VertexBuffer.UVKind:
case VertexBuffer.UV2Kind: {
for (let k = 0, length = meshAttributeArray.length / stride; k < length; ++k) {
index = k * stride;
vertexAttributes.push(this._convertToRightHandedSystem ? [meshAttributeArray[index], meshAttributeArray[index + 1]] : [meshAttributeArray[index], meshAttributeArray[index + 1]]);
}
break;
}
default: {
Tools.Warn("Unsupported Vertex Buffer Type: " + vertexBufferKind);
vertexAttributes = [];
}
this.forceUpdate();
return;
}
var normals = mesh.getVerticesData(VertexBuffer.NormalKind);
var positions = mesh.getVerticesData(VertexBuffer.PositionKind);
const color = Color3.White();
const bbox = mesh.getBoundingInfo();
const diag = bbox.maximum.subtractToRef(bbox.minimum, TmpVectors.Vector3[0]);
const size = diag.length() * 0.05;
var lines = [];
for (var i = 0; i < normals!.length; i += 3) {
var v1 = Vector3.FromArray(positions!, i);
var v2 = v1.add(Vector3.FromArray(normals!, i).scaleInPlace(size));
lines.push([v1, v2]);
}
var normalLines = LinesBuilder.CreateLineSystem("normalLines", { lines: lines }, scene);
normalLines.color = color;
normalLines.parent = mesh;
normalLines.reservedDataStore = { hidden: true };
if (!mesh.reservedDataStore) {
mesh.reservedDataStore = {};
}
mesh.reservedDataStore.normalLines = normalLines;
this.forceUpdate();
this.forceUpdate();
return;
}
var normals = mesh.getVerticesData(VertexBuffer.NormalKind);
var positions = mesh.getVerticesData(VertexBuffer.PositionKind);
const color = Color3.White();
const bbox = mesh.getBoundingInfo();
const diag = bbox.maximum.subtractToRef(bbox.minimum, TmpVectors.Vector3[0]);
const size = diag.length() * 0.05;
var lines = [];
for (var i = 0; i < normals!.length; i += 3) {
var v1 = Vector3.FromArray(positions!, i);
var v2 = v1.add(Vector3.FromArray(normals!, i).scaleInPlace(size));
lines.push([v1, v2]);
}
var normalLines = LinesBuilder.CreateLineSystem("normalLines", { lines: lines }, scene);
normalLines.color = color;
normalLines.parent = mesh;
normalLines.reservedDataStore = { hidden: true };
if (!mesh.reservedDataStore) {
mesh.reservedDataStore = {};
}
mesh.reservedDataStore.normalLines = normalLines;
this.forceUpdate();
}