@@ -10,38 +10,53 @@ import {
1010class Entities {
1111 constructor ( game ) {
1212 this . game = game
13+
1314 this . mobMaterial = new MeshStandardMaterial ( {
1415 color : new Color ( 'red' )
1516 } )
1617 this . mobGeometry = new BoxGeometry ( 1 , 1 , 1 )
17- this . mobMaxCount = 200
18+ this . mobMaxCount = 1000
1819 this . mobMesh = new InstancedMesh (
1920 this . mobGeometry ,
2021 this . mobMaterial ,
2122 this . mobMaxCount
2223 )
2324 this . mobMesh . instanceMatrix . setUsage ( DynamicDrawUsage )
2425 this . game . scene . add ( this . mobMesh )
26+
2527 this . playerMaterial = new MeshStandardMaterial ( {
2628 color : new Color ( 'blue' )
2729 } )
2830 this . playerGeometry = new BoxGeometry ( 1 , 1 , 1 )
29- this . playerMaxCount = 200
31+ this . playerMaxCount = 1000
3032 this . playerMesh = new InstancedMesh (
3133 this . playerGeometry ,
3234 this . playerMaterial ,
3335 this . playerMaxCount
3436 )
3537 this . playerMesh . instanceMatrix . setUsage ( DynamicDrawUsage )
3638 this . game . scene . add ( this . playerMesh )
39+
40+ this . objectMaterial = new MeshStandardMaterial ( {
41+ color : new Color ( 'green' )
42+ } )
43+ this . objectGeometry = new BoxGeometry ( 0.25 , 0.25 , 0.25 )
44+ this . objectMaxCount = 1000
45+ this . objectMesh = new InstancedMesh (
46+ this . objectGeometry ,
47+ this . objectMaterial ,
48+ this . objectMaxCount
49+ )
50+ this . objectMesh . instanceMatrix . setUsage ( DynamicDrawUsage )
51+ this . game . scene . add ( this . objectMesh )
52+
3753 this . dummy = new Object3D ( )
3854 }
3955
4056 update ( entities ) {
4157 const offset = [ - 0.5 , 16 , - 0.5 ]
4258 let numMobs = 0
4359 this . mobMesh . count = entities . mobs . length
44- numMobs = 0
4560 for ( const i in entities . mobs ) {
4661 this . dummy . position . set (
4762 entities . mobs [ i ] [ 0 ] + offset [ 0 ] ,
@@ -52,6 +67,20 @@ class Entities {
5267 this . mobMesh . setMatrixAt ( numMobs ++ , this . dummy . matrix )
5368 }
5469 this . mobMesh . instanceMatrix . needsUpdate = true
70+
71+ let numObjects = 0
72+ this . objectMesh . count = entities . objects . length
73+ for ( const i in entities . objects ) {
74+ this . dummy . position . set (
75+ entities . objects [ i ] [ 0 ] + offset [ 0 ] ,
76+ entities . objects [ i ] [ 1 ] + offset [ 1 ] ,
77+ entities . objects [ i ] [ 2 ] + offset [ 2 ]
78+ )
79+ this . dummy . updateMatrix ( )
80+ this . objectMesh . setMatrixAt ( numObjects ++ , this . dummy . matrix )
81+ }
82+ this . objectMesh . instanceMatrix . needsUpdate = true
83+
5584 let numPlayers = 0
5685 for ( const i in entities . players ) {
5786 if ( entities . players [ i ] [ 0 ] !== this . game . nick ) {
0 commit comments