Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let outputLength: number;
let animationSampler: IAnimationSampler;
let animationChannel: IAnimationChannel;
if (animationData) {
let nodeIndex = nodeMap[babylonTransformNode.uniqueId];
// Creates buffer view and accessor for key frames.
let byteLength = animationData.inputs.length * 4;
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} keyframe data view`);
bufferViews.push(bufferView);
animationData.inputs.forEach(function(input) {
binaryWriter.setFloat32(input);
});
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} keyframes`, AccessorType.SCALAR, AccessorComponentType.FLOAT, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
accessors.push(accessor);
keyframeAccessorIndex = accessors.length - 1;
// create bufferview and accessor for keyed values.
outputLength = animationData.outputs.length;
byteLength = dataAccessorType === AccessorType.VEC3 ? animationData.outputs.length * 12 : animationData.outputs.length * 16;
// check for in and out tangents
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} data view`);
bufferViews.push(bufferView);
animationData.outputs.forEach(function(output) {
output.forEach(function(entry) {
binaryWriter.setFloat32(entry);
});
});
let outputLength: number;
let animationSampler: IAnimationSampler;
let animationChannel: IAnimationChannel;
if (animationData) {
let nodeIndex = nodeMap[babylonTransformNode.uniqueId];
// Creates buffer view and accessor for key frames.
let byteLength = animationData.inputs.length * 4;
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} keyframe data view`);
bufferViews.push(bufferView);
animationData.inputs.forEach(function(input) {
binaryWriter.setFloat32(input);
});
accessor = _GLTFUtilities._CreateAccessor(bufferViews.length - 1, `${name} keyframes`, AccessorType.SCALAR, AccessorComponentType.FLOAT, animationData.inputs.length, null, [animationData.inputsMin], [animationData.inputsMax]);
accessors.push(accessor);
keyframeAccessorIndex = accessors.length - 1;
// create bufferview and accessor for keyed values.
outputLength = animationData.outputs.length;
byteLength = dataAccessorType === AccessorType.VEC3 ? animationData.outputs.length * 12 : animationData.outputs.length * 16;
// check for in and out tangents
bufferView = _GLTFUtilities._CreateBufferView(0, binaryWriter.getByteOffset(), byteLength, undefined, `${name} data view`);
bufferViews.push(bufferView);
animationData.outputs.forEach(function(output) {
output.forEach(function(entry) {
binaryWriter.setFloat32(entry);
});
});
const bufferViewIndex = attribute.bufferViewIndex;
if (bufferViewIndex != undefined) { // check to see if bufferviewindex has a numeric value assigned.
minMax = { min: null, max: null };
if (attributeKind == VertexBuffer.PositionKind) {
minMax = _GLTFUtilities._CalculateMinMaxPositions(vertexData, 0, vertexData.length / stride, this._convertToRightHandedSystem);
}
const accessor = _GLTFUtilities._CreateAccessor(bufferViewIndex, attributeKind + " - " + babylonTransformNode.name, attribute.accessorType, AccessorComponentType.FLOAT, vertexData.length / stride, 0, minMax.min, minMax.max);
this._accessors.push(accessor);
this.setAttributeKind(meshPrimitive, attributeKind);
}
}
}
}
if (indexBufferViewIndex) {
// Create accessor
const accessor = _GLTFUtilities._CreateAccessor(indexBufferViewIndex, "indices - " + babylonTransformNode.name, AccessorType.SCALAR, AccessorComponentType.UNSIGNED_INT, submesh.indexCount, submesh.indexStart * 4, null, null);
this._accessors.push(accessor);
meshPrimitive.indices = this._accessors.length - 1;
}
if (materialIndex != null && Object.keys(meshPrimitive.attributes).length > 0) {
let sideOrientation = bufferMesh.overrideMaterialSideOrientation !== null ? bufferMesh.overrideMaterialSideOrientation : babylonMaterial.sideOrientation;
// Only reverse the winding if we have a clockwise winding
if (sideOrientation === Material.ClockWiseSideOrientation) {
let byteOffset = indexBufferViewIndex != null ? this._bufferViews[indexBufferViewIndex].byteOffset : null;
if (byteOffset == null) { byteOffset = 0; }
let babylonIndices: Nullable = null;
if (indexBufferViewIndex != null) {
babylonIndices = bufferMesh.getIndices();
}
if (babylonIndices) {
this.reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
private _loadIndicesAccessorAsync(context: string, accessor: IAccessor): Promise {
if (accessor.type !== AccessorType.SCALAR) {
throw new Error(`${context}/type: Invalid value ${accessor.type}`);
}
if (accessor.componentType !== AccessorComponentType.UNSIGNED_BYTE &&
accessor.componentType !== AccessorComponentType.UNSIGNED_SHORT &&
accessor.componentType !== AccessorComponentType.UNSIGNED_INT) {
throw new Error(`${context}/componentType: Invalid value ${accessor.componentType}`);
}
if (accessor._data) {
return accessor._data as Promise;
}
if (accessor.sparse) {
const constructor = GLTFLoader._GetTypedArrayConstructor(`${context}/componentType`, accessor.componentType);
accessor._data = this._loadAccessorAsync(context, accessor, constructor);
private _loadIndicesAccessorAsync(context: string, accessor: IAccessor): Promise {
if (accessor.type !== AccessorType.SCALAR) {
throw new Error(`${context}/type: Invalid value ${accessor.type}`);
}
if (accessor.componentType !== AccessorComponentType.UNSIGNED_BYTE &&
accessor.componentType !== AccessorComponentType.UNSIGNED_SHORT &&
accessor.componentType !== AccessorComponentType.UNSIGNED_INT) {
throw new Error(`${context}/componentType: Invalid value ${accessor.componentType}`);
}
if (accessor._data) {
return accessor._data as Promise;
}
const bufferView = ArrayItem.Get(`${context}/bufferView`, this._gltf.bufferViews, accessor.bufferView);
accessor._data = this.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {
return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);