Skip to content

Commit 78c1eb7

Browse files
committed
Removed debug, modified signatuers, added fog
1 parent 0ad265d commit 78c1eb7

1 file changed

Lines changed: 21 additions & 132 deletions

File tree

src/gameobjects/mesh/Mesh.js

Lines changed: 21 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var MeshRender = require('./MeshRender');
1313
var MeshCamera = require('./MeshCamera');
1414
var MeshLight = require('./MeshLight');
1515
var Model = require('../../geom/mesh/Model');
16-
var Vector3 = require('../../math/Vector3');
16+
var CONST = require('../../renderer/webgl/pipelines/const');
1717

1818
/**
1919
* @classdesc
@@ -86,49 +86,27 @@ var Mesh = new Class({
8686
*/
8787
this.camera = new MeshCamera(45, 0, 0, -10, 0.01, 1000);
8888

89-
this.light = new MeshLight();
90-
9189
/**
92-
* An array of Model instances that have been created in this Mesh.
90+
* TODO
9391
*
94-
* @name Phaser.GameObjects.Mesh#models
95-
* @type {Phaser.Geom.Mesh.Model[]}
92+
* @name Phaser.GameObjects.Mesh#light
93+
* @type {Phaser.GameObjects.MeshLight}
9694
* @since 3.50.0
9795
*/
98-
this.models = [];
96+
this.light = new MeshLight();
9997

100-
/**
101-
* You can optionally choose to render the vertices of this Mesh to a Graphics instance.
102-
*
103-
* Achieve this by setting the `debugCallback` and the `debugGraphic` properties.
104-
*
105-
* You can do this in a single call via the `Mesh.setDebug` method, which will use the
106-
* built-in debug function. You can also set it to your own callback. The callback
107-
* will be invoked _once per render_ and sent the following parameters:
108-
*
109-
* `debugCallback(src, meshLength, verts)`
110-
*
111-
* `src` is the Mesh instance being debugged.
112-
* `meshLength` is the number of mesh vertices in total.
113-
* `verts` is an array of the translated vertex coordinates.
114-
*
115-
* To disable rendering, set this property back to `null`.
116-
*
117-
* @name Phaser.GameObjects.Mesh#debugCallback
118-
* @type {function}
119-
* @since 3.50.0
120-
*/
121-
this.debugCallback = null;
98+
this.fogColor = { r: 0, g: 0, b: 0 };
99+
this.fogNear = 0;
100+
this.fogFar = Infinity;
122101

123102
/**
124-
* The Graphics instance that the debug vertices will be drawn to, if `setDebug` has
125-
* been called.
103+
* An array of Model instances that have been created in this Mesh.
126104
*
127-
* @name Phaser.GameObjects.Mesh#debugGraphic
128-
* @type {Phaser.GameObjects.Graphics}
105+
* @name Phaser.GameObjects.Mesh#models
106+
* @type {Phaser.Geom.Mesh.Model[]}
129107
* @since 3.50.0
130108
*/
131-
this.debugGraphic = null;
109+
this.models = [];
132110

