# How to use the babylonjs/Maths/math.Vector3.FromArray function in babylonjs

## To help you get started, weâ€™ve selected a few babylonjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

BabylonJS / Babylon.js / loaders / src / glTF / 2.0 / glTFLoader.ts View on Github
``````// 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;
}``````
BabylonJS / Babylon.js / loaders / src / glTF / 2.0 / glTFLoader.ts View on Github
``````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());
}``````
BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFExporter.ts View on Github
``````(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;
}``````
BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFExporter.ts View on Github
``````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 = [];
}``````
BabylonJS / Babylon.js / inspector / src / components / actionTabs / tabs / propertyGrids / meshes / meshPropertyGridComponent.tsx View on Github
``````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);
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();``````
BabylonJS / Babylon.js / inspector / src / components / actionTabs / tabs / propertyGrids / meshes / meshPropertyGridComponent.tsx View on Github
``````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);
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();
}``````

## babylonjs

* We recommend using the [Core ES6-supported version](https://www.npmjs.com/package/@babylonjs/core);

Apache-2.0