11import * as THREE from 'three'
22import { Primitive } from "./primitive.js"
3+ import { isSphere } from './../utils/primitiveUtils.js'
34
45export class BatchedPrimitive extends Primitive {
56 static __type = 'BatchedPrimitive'
67
7- constructor ( primitive , params ) {
8+ constructor ( type , params ) {
89
910 super ( params )
10-
11- this . constructor . __type = primitive . __type // dont like the idea this redefines what the actual type is
11+
12+ this . constructor . __type = type // dont like the idea this redefines what the actual type is / hardcode for now
1213
1314 if ( isSphere ( this ) ) this . infrastructure . config . radius = params . radius
1415
1516 }
1617
1718 createDimensions ( ) {
1819
19- let batchedMesh = new THREE . BatchedMesh ( 0 , 0 , 0 , new THREE . MeshStandardMaterial ( ) )
20+ let batchedMesh = new THREE . BatchedMesh ( 1 , 1 , 1 , this . infrastructure . config . material )
2021
2122 this . _transferGeometry ( batchedMesh )
2223
@@ -40,14 +41,16 @@ export class BatchedPrimitive extends Primitive{
4041
4142 let polyPerLevel = this . infrastructure . config . levels . polyPerLevel
4243
43- this . infrastructure . on ( 'afterMeshCreation' , ( node , payload ) => {
44+ this . infrastructure . events . on ( 'afterMeshCreation' , ( node , payload ) => {
4445
4546 const parent = node . parent ;
4647
4748 parent . remove ( node ) ;
4849
4950 const geometry = node . mesh ( ) . geometry
50-
51+
52+ const material = node . mesh ( ) . material
53+
5154 const depth = node . params . depth
5255
5356 const vertex = polyPerLevel [ depth ]
@@ -77,10 +80,29 @@ export class BatchedPrimitive extends Primitive{
7780 batchedMesh . setMatrixAt ( id , matrix ) ;
7881
7982 batchedMesh . setColorAt ( id , new THREE . Color ( Math . random ( ) * 0xffffff ) )
83+
84+ geometry . dispose ( ) // might need this when phyics engine works
85+
86+ material . dispose ( )
8087
8188 } )
82-
8389 }
84-
8590 }
86-
91+
92+ //example usage
93+ /*
94+ let planet2 = new BatchedPrimitive(122,{
95+ offset:1/0.5 ,
96+ levels:1,
97+ size:1,
98+ radius:10.0,
99+ resolution:50,
100+ dimension:10
101+ })
102+ planet2.infrastructure.config.lodDistanceOffset = 1
103+ planet2.createQuadTree({levels:1})
104+
105+ planet2.createMeshNodes()
106+
107+ planet2.createDimensions()
108+ */
0 commit comments