|
@@ -222,6 +222,10 @@ Class Gltf2Loader
|
|
|
Case "BLEND" mat.BlendMode=BlendMode.Alpha
|
|
|
End
|
|
|
|
|
|
+ If material.doubleSided
|
|
|
+ mat.CullMode=CullMode.None
|
|
|
+ Endif
|
|
|
+
|
|
|
_materialCache[material]=mat
|
|
|
Return mat
|
|
|
End
|
|
@@ -235,11 +239,28 @@ Class Gltf2Loader
|
|
|
Return matrix
|
|
|
End
|
|
|
|
|
|
- Method GetMatrix:Mat4f( node:Gltf2Node )
|
|
|
+ Method GetWorldMatrix:Mat4f( node:Gltf2Node )
|
|
|
+
|
|
|
+ Return node.parent ? GetWorldMatrix( node.parent ) * GetLocalMatrix( node ) Else GetLocalMatrix( node )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method GetLocalMatrix:Mat4f( node:Gltf2Node )
|
|
|
+
|
|
|
+ Local matrix:Mat4f
|
|
|
+
|
|
|
+ If node.hasMatrix Return FlipMatrix( node.matrix )
|
|
|
+
|
|
|
+ Local v:=node.translation
|
|
|
+ v.z=-v.z
|
|
|
|
|
|
- Local matrix:=FlipMatrix( node.matrix )
|
|
|
+ Local q:=node.rotation
|
|
|
+ q.v.x=-q.v.x
|
|
|
+ q.v.y=-q.v.y
|
|
|
+ q.w=-q.w
|
|
|
|
|
|
- Return node.parent ? GetMatrix( node.parent ) * matrix Else matrix
|
|
|
+ Local s:=node.scale
|
|
|
+
|
|
|
+ Return Mat4f.Translation( v ) * Mat4f.Rotation( q ) * Mat4f.Scaling( s )
|
|
|
End
|
|
|
|
|
|
Method LoadPrimitive:Mesh( prim:Gltf2Primitive )
|
|
@@ -311,7 +332,7 @@ Class Gltf2Loader
|
|
|
|
|
|
If prim.TEXCOORD_0
|
|
|
If prim.TEXCOORD_0.componentType=GLTF_FLOAT And prim.TEXCOORD_0.type="VEC2"
|
|
|
-' Print "Gltf2 primitive has texcoords"
|
|
|
+' Print "Gltf2 primitive has texcoords0"
|
|
|
Local datap:=GetData( prim.TEXCOORD_0 )
|
|
|
Local stride:=prim.TEXCOORD_0.bufferView.byteStride ?Else 8
|
|
|
For Local i:=0 Until vcount
|
|
@@ -323,6 +344,20 @@ Class Gltf2Loader
|
|
|
Endif
|
|
|
Endif
|
|
|
|
|
|
+ If prim.TEXCOORD_1
|
|
|
+ If prim.TEXCOORD_1.componentType=GLTF_FLOAT And prim.TEXCOORD_1.type="VEC2"
|
|
|
+' Print "Gltf2 primitive has texcoords1"
|
|
|
+ Local datap:=GetData( prim.TEXCOORD_1 )
|
|
|
+ Local stride:=prim.TEXCOORD_1.bufferView.byteStride ?Else 8
|
|
|
+ For Local i:=0 Until vcount
|
|
|
+ vertices[i].texCoord1=Cast<Vec2f Ptr>( datap )[0]
|
|
|
+ datap+=stride
|
|
|
+ Next
|
|
|
+ Else
|
|
|
+ Print "Unsupported gltf2 primitive TEXCOORD_1 format"
|
|
|
+ Endif
|
|
|
+ Endif
|
|
|
+
|
|
|
If prim.JOINTS_0
|
|
|
Local datap:=GetData( prim.JOINTS_0 )
|
|
|
If prim.JOINTS_0.componentType=GLTF_UNSIGNED_SHORT And prim.JOINTS_0.type="VEC4"
|
|
@@ -407,7 +442,7 @@ Class Gltf2Loader
|
|
|
|
|
|
If node.mesh
|
|
|
|
|
|
- Local matrix:=New AffineMat4f( GetMatrix( node ) )
|
|
|
+ Local matrix:=New AffineMat4f( GetWorldMatrix( node ) )
|
|
|
|
|
|
For Local prim:=Eachin node.mesh.primitives
|
|
|
|
|
@@ -445,7 +480,7 @@ Class Gltf2Loader
|
|
|
|
|
|
model.Name=node.name
|
|
|
|
|
|
- model.LocalMatrix=New AffineMat4f( FlipMatrix( node.matrix ) )
|
|
|
+ model.LocalMatrix=New AffineMat4f( GetLocalMatrix( node ) )
|
|
|
|
|
|
Local id:=_entities.Length
|
|
|
_entities.Add( model )
|
|
@@ -696,11 +731,10 @@ Class Gltf2Loader
|
|
|
|
|
|
For Local i:=0 Until n
|
|
|
|
|
|
- Local entity:=_entities[ _nodeIds[skin.joints[i]] ]
|
|
|
- Local matrix:=datap ? FlipMatrix( Cast<Mat4f Ptr>( datap )[0] ) Else New Mat4f
|
|
|
+ Local matrix:=datap ? New AffineMat4f( FlipMatrix( Cast<Mat4f Ptr>( datap )[0] ) ) Else New AffineMat4f
|
|
|
|
|
|
- _bones[i].entity=entity
|
|
|
- _bones[i].offset=New AffineMat4f( matrix )
|
|
|
+ _bones[i].entity=_entities[ _nodeIds[skin.joints[i]] ]
|
|
|
+ _bones[i].offset=matrix
|
|
|
|
|
|
If datap datap+=stride
|
|
|
Next
|