@@ -34,7 +34,7 @@ var Model = new Class({
3434
3535 initialize :
3636
37- function Model ( mesh , texture , frame , x , y , z )
37+ function Model ( mesh , verticesCount , texture , frame , x , y , z )
3838 {
3939 if ( x === undefined ) { x = 0 ; }
4040 if ( y === undefined ) { y = 0 ; }
@@ -53,29 +53,10 @@ var Model = new Class({
5353 */
5454 this . anims = new AnimationState ( this ) ;
5555
56- /**
57- * An array containing the Face instances belonging to this Mesh.
58- *
59- * A Face consists of 3 Vertex objects.
60- *
61- * This array is populated during the `addVertices` method.
62- *
63- * @name Phaser.Geom.Mesh.Model#faces
64- * @type {Phaser.Geom.Mesh.Face[] }
65- * @since 3.50.0
66- */
67- this . faces = [ ] ;
68-
69- /**
70- * An array containing Vertex instances. One instance per vertex in this Mesh.
71- *
72- * This array is populated during the `setVertices` method.
73- *
74- * @name Phaser.Geom.Mesh.Model#vertices
75- * @type {Phaser.Geom.Mesh.Vertex[] }
76- * @since 3.50.0
77- */
78- this . vertices = [ ] ;
56+ this . vertexSize = 32 ; // 8 attributes * bytes size
57+ this . vertexCount = 0 ; // current number of vertices added to the buffer
58+ this . vertexData = new ArrayBuffer ( verticesCount * this . vertexSize ) ;
59+ this . vertexViewF32 = new Float32Array ( this . vertexData ) ;
7960
8061 this . position = new Vector3 ( x , y , z ) ;
8162 this . scale = new Vector3 ( 1 , 1 , 1 ) ;
@@ -106,28 +87,6 @@ var Model = new Class({
10687 this . mesh . emit . call ( arguments ) ;
10788 } ,
10889
109- /**
110- * Iterates and destroys all current Faces in this Mesh, if any.
111- * Then resets the Face and Vertices arrays.
112- *
113- * @method Phaser.Geom.Mesh.Model#clearVertices
114- * @since 3.50.0
115- *
116- * @return {this } This Mesh Game Object.
117- */
118- clearVertices : function ( )
119- {
120- this . faces . forEach ( function ( face )
121- {
122- face . destroy ( ) ;
123- } ) ;
124-
125- this . faces = [ ] ;
126- this . vertices = [ ] ;
127-
128- return this ;
129- } ,
130-
13190 isDirty : function ( )
13291 {
13392 var position = this . position ;
@@ -219,20 +178,34 @@ var Model = new Class({
219178 */
220179 getFaceCount : function ( )
221180 {
222- return this . faces . length ;
181+ return this . vertexCount / 3 ;
223182 } ,
224183
225184 /**
226- * Returns the total number of Vertices in this Mesh Game Object.
185+ * TODO
227186 *
228- * @method Phaser.Geom.Mesh.Model#getVertexCount
187+ * @method Phaser.Geom.Mesh.Model#getVertex
229188 * @since 3.50.0
230189 *
231- * @return {number } The number of Vertices in this Mesh Game Object .
190+ * @return {Phaser.Geom.Mesh.Vertex } A Vertex object .
232191 */
233- getVertexCount : function ( )
192+ getVertex : function ( index )
234193 {
235- return this . vertices . length ;
194+ var vertexViewF32 = this . vertexViewF32 ;
195+
196+ // 8 = attribute count (number of items added into the view below)
197+ var vertexOffset = ( index * 8 ) - 1 ;
198+
199+ var x = vertexViewF32 [ ++ vertexOffset ] ;
200+ var y = vertexViewF32 [ ++ vertexOffset ] ;
201+ var z = vertexViewF32 [ ++ vertexOffset ] ;
202+ var normalX = vertexViewF32 [ ++ vertexOffset ] ;
203+ var normalY = vertexViewF32 [ ++ vertexOffset ] ;
204+ var normalZ = vertexViewF32 [ ++ vertexOffset ] ;
205+ var u = vertexViewF32 [ ++ vertexOffset ] ;
206+ var v = vertexViewF32 [ ++ vertexOffset ] ;
207+
208+ return new Vertex ( x , y , z , u , v , normalX , normalY , normalZ ) ;
236209 } ,
237210
238211 /**
@@ -247,7 +220,6 @@ var Model = new Class({
247220 */
248221 getFace : function ( index )
249222 {
250- return this . faces [ index ] ;
251223 } ,
252224
253225 /**
@@ -264,41 +236,27 @@ var Model = new Class({
264236 * @param {number } z - The z position of the vertex.
265237 * @param {number } u - The UV u coordinate of the vertex.
266238 * @param {number } v - The UV v coordinate of the vertex.
267- * @param {number } [color=0xffffff] - The color value of the vertex.
268239 * @param {number } [alpha=1] - The alpha value of the vertex.
269240 *
270241 * @return {this } This Mesh Game Object.
271242 */
272- addVertex : function ( x , y , z , u , v , color , alpha )
243+ addVertex : function ( x , y , z , u , v , normalX , normalY , normalZ , alpha )
273244 {
274- var vert = new Vertex ( x , y , z , u , v , color , alpha ) ;
275-
276- this . vertices . push ( vert ) ;
277-
278- return vert ;
279- } ,
245+ var vertexViewF32 = this . vertexViewF32 ;
280246
281- /**
282- * Adds a new Face into the faces array of this Mesh.
283- *
284- * A Face consists of references to 3 Vertex instances, which must be provided.
285- *
286- * @method Phaser.Geom.Mesh.Model#addFace
287- * @since 3.50.0
288- *
289- * @param {Phaser.Geom.Mesh.Vertex } vertex1 - The first vertex of the Face.
290- * @param {Phaser.Geom.Mesh.Vertex } vertex2 - The second vertex of the Face.
291- * @param {Phaser.Geom.Mesh.Vertex } vertex3 - The third vertex of the Face.
292- *
293- * @return {this } This Mesh Game Object.
294- */
295- addFace : function ( vertex1 , vertex2 , vertex3 )
296- {
297- var face = new Face ( vertex1 , vertex2 , vertex3 ) ;
247+ // 8 = attribute count (number of items added into the view below)
248+ var vertexOffset = ( this . vertexCount * 8 ) - 1 ;
298249
299- this . faces . push ( face ) ;
250+ vertexViewF32 [ ++ vertexOffset ] = x ;
251+ vertexViewF32 [ ++ vertexOffset ] = y ;
252+ vertexViewF32 [ ++ vertexOffset ] = z ;
253+ vertexViewF32 [ ++ vertexOffset ] = normalX ;
254+ vertexViewF32 [ ++ vertexOffset ] = normalY ;
255+ vertexViewF32 [ ++ vertexOffset ] = normalZ ;
256+ vertexViewF32 [ ++ vertexOffset ] = u ;
257+ vertexViewF32 [ ++ vertexOffset ] = v ;
300258
301- return face ;
259+ this . vertexCount ++ ;
302260 } ,
303261
304262 /**
@@ -551,8 +509,6 @@ var Model = new Class({
551509 */
552510 destroy : function ( )
553511 {
554- this . clearVertices ( ) ;
555-
556512 this . anims . destroy ( ) ;
557513
558514 this . mesh = null ;
@@ -562,6 +518,7 @@ var Model = new Class({
562518 this . rotation = null ;
563519 this . scale = null ;
564520 this . transformMatrix = null ;
521+ this . vertexData = null ;
565522 }
566523
567524} ) ;
0 commit comments