File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
Sources/GateEngine/Resources/Import & Export/Importers Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -632,8 +632,23 @@ extension GLTransmissionFormat: GeometryImporter {
632632
633633 var tangents : [ Float ] ? = nil
634634 if let accessorIndex = primitive [ . tangent] {
635- tangents = await gltf. values ( forAccessor: accessorIndex)
636- #warning("Tangents not filtered to vec3")
635+ let accessor = gltf. accessors [ accessorIndex]
636+ switch accessor. type {
637+ case . vec3:
638+ tangents = await gltf. values ( forAccessor: accessorIndex)
639+ case . vec4:
640+ // the 4th scalar in each primitive is for generating a bitangent
641+ // Bitangent can be generated without this value, so we discard it.
642+ if var _tangents: [ Float ] = await gltf. values ( forAccessor: accessorIndex) {
643+ for indexOfW in stride ( from: 3 , to: _tangents. count, by: 4 ) {
644+ _tangents. remove ( at: indexOfW)
645+ }
646+ tangents = _tangents
647+ }
648+ default :
649+ throw GateEngineError . failedToDecode ( " Unhandled accessor type for tangents: \( accessor. type) " )
650+ }
651+ Log . assert ( tangents == nil || tangents!. count == positions. count, " Tangent count doesn't match position count. " )
637652 }
638653
639654 var colors : [ Float ] ? = nil
You can’t perform that action at this time.
0 commit comments