@@ -395,53 +395,6 @@ const generateNormals = (sourceDesc, indices) => {
395
395
} ;
396
396
} ;
397
397
398
- const flipTexCoordVs = ( vertexBuffer ) => {
399
- let i , j ;
400
-
401
- const floatOffsets = [ ] ;
402
- const shortOffsets = [ ] ;
403
- const byteOffsets = [ ] ;
404
- for ( i = 0 ; i < vertexBuffer . format . elements . length ; ++ i ) {
405
- const element = vertexBuffer . format . elements [ i ] ;
406
- if ( element . name === SEMANTIC_TEXCOORD0 ||
407
- element . name === SEMANTIC_TEXCOORD1 ) {
408
- switch ( element . dataType ) {
409
- case TYPE_FLOAT32 :
410
- floatOffsets . push ( { offset : element . offset / 4 + 1 , stride : element . stride / 4 } ) ;
411
- break ;
412
- case TYPE_UINT16 :
413
- shortOffsets . push ( { offset : element . offset / 2 + 1 , stride : element . stride / 2 } ) ;
414
- break ;
415
- case TYPE_UINT8 :
416
- byteOffsets . push ( { offset : element . offset + 1 , stride : element . stride } ) ;
417
- break ;
418
- }
419
- }
420
- }
421
-
422
- const flip = ( offsets , type , one ) => {
423
- const typedArray = new type ( vertexBuffer . storage ) ;
424
- for ( i = 0 ; i < offsets . length ; ++ i ) {
425
- let index = offsets [ i ] . offset ;
426
- const stride = offsets [ i ] . stride ;
427
- for ( j = 0 ; j < vertexBuffer . numVertices ; ++ j ) {
428
- typedArray [ index ] = one - typedArray [ index ] ;
429
- index += stride ;
430
- }
431
- }
432
- } ;
433
-
434
- if ( floatOffsets . length > 0 ) {
435
- flip ( floatOffsets , Float32Array , 1.0 ) ;
436
- }
437
- if ( shortOffsets . length > 0 ) {
438
- flip ( shortOffsets , Uint16Array , 65535 ) ;
439
- }
440
- if ( byteOffsets . length > 0 ) {
441
- flip ( byteOffsets , Uint8Array , 255 ) ;
442
- }
443
- } ;
444
-
445
398
// given a texture, clone it
446
399
// NOTE: CPU-side texture data will be shared but GPU memory will be duplicated
447
400
const cloneTexture = ( texture ) => {
@@ -479,7 +432,7 @@ const cloneTextureAsset = (src) => {
479
432
return result ;
480
433
} ;
481
434
482
- const createVertexBufferInternal = ( device , sourceDesc , flipV ) => {
435
+ const createVertexBufferInternal = ( device , sourceDesc ) => {
483
436
const positionDesc = sourceDesc [ SEMANTIC_POSITION ] ;
484
437
if ( ! positionDesc ) {
485
438
// ignore meshes without positions
@@ -572,16 +525,12 @@ const createVertexBufferInternal = (device, sourceDesc, flipV) => {
572
525
}
573
526
}
574
527
575
- if ( flipV ) {
576
- flipTexCoordVs ( vertexBuffer ) ;
577
- }
578
-
579
528
vertexBuffer . unlock ( ) ;
580
529
581
530
return vertexBuffer ;
582
531
} ;
583
532
584
- const createVertexBuffer = ( device , attributes , indices , accessors , bufferViews , flipV , vertexBufferDict ) => {
533
+ const createVertexBuffer = ( device , attributes , indices , accessors , bufferViews , vertexBufferDict ) => {
585
534
586
535
// extract list of attributes to use
587
536
const useAttributes = { } ;
@@ -630,7 +579,7 @@ const createVertexBuffer = (device, attributes, indices, accessors, bufferViews,
630
579
}
631
580
632
581
// create and store it in the dictionary
633
- vb = createVertexBufferInternal ( device , sourceDesc , flipV ) ;
582
+ vb = createVertexBufferInternal ( device , sourceDesc ) ;
634
583
vertexBufferDict [ vbKey ] = vb ;
635
584
}
636
585
@@ -777,7 +726,7 @@ const createDracoMesh = (device, primitive, accessors, bufferViews, meshVariants
777
726
return result ;
778
727
} ;
779
728
780
- const createMesh = ( device , gltfMesh , accessors , bufferViews , flipV , vertexBufferDict , meshVariants , meshDefaultMaterials , assetOptions , promises ) => {
729
+ const createMesh = ( device , gltfMesh , accessors , bufferViews , vertexBufferDict , meshVariants , meshDefaultMaterials , assetOptions , promises ) => {
781
730
const meshes = [ ] ;
782
731
783
732
gltfMesh . primitives . forEach ( ( primitive ) => {
@@ -788,7 +737,7 @@ const createMesh = (device, gltfMesh, accessors, bufferViews, flipV, vertexBuffe
788
737
} else {
789
738
// handle uncompressed mesh
790
739
let indices = primitive . hasOwnProperty ( 'indices' ) ? getAccessorData ( accessors [ primitive . indices ] , bufferViews , true ) : null ;
791
- const vertexBuffer = createVertexBuffer ( device , primitive . attributes , indices , accessors , bufferViews , flipV , vertexBufferDict ) ;
740
+ const vertexBuffer = createVertexBuffer ( device , primitive . attributes , indices , accessors , bufferViews , vertexBufferDict ) ;
792
741
const primitiveType = getPrimitiveType ( primitive ) ;
793
742
794
743
// build the mesh
@@ -1163,7 +1112,7 @@ const extensionIridescence = (data, material, textures) => {
1163
1112
}
1164
1113
} ;
1165
1114
1166
- const createMaterial = ( gltfMaterial , textures , flipV ) => {
1115
+ const createMaterial = ( gltfMaterial , textures ) => {
1167
1116
const material = new StandardMaterial ( ) ;
1168
1117
1169
1118
// glTF doesn't define how to occlude specular
@@ -1692,7 +1641,7 @@ const createSkins = (device, gltf, nodes, bufferViews) => {
1692
1641
} ) ;
1693
1642
} ;
1694
1643
1695
- const createMeshes = ( device , gltf , bufferViews , flipV , options ) => {
1644
+ const createMeshes = ( device , gltf , bufferViews , options ) => {
1696
1645
// dictionary of vertex buffers to avoid duplicates
1697
1646
const vertexBufferDict = { } ;
1698
1647
const meshVariants = { } ;
@@ -1701,7 +1650,7 @@ const createMeshes = (device, gltf, bufferViews, flipV, options) => {
1701
1650
1702
1651
const valid = ( ! options . skipMeshes && gltf ?. meshes ?. length && gltf ?. accessors ?. length && gltf ?. bufferViews ?. length ) ;
1703
1652
const meshes = valid ? gltf . meshes . map ( ( gltfMesh ) => {
1704
- return createMesh ( device , gltfMesh , gltf . accessors , bufferViews , flipV , vertexBufferDict , meshVariants , meshDefaultMaterials , options , promises ) ;
1653
+ return createMesh ( device , gltfMesh , gltf . accessors , bufferViews , vertexBufferDict , meshVariants , meshDefaultMaterials , options , promises ) ;
1705
1654
} ) : [ ] ;
1706
1655
1707
1656
return {
@@ -1712,7 +1661,7 @@ const createMeshes = (device, gltf, bufferViews, flipV, options) => {
1712
1661
} ;
1713
1662
} ;
1714
1663
1715
- const createMaterials = ( gltf , textures , options , flipV ) => {
1664
+ const createMaterials = ( gltf , textures , options ) => {
1716
1665
if ( ! gltf . hasOwnProperty ( 'materials' ) || gltf . materials . length === 0 ) {
1717
1666
return [ ] ;
1718
1667
}
@@ -1725,7 +1674,7 @@ const createMaterials = (gltf, textures, options, flipV) => {
1725
1674
if ( preprocess ) {
1726
1675
preprocess ( gltfMaterial ) ;
1727
1676
}
1728
- const material = process ( gltfMaterial , textures , flipV ) ;
1677
+ const material = process ( gltfMaterial , textures ) ;
1729
1678
if ( postprocess ) {
1730
1679
postprocess ( gltfMaterial , material ) ;
1731
1680
}
@@ -1936,14 +1885,14 @@ const createResources = async (device, gltf, bufferViews, textures, options) =>
1936
1885
preprocess ( gltf ) ;
1937
1886
}
1938
1887
1939
- // The original version of FACT generated incorrectly flipped V texture
1940
- // coordinates. We must compensate by flipping V in this case. Once
1941
- // all models have been re-exported we can remove this flag.
1942
- const flipV = gltf . asset && gltf . asset . generator === 'PlayCanvas' ;
1943
1888
1944
- // We'd like to remove the flipV code at some point.
1945
- if ( flipV ) {
1946
- Debug . warn ( 'glTF model may have flipped UVs. Please reconvert.' ) ;
1889
+ // The very first version of FACT generated incorrectly flipped V texture
1890
+ // coordinates. Since this first version was only ever available behind an
1891
+ // editor flag there should be very few such GLB models in the wild.
1892
+ // Instead of bloating the engine forevermore with code to handle this case,
1893
+ // we now issue a warning and prompt user to reconvert their FBX.
1894
+ if ( gltf . asset && gltf . asset . generator === 'PlayCanvas' ) {
1895
+ Debug . warn ( `glTF model may have been generated with flipped UVs. Please reconvert.` ) ;
1947
1896
}
1948
1897
1949
1898
const nodes = createNodes ( gltf , options ) ;
@@ -1954,13 +1903,13 @@ const createResources = async (device, gltf, bufferViews, textures, options) =>
1954
1903
1955
1904
// buffer data must have finished loading in order to create meshes and animations
1956
1905
const bufferViewData = await Promise . all ( bufferViews ) ;
1957
- const { meshes, meshVariants, meshDefaultMaterials, promises } = createMeshes ( device , gltf , bufferViewData , flipV , options ) ;
1906
+ const { meshes, meshVariants, meshDefaultMaterials, promises } = createMeshes ( device , gltf , bufferViewData , options ) ;
1958
1907
const animations = createAnimations ( gltf , nodes , bufferViewData , options ) ;
1959
1908
1960
1909
// textures must have finished loading in order to create materials
1961
1910
const textureAssets = await Promise . all ( textures ) ;
1962
1911
const textureInstances = textureAssets . map ( t => t . resource ) ;
1963
- const materials = createMaterials ( gltf , textureInstances , options , flipV ) ;
1912
+ const materials = createMaterials ( gltf , textureInstances , options ) ;
1964
1913
const skins = createSkins ( device , gltf , nodes , bufferViewData ) ;
1965
1914
1966
1915
// create renders to wrap meshes
0 commit comments