import { IBufferView , AccessorType , AccessorComponentType , IAccessor } from "babylonjs-gltf2interface" ; import { FloatArray , Nullable } from "babylonjs/types" ; import { Vector3 , Vector4 , Quaternion } from "babylonjs/Maths/math.vector" ; hidden export class _GLTFUtilities { param bufferIndex param byteOffset param byteLength param byteStride param name returns public static _CreateBufferView ( bufferIndex , byteOffset , byteLength , byteStride ? , name ? ) { let bufferview = { buffer : bufferIndex , byteLength : byteLength } ; if ( byteOffset ) { bufferview . byteOffset = byteOffset ; } if ( name ) { bufferview . name = name ; } if ( byteStride ) { bufferview . byteStride = byteStride ; } return bufferview ; } param bufferviewIndex param name param type param componentType param count param byteOffset param min param max returns public static _CreateAccessor ( bufferviewIndex , name , type , componentType , count , byteOffset , min , max ) { let accessor = { name : name , bufferView : bufferviewIndex , componentType : componentType , count : count , type : type } ; if ( min != null ) { accessor . min = min ; } if ( max != null ) { accessor . max = max ; } if ( byteOffset != null ) { accessor . byteOffset = byteOffset ; } return accessor ; } param positions param vertexStart param vertexCount returns public static _CalculateMinMaxPositions ( positions , vertexStart , vertexCount , convertToRightHandedSystem ) { const min = [ Infinity , Infinity , Infinity ] ; const max = [ - Infinity , - Infinity , - Infinity ] ; const positionStrideSize = 3 ; let indexOffset ; let position ; let vector ; if ( vertexCount ) { for ( let i = vertexStart , length = vertexStart + vertexCount ; i < length ; ++ i ) { indexOffset = positionStrideSize * i ; position = Vector3 . FromArray ( positions , indexOffset ) ; if ( convertToRightHandedSystem ) { _GLTFUtilities . _GetRightHandedPositionVector3FromRef ( position ) ; } vector = position . asArray ( ) ; for ( let j = 0 ; j < positionStrideSize ; ++ j ) { let num = vector [ j ] ; if ( num < min [ j ] ) { min [ j ] = num ; } if ( num > max [ j ] ) { max [ j ] = num ; } ++ indexOffset ; } } } return { min , max } ; } param vector returns public static _GetRightHandedPositionVector3 ( vector ) { return new Vector3 ( vector . x , vector . y , - vector . z ) ; } param vector public static _GetRightHandedPositionVector3FromRef ( vector ) { vector . z *= - 1 ; } param vector public static _GetRightHandedPositionArray3FromRef ( vector ) { vector [ 2 ] *= - 1 ; } param vector returns public static _GetRightHandedNormalVector3 ( vector ) { return new Vector3 ( vector . x , vector . y , - vector . z ) ; } param vector public static _GetRightHandedNormalVector3FromRef ( vector ) { vector . z *= - 1 ; } param vector public static _GetRightHandedNormalArray3FromRef ( vector ) { vector [ 2 ] *= - 1 ; } param vector public static _GetRightHandedVector4FromRef ( vector ) { vector . z *= - 1 ; vector . w *= - 1 ; } param vector public static _GetRightHandedArray4FromRef ( vector ) { vector [ 2 ] *= - 1 ; vector [ 3 ] *= - 1 ; } param quaternion public static _GetRightHandedQuaternionFromRef ( quaternion ) { quaternion . x *= - 1 ; quaternion . y *= - 1 ; } param quaternion public static _GetRightHandedQuaternionArrayFromRef ( quaternion ) { quaternion [ 0 ] *= - 1 ; quaternion [ 1 ] *= - 1 ; } public static _NormalizeTangentFromRef ( tangent ) { const length = Math . sqrt ( tangent . x * tangent . x + tangent . y * tangent . y + tangent . z * tangent . z ) ; if ( length > 0 ) { tangent . x /= length ; tangent . y /= length ; tangent . z /= length ; } } public static _GetDataAccessorElementCount ( accessorType ) { switch ( accessorType ) { case AccessorType . MAT2 : return 4 ; case AccessorType . MAT3 : return 9 ; case AccessorType . MAT4 : return 16 ; case AccessorType . SCALAR : return 1 ; case AccessorType . VEC2 : return 2 ; case AccessorType . VEC3 : return 3 ; case AccessorType . VEC4 : return 4 ; } } }