Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let promises: Promise[] = [];
let bufferMesh: Nullable = null;
let bufferView: IBufferView;
let minMax: { min: Nullable, max: Nullable };
if (babylonTransformNode instanceof Mesh) {
bufferMesh = (babylonTransformNode as Mesh);
}
else if (babylonTransformNode instanceof InstancedMesh) {
bufferMesh = (babylonTransformNode as InstancedMesh).sourceMesh;
}
const attributeData: _IVertexAttributeData[] = [
{ kind: VertexBuffer.PositionKind, accessorType: AccessorType.VEC3, byteStride: 12 },
{ kind: VertexBuffer.NormalKind, accessorType: AccessorType.VEC3, byteStride: 12 },
{ kind: VertexBuffer.ColorKind, accessorType: AccessorType.VEC4, byteStride: 16 },
{ kind: VertexBuffer.TangentKind, accessorType: AccessorType.VEC4, byteStride: 16 },
{ kind: VertexBuffer.UVKind, accessorType: AccessorType.VEC2, byteStride: 8 },
{ kind: VertexBuffer.UV2Kind, accessorType: AccessorType.VEC2, byteStride: 8 },
];
if (bufferMesh) {
let indexBufferViewIndex: Nullable = null;
const primitiveMode = this.getMeshPrimitiveMode(bufferMesh);
let vertexAttributeBufferViews: { [attributeKind: string]: number } = {};
// For each BabylonMesh, create bufferviews for each 'kind'
for (const attribute of attributeData) {
const attributeKind = attribute.kind;
if (bufferMesh.isVerticesDataPresent(attributeKind)) {
const vertexBuffer = this.getVertexBufferFromMesh(attributeKind, bufferMesh);
attribute.byteStride = vertexBuffer ? vertexBuffer.getSize() * 4 : VertexBuffer.DeduceStride(attributeKind) * 4;
if (attribute.byteStride === 12) {
private static _DeduceAnimationInfo(animation: Animation): Nullable<_IAnimationInfo> {
let animationChannelTargetPath: Nullable = null;
let dataAccessorType = AccessorType.VEC3;
let useQuaternion: boolean = false;
let property = animation.targetProperty.split('.');
switch (property[0]) {
case 'scaling': {
animationChannelTargetPath = AnimationChannelTargetPath.SCALE;
break;
}
case 'position': {
animationChannelTargetPath = AnimationChannelTargetPath.TRANSLATION;
break;
}
case 'rotation': {
dataAccessorType = AccessorType.VEC4;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
case 'rotationQuaternion': {
dataAccessorType = AccessorType.VEC4;
useQuaternion = true;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
default: {
Tools.Error(`Unsupported animatable property ${property[0]}`);
}
}
if (animationChannelTargetPath) {
return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
}
loadAttribute("COLOR_0", VertexBuffer.ColorKind, (accessor) => {
if (accessor.type === AccessorType.VEC4) {
babylonMesh.hasVertexAlpha = true;
}
});
loadAttribute("COLOR_0", VertexBuffer.ColorKind, (accessor) => {
if (accessor.type === AccessorType.VEC4) {
babylonMesh.hasVertexAlpha = true;
}
});
switch (property[0]) {
case 'scaling': {
animationChannelTargetPath = AnimationChannelTargetPath.SCALE;
break;
}
case 'position': {
animationChannelTargetPath = AnimationChannelTargetPath.TRANSLATION;
break;
}
case 'rotation': {
dataAccessorType = AccessorType.VEC4;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
case 'rotationQuaternion': {
dataAccessorType = AccessorType.VEC4;
useQuaternion = true;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
default: {
Tools.Error(`Unsupported animatable property ${property[0]}`);
}
}
if (animationChannelTargetPath) {
return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
}
else {
Tools.Error('animation channel target path and data accessor type could be deduced');
}
return null;
}