@@ -22,7 +22,7 @@ import { IModelApp } from "../IModelApp";
2222import { InstancedGraphicParams } from "../common/render/InstancedGraphicParams" ;
2323import { RealityMeshParams } from "../render/RealityMeshParams" ;
2424import { Mesh } from "../common/internal/render/MeshPrimitives" ;
25- import { Triangle } from "../common/internal/render/Primitives" ;
25+ import { Triangle , TriangleList } from "../common/internal/render/Primitives" ;
2626import { RenderGraphic } from "../render/RenderGraphic" ;
2727import { RenderSystem } from "../render/RenderSystem" ;
2828import { BatchedTileIdMap , decodeMeshoptBuffer , RealityTileGeometry , TileContent } from "./internal" ;
@@ -31,7 +31,7 @@ import { CreateRenderMaterialArgs } from "../render/CreateRenderMaterialArgs";
3131import { DisplayParams } from "../common/internal/render/DisplayParams" ;
3232import { FrontendLoggerCategory } from "../common/FrontendLoggerCategory" ;
3333import { getImageSourceFormatForMimeType , imageBitmapFromImageSource , imageElementFromImageSource , tryImageElementFromUrl } from "../common/ImageUtil" ;
34- import { MeshPrimitiveType } from "../common/internal/render/MeshPrimitive" ;
34+ import { MeshPointList , MeshPrimitiveType } from "../common/internal/render/MeshPrimitive" ;
3535import { PointCloudArgs } from "../common/internal/render/PointCloudPrimitive" ;
3636import { TextureImageSource } from "../common/render/TextureParams" ;
3737import {
@@ -258,7 +258,7 @@ export class GltfReaderProps {
258258
259259/** The GltfMeshData contains the raw GLTF mesh data. If the data is suitable to create a [[RealityMesh]] directly, basically in the quantized format produced by
260260 * ContextCapture, then a RealityMesh is created directly from this data. Otherwise, the mesh primitive is populated from the raw data and a MeshPrimitive
261- * is generated. The MeshPrimitve path is much less efficient but should be rarely used.
261+ * is generated. The MeshPrimitive path is much less efficient but should be rarely used.
262262 *
263263 * @internal
264264 */
@@ -664,7 +664,8 @@ export abstract class GltfReader {
664664 } ;
665665 }
666666
667- public readGltfAndCreateGeometry ( transformToRoot ?: Transform , needNormals = false , needParams = false ) : RealityTileGeometry {
667+ public async readGltfAndCreateGeometry ( transformToRoot ?: Transform , needNormals = false , needParams = false ) : Promise < RealityTileGeometry > {
668+ await this . resolveResources ( ) ;
668669 const transformStack = new TransformStack ( this . getTileTransform ( transformToRoot ) ) ;
669670 const polyfaces : IndexedPolyface [ ] = [ ] ;
670671 for ( const nodeKey of this . _sceneNodes ) {
@@ -949,11 +950,31 @@ export abstract class GltfReader {
949950 }
950951
951952 private polyfaceFromGltfMesh ( mesh : GltfMeshData , transform : Transform | undefined , needNormals : boolean , needParams : boolean ) : IndexedPolyface | undefined {
952- if ( ! mesh . pointQParams || ! mesh . points || ! mesh . indices )
953- return undefined ;
953+ if ( mesh . pointQParams && mesh . points && mesh . indices )
954+ return this . polyfaceFromQuantizedData ( mesh . pointQParams , mesh . points , mesh . indices , mesh . normals , mesh . uvQParams , mesh . uvs , transform , needNormals , needParams ) ;
954955
955- const { points, pointQParams, normals, uvs, uvQParams, indices } = mesh ;
956+ const meshPrim = mesh . primitive ;
957+ const triangles = meshPrim . triangles ;
958+ const points = meshPrim . points ;
959+ if ( ! triangles || triangles . isEmpty || points . length === 0 )
960+ return undefined ;
956961
962+ // This will likely only be the case for Draco-compressed meshes-- see where readDracoMeshPrimitive is called within readMeshPrimitive
963+ // That is the only case where mesh.primitive is populated but mesh.pointQParams, mesh.points, & mesh.indices are not
964+ return this . polyfaceFromMeshPrimitive ( triangles , points , meshPrim . normals , meshPrim . uvParams , transform , needNormals , needParams ) ;
965+ }
966+
967+ private polyfaceFromQuantizedData (
968+ pointQParams : QParams3d ,
969+ points : Uint16Array ,
970+ indices : Uint8Array | Uint16Array | Uint32Array ,
971+ normals : Uint16Array | undefined ,
972+ uvQParams : QParams2d | undefined ,
973+ uvs : Uint16Array | undefined ,
974+ transform : Transform | undefined ,
975+ needNormals : boolean ,
976+ needParams : boolean
977+ ) : IndexedPolyface {
957978 const includeNormals = needNormals && undefined !== normals ;
958979 const includeParams = needParams && undefined !== uvQParams && undefined !== uvs ;
959980
@@ -990,6 +1011,62 @@ export abstract class GltfReader {
9901011 return polyface ;
9911012 }
9921013
1014+ private polyfaceFromMeshPrimitive (
1015+ triangles : TriangleList ,
1016+ points : MeshPointList ,
1017+ normals : OctEncodedNormal [ ] ,
1018+ uvParams : Point2d [ ] ,
1019+ transform : Transform | undefined ,
1020+ needNormals : boolean ,
1021+ needParams : boolean
1022+ ) : IndexedPolyface {
1023+ const includeNormals = needNormals && normals . length > 0 ;
1024+ const includeParams = needParams && uvParams . length > 0 ;
1025+
1026+ const polyface = IndexedPolyface . create ( includeNormals , includeParams ) ;
1027+
1028+ if ( points instanceof QPoint3dList ) {
1029+ for ( let i = 0 ; i < points . length ; i ++ ) {
1030+ const point = points . unquantize ( i ) ;
1031+ if ( transform )
1032+ transform . multiplyPoint3d ( point , point ) ;
1033+ polyface . addPoint ( point ) ;
1034+ }
1035+ } else {
1036+ const center = points . range . center ;
1037+ for ( const pt of points ) {
1038+ const point = pt . plus ( center ) ;
1039+ if ( transform )
1040+ transform . multiplyPoint3d ( point , point ) ;
1041+ polyface . addPoint ( point ) ;
1042+ }
1043+ }
1044+
1045+ if ( includeNormals )
1046+ for ( const normal of normals )
1047+ polyface . addNormal ( OctEncodedNormal . decodeValue ( normal . value ) ) ;
1048+
1049+ if ( includeParams )
1050+ for ( const uv of uvParams )
1051+ polyface . addParam ( uv ) ;
1052+
1053+ const indices = triangles . indices ;
1054+ let j = 0 ;
1055+ for ( const index of indices ) {
1056+ polyface . addPointIndex ( index ) ;
1057+ if ( includeNormals )
1058+ polyface . addNormalIndex ( index ) ;
1059+
1060+ if ( includeParams )
1061+ polyface . addParamIndex ( index ) ;
1062+
1063+ if ( 0 === ( ++ j % 3 ) )
1064+ polyface . terminateFacet ( ) ;
1065+ }
1066+
1067+ return polyface ;
1068+ }
1069+
9931070 // ###TODO what is the actual type of `json`?
9941071 public getBufferView ( json : { [ k : string ] : any } , accessorName : string ) : GltfBufferView | undefined {
9951072 try {
0 commit comments