133111
/**
134112
* Internal cached value.
@@ -153,11 +131,8 @@ var Mesh = new Class({
153131
var renderer = scene.sys.renderer;
154132

155133
this.setPosition(x, y);
156-
157134
this.setSize(renderer.width, renderer.height);
158-
159-
// TODO - Change to const
160-
this.initPipeline('MeshPipeline');
135+
this.initPipeline(CONST.MESH_PIPELINE);
161136

162137
if (vertices)
163138
{
@@ -212,9 +187,9 @@ var Mesh = new Class({
212187
*
213188
* @return {Phaser.Geom.Mesh.Model} The Model instance that was created.
214189
*/
215-
addModel: function (texture, frame, x, y, z)
190+
addModel: function (verticesCount, texture, frame, x, y, z)
216191
{
217-
var model = new Model(this, texture, frame, x, y, z);
192+
var model = new Model(this, verticesCount, texture, frame, x, y, z);
218193

219194
this.models.push(model);
220195

@@ -323,15 +298,15 @@ var Mesh = new Class({
323298

324299
for (var m = 0; m < data.models.length; m++)
325300
{
326-
var model = this.addModel(texture, frame);
327-
328301
var modelData = data.models[m];
329302

330303
var vertices = modelData.vertices;
331304
var textureCoords = modelData.textureCoords;
332305
var normals = modelData.vertexNormals;
333306
var faces = modelData.faces;
334307

308+
var model = this.addModel(faces.length * 3, texture, frame);
309+
335310
var defaultUV1 = { u: 0, v: 1 };
336311
var defaultUV2 = { u: 0, v: 0 };
337312
var defaultUV3 = { u: 1, v: 1 };
@@ -362,11 +337,9 @@ var Mesh = new Class({
362337
var uv2 = (t2 === -1) ? defaultUV2 : textureCoords[t2];
363338
var uv3 = (t3 === -1) ? defaultUV3 : textureCoords[t3];
364339

365-
var vert1 = model.addVertex(originX + m1.x * scale, originY + m1.y * scale, originZ + m1.z * scale, uv1.u, uv1.v, n1.x, n1.y, n1.z);
366-
var vert2 = model.addVertex(originX + m2.x * scale, originY + m2.y * scale, originZ + m2.z * scale, uv2.u, uv2.v, n2.x, n2.y, n2.z);
367-
var vert3 = model.addVertex(originX + m3.x * scale, originY + m3.y * scale, originZ + m3.z * scale, uv3.u, uv3.v, n3.x, n3.y, n3.z);
368-
369-
model.addFace(vert1, vert2, vert3);
340+
model.addVertex(originX + m1.x * scale, originY + m1.y * scale, originZ + m1.z * scale, uv1.u, uv1.v, n1.x, n1.y, n1.z);
341+
model.addVertex(originX + m2.x * scale, originY + m2.y * scale, originZ + m2.z * scale, uv2.u, uv2.v, n2.x, n2.y, n2.z);
342+
model.addVertex(originX + m3.x * scale, originY + m3.y * scale, originZ + m3.z * scale, uv3.u, uv3.v, n3.x, n3.y, n3.z);
370343
}
371344

372345
results.push(model);
@@ -430,7 +403,7 @@ var Mesh = new Class({
430403
},
431404

432405
/**
433-
* Return an array of Modes from this Mesh that intersect with the given coordinates.
406+
* Return an array of Models from this Mesh that intersect with the given coordinates.
434407
*
435408
* The given position is translated through the matrix of this Mesh and the given Camera,
436409
* before being compared against the model vertices.
@@ -475,59 +448,6 @@ var Mesh = new Class({
475448
return results;
476449
},
477450

478-
/**
479-
* This method enables rendering of the Model vertices to the given Graphics instance.
480-
*
481-
* If you enable this feature, you **must** call `Graphics.clear()` in your Scene `update`,
482-
* otherwise the Graphics instance you provide to debug will fill-up with draw calls,
483-
* eventually crashing the browser. This is not done automatically to allow you to debug
484-
* draw multiple Mesh objects to a single Graphics instance.
485-
*
486-
* You can toggle debug drawing on a per-Model basis via the `Model.drawDebug` boolean property.
487-
*
488-
* The Mesh class has a built-in debug rendering callback `Mesh.renderDebugVerts`, however
489-
* you can also provide your own callback to be used instead. Do this by setting the `callback` parameter.
490-
*
491-
* The callback is invoked _once per render_ and sent the following parameters:
492-
*
493-
* `callback(src, meshLength, verts)`
494-
*
495-
* `src` is the Model instance being debugged.
496-
* `verts` is an array of the translated vertex coordinates.
497-
*
498-
* If using your own callback you do not have to provide a Graphics instance to this method.
499-
*
500-
* To disable debug rendering, to either your own callback or the built-in one, call this method
501-
* with no arguments.
502-
*
503-
* @method Phaser.GameObjects.Mesh#setDebug
504-
* @since 3.50.0
505-
*
506-
* @param {Phaser.GameObjects.Graphics} [graphic] - The Graphic instance to render to if using the built-in callback.
507-
* @param {function} [callback] - The callback to invoke during debug render. Leave as undefined to use the built-in callback.
508-
*
509-
* @return {this} This Game Object instance.
510-
*/
511-
setDebug: function (graphic, callback)
512-
{
513-
this.debugGraphic = graphic;
514-
515-
if (!graphic && !callback)
516-
{
517-
this.debugCallback = null;
518-
}
519-
else if (!callback)
520-
{
521-
this.debugCallback = this.renderDebugVerts;
522-
}
523-
else
524-
{
525-
this.debugCallback = callback;
526-
}
527-
528-
return this;
529-
},
530-
531451
/**
532452
* The Mesh update loop.
533453
*
@@ -573,34 +493,6 @@ var Mesh = new Class({
573493
camera.dirty = false;
574494
},
575495

576-
/**
577-
* The built-in vertices debug rendering method.
578-
*
579-
* See `Mesh.setDebug` for more details.
580-
*
581-
* @method Phaser.GameObjects.Mesh#renderDebugVerts
582-
* @since 3.50.0
583-
*
584-
* @param {Phaser.Geom.Mesh.Model} src - The Model being rendered.
585-
* @param {number[]} verts - An array of translated vertex coordinates.
586-
*/
587-
renderDebugVerts: function (src, verts)
588-
{
589-
var graphic = src.debugGraphic;
590-
591-
for (var i = 0; i < verts.length; i += 6)
592-
{
593-
var x0 = verts[i + 0];
594-
var y0 = verts[i + 1];
595-
var x1 = verts[i + 2];
596-
var y1 = verts[i + 3];
597-
var x2 = verts[i + 4];
598-
var y2 = verts[i + 5];
599-
600-
graphic.strokeTriangle(x0, y0, x1, y1, x2, y2);
601-
}
602-
},
603-
604496
/**
605497
* The destroy step for the Mesh, which removes all models, destroys the camera and
606498
* nulls references.
@@ -616,9 +508,6 @@ var Mesh = new Class({
616508
this.camera.destroy();
617509

618510
this.camera = null;
619-
620-
this.debugCallback = null;
621-
this.debugGraphic = null;
622511
}
623512

624513
});

0 commit comments

Comments
 (0)