Skip to content

Commit 20fd06d

Browse files
Cleaner primitiveSubParts from hmd in meshBatch
1 parent d6000f0 commit 20fd06d

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

h3d/scene/MeshBatch.hx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,8 @@ class MeshBatch extends MultiMaterial {
9696
var lodCount = prim.lodCount();
9797
if ( lodCount <= 1 )
9898
return;
99-
var prim = Std.downcast(prim, h3d.prim.HMDModel);
100-
if ( prim == null )
101-
return;
102-
if ( primitiveSubParts == null ) {
103-
primitiveSubParts = [];
104-
for ( m in 0...materials.length ) {
105-
var primitiveSubPart = new MeshBatchPart();
106-
primitiveSubPart.indexStart = prim.getMaterialIndexStart(m, 0);
107-
primitiveSubPart.indexCount = prim.getMaterialIndexCount(m, 0);
108-
primitiveSubPart.lodIndexCount = [for (i in 0...prim.lodCount() ) prim.getMaterialIndexCount(m, i)];
109-
primitiveSubPart.lodIndexStart = [for (i in 0...prim.lodCount() ) prim.getMaterialIndexStart(m, i) ];
110-
primitiveSubPart.lodConfig = prim.getLodConfig();
111-
primitiveSubPart.baseVertex = 0;
112-
primitiveSubPart.bounds = prim.getBounds();
113-
114-
primitiveSubParts.push(primitiveSubPart);
115-
}
116-
}
117-
meshBatchFlags.set(EnableCpuLod);
99+
if ( partsFromPrimitive(prim) )
100+
meshBatchFlags.set(EnableCpuLod);
118101
}
119102

120103
function getPrimitive() return @:privateAccess instanced.primitive;
@@ -550,6 +533,28 @@ class MeshBatch extends MultiMaterial {
550533
instanced.setCommand(p.matIndex, instanced.screenRatioToLod(curScreenRatio), count);
551534
}
552535

536+
function partsFromPrimitive(prim : h3d.prim.MeshPrimitive) {
537+
var hmd = Std.downcast(prim, h3d.prim.HMDModel);
538+
if ( hmd == null )
539+
return false;
540+
if ( primitiveSubParts == null ) {
541+
primitiveSubParts = [];
542+
for ( m in 0...materials.length ) {
543+
var primitiveSubPart = new MeshBatchPart();
544+
primitiveSubPart.indexStart = hmd.getMaterialIndexStart(m, 0);
545+
primitiveSubPart.indexCount = hmd.getMaterialIndexCount(m, 0);
546+
primitiveSubPart.lodIndexCount = [for (i in 0...hmd.lodCount() ) hmd.getMaterialIndexCount(m, i)];
547+
primitiveSubPart.lodIndexStart = [for (i in 0...hmd.lodCount() ) hmd.getMaterialIndexStart(m, i) ];
548+
primitiveSubPart.lodConfig = hmd.getLodConfig();
549+
primitiveSubPart.baseVertex = 0;
550+
primitiveSubPart.bounds = hmd.getBounds();
551+
552+
primitiveSubParts.push(primitiveSubPart);
553+
}
554+
}
555+
return true;
556+
}
557+
553558
override function calcScreenRatio(ctx:RenderContext) {
554559
curScreenRatio = getPrimitive().getBounds().dimension() / ( 2.0 * hxd.Math.max(lodDistance, 0.0001) );
555560
}

0 commit comments

Comments
 (0)