Skip to content

Commit bf3a016

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 039ed52 + f5232da commit bf3a016

32 files changed

Lines changed: 1024 additions & 85 deletions

v3/src/cache/GlobalCache.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ var GlobalCache = new Class({
8181
*/
8282
this.text = new BaseCache();
8383

84+
/**
85+
* [description]
86+
*
87+
* @property {Phaser.Cache.BaseCache} obj
88+
* @protected
89+
*/
90+
this.obj = new BaseCache();
91+
8492
/**
8593
* [description]
8694
*

v3/src/gameobjects/graphics/Graphics.js

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ var Ellipse = require('../../geom/ellipse/');
77
var GameObject = require('../GameObject');
88
var GetValue = require('../../utils/object/GetValue');
99
var MATH_CONST = require('../../math/const');
10+
var Matrix4 = require('../../math/Matrix4');
11+
var Mesh = require('../../geom/mesh/Mesh');
1012
var Render = require('./GraphicsRender');
13+
var Vector3 = require('../../math/Vector3');
1114

1215
var Graphics = new Class({
1316

@@ -49,6 +52,22 @@ var Graphics = new Class({
4952

5053
this.setDefaultStyles(options);
5154

55+
// Mesh viewport camera
56+
57+
this.viewportWidth = scene.sys.game.config.width;
58+
this.viewportHeight = scene.sys.game.config.height;
59+
60+
this.camera = {
61+
position: new Vector3(),
62+
target: new Vector3()
63+
};
64+
65+
this.up = new Vector3().up();
66+
this.projectionMatrix = new Matrix4();
67+
this.viewMatrix = new Matrix4().lookAt(this.camera.position, this.camera.target, this.up);
68+
69+
this.setViewport(this.viewportWidth, this.viewportHeight);
70+
5271
var resourceManager = scene.sys.game.renderer.resourceManager;
5372

5473
if (resourceManager !== undefined)
@@ -398,6 +417,158 @@ var Graphics = new Class({
398417
return this;
399418
},
400419

420+
// MESH + VIEWPORT + CAMERA
421+
422+
cameraX: {
423+
424+
get: function ()
425+
{
426+
return this.camera.position.x;
427+
},
428+
429+
set: function (value)
430+
{
431+
this.camera.position.x = value;
432+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
433+
}
434+
435+
},
436+
437+
cameraY: {
438+
439+
get: function ()
440+
{
441+
return this.camera.position.y;
442+
},
443+
444+
set: function (value)
445+
{
446+
this.camera.position.y = value;
447+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
448+
}
449+
450+
},
451+
452+
cameraZ: {
453+
454+
get: function ()
455+
{
456+
return this.camera.position.z;
457+
},
458+
459+
set: function (value)
460+
{
461+
this.camera.position.z = value;
462+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
463+
}
464+
465+
},
466+
467+
cameraTargetX: {
468+
469+
get: function ()
470+
{
471+
return this.camera.target.x;
472+
},
473+
474+
set: function (value)
475+
{
476+
this.camera.target.x = value;
477+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
478+
}
479+
480+
},
481+
482+
cameraTargetY: {
483+
484+
get: function ()
485+
{
486+
return this.camera.target.y;
487+
},
488+
489+
set: function (value)
490+
{
491+
this.camera.target.y = value;
492+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
493+
}
494+
495+
},
496+
497+
cameraTargetZ: {
498+
499+
get: function ()
500+
{
501+
return this.camera.target.z;
502+
},
503+
504+
set: function (value)
505+
{
506+
this.camera.target.z = value;
507+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
508+
}
509+
510+
},
511+
512+
setCameraPosition: function (x, y, z)
513+
{
514+
this.camera.position.set(x, y, z);
515+
516+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
517+
518+
return this;
519+
},
520+
521+
setCameraTarget: function (x, y, z)
522+
{
523+
this.camera.target.set(x, y, z);
524+
525+
this.viewMatrix.lookAt(this.camera.position, this.camera.target, this.up);
526+
527+
return this;
528+
},
529+
530+
// @param {number} fovy Vertical field of view in radians
531+
// @param {number} near Near bound of the frustum
532+
// @param {number} far Far bound of the frustum
533+
setViewport: function (width, height, fov, near, far)
534+
{
535+
if (fov === undefined) { fov = 0.8; }
536+
if (near === undefined) { near = 0.01; }
537+
if (far === undefined) { far = 1; }
538+
539+
this.viewportWidth = width;
540+
this.viewportHeight = height;
541+
542+
// fov, aspect, near, far
543+
this.projectionMatrix.perspective(fov, width / height, near, far);
544+
545+
return this;
546+
},
547+
548+
// Allow key to be a data array OR object containing the rest of the properties + color etc
549+
createMesh: function (key, x, y, z)
550+
{
551+
var data = this.scene.sys.cache.obj.get(key);
552+
553+
var mesh = new Mesh(data, x, y, z);
554+
555+
return mesh;
556+
},
557+
558+
fillMesh: function (mesh)
559+
{
560+
mesh.fill(this);
561+
562+
return this;
563+
},
564+
565+
strokeMesh: function (mesh)
566+
{
567+
mesh.stroke(this);
568+
569+
return this;
570+
},
571+
401572
// TRANSFORM
402573

403574
save: function ()

v3/src/gameobjects/graphics/GraphicsCanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c
102102
break;
103103

104104
case Commands.FILL_PATH:
105-
if (!allowClip)
105+
if (!allowClip)
106106
{
107107
ctx.fill();
108108
}
@@ -143,7 +143,7 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c
143143
ctx.lineTo(commandBuffer[index + 3], commandBuffer[index + 4]);
144144
ctx.lineTo(commandBuffer[index + 5], commandBuffer[index + 6]);
145145
ctx.closePath();
146-
if (!allowClip)
146+
if (!allowClip)
147147
{
148148
ctx.fill();
149149
}

v3/src/gameobjects/graphics/GraphicsWebGLRenderer.js

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
var GameObject = require('../GameObject');
21
var Commands = require('./Commands');
2+
var GameObject = require('../GameObject');
33
var TransformMatrix = require('../components/TransformMatrix');
4-
var pathArray = [];
4+
55
var cos = Math.cos;
66
var sin = Math.sin;
7-
var sqrt = Math.sqrt;
8-
var tempMatrix = new TransformMatrix();
7+
8+
var currentMatrix = new TransformMatrix();
99
var matrixStack = new Float32Array(6 * 1000);
1010
var matrixStackLength = 0;
11-
var currentMatrix = new TransformMatrix();
11+
var pathArray = [];
12+
var tempMatrix = new TransformMatrix();
1213

1314
var Point = function (x, y, width, rgb, alpha)
1415
{
@@ -35,19 +36,14 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
3536

3637
var renderTarget = forceRenderTarget || gameObject.renderTarget;
3738
var shapeBatch = renderer.shapeBatch;
38-
var vertexDataBuffer = shapeBatch.vertexDataBuffer;
39-
var vertexBufferF32 = vertexDataBuffer.floatView;
40-
var vertexBufferU32 = vertexDataBuffer.uintView;
41-
var vertexOffset = 0;
4239
var cameraScrollX = camera.scrollX * gameObject.scrollFactorX;
4340
var cameraScrollY = camera.scrollY * gameObject.scrollFactorY;
44-
const srcX = gameObject.x - cameraScrollX;
45-
const srcY = gameObject.y - cameraScrollY;
46-
const srcScaleX = gameObject.scaleX;
47-
const srcScaleY = gameObject.scaleY;
48-
const srcRotation = -gameObject.rotation;
41+
var srcX = gameObject.x - cameraScrollX;
42+
var srcY = gameObject.y - cameraScrollY;
43+
var srcScaleX = gameObject.scaleX;
44+
var srcScaleY = gameObject.scaleY;
45+
var srcRotation = -gameObject.rotation;
4946
var commandBuffer = gameObject.commandBuffer;
50-
var value;
5147
var lineAlpha = 1.0;
5248
var fillAlpha = 1.0;
5349
var lineColor = 0;
@@ -61,22 +57,10 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
6157
var ty = 0;
6258
var ta = 0;
6359
var x, y, radius, startAngle, endAngle, anticlockwise;
64-
var width, height, txw, tyh;
65-
var vertexCount = shapeBatch.vertexCount;
66-
var polygon = [];
67-
var x0, y0, x1, y1, x2, y2;
68-
var tx0, ty0, tx1, ty1, tx2, ty2;
69-
var v0, v1, v2;
70-
var polygonIndex;
7160
var path;
72-
var pathLength;
73-
var point;
74-
var maxVertices = shapeBatch.maxVertices;
75-
var translateX, translateY;
7661
var tempMatrixMatrix = tempMatrix.matrix;
7762
var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf;
7863
var mva, mvb, mvc, mvd, mve, mvf;
79-
var abs = Math.abs;
8064

8165
tempMatrix.applyITRS(srcX, srcY, srcRotation, srcScaleX, srcScaleY);
8266

@@ -105,9 +89,9 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
10589

10690
for (var cmdIndex = 0, cmdLength = commandBuffer.length; cmdIndex < cmdLength; ++cmdIndex)
10791
{
108-
var cmd = commandBuffer[cmdIndex];
92+
cmd = commandBuffer[cmdIndex];
10993

110-
switch(cmd)
94+
switch (cmd)
11195
{
11296
case Commands.ARC:
11397
iteration = 0;
@@ -198,7 +182,7 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
198182
pathArrayIndex < pathArrayLength;
199183
++pathArrayIndex)
200184
{
201-
var path = pathArray[pathArrayIndex];
185+
path = pathArray[pathArrayIndex];
202186
shapeBatch.addStrokePath(
203187
/* Graphics Game Object Properties */
204188
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
@@ -211,7 +195,6 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
211195
mva, mvb, mvc, mvd, mve, mvf,
212196
path === this._lastPath,
213197
currentMatrix
214-
215198
);
216199
}
217200
break;
@@ -230,7 +213,6 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
230213
/* Transform */
231214
mva, mvb, mvc, mvd, mve, mvf,
232215
currentMatrix
233-
234216
);
235217

236218
cmdIndex += 4;
@@ -252,7 +234,6 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
252234
/* Transform */
253235
mva, mvb, mvc, mvd, mve, mvf,
254236
currentMatrix
255-
256237
);
257238

258239
cmdIndex += 6;
@@ -275,11 +256,10 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
275256
/* Transform */
276257
mva, mvb, mvc, mvd, mve, mvf,
277258
currentMatrix
278-
279259
);
280260

281261
cmdIndex += 6;
282-
break
262+
break;
283263

284264
case Commands.LINE_TO:
285265
if (lastPath !== null)
@@ -304,8 +284,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
304284
if (lastPath !== null)
305285
{
306286
lastPath.points.push(new Point(
307-
commandBuffer[cmdIndex + 1],
308-
commandBuffer[cmdIndex + 2],
287+
commandBuffer[cmdIndex + 1],
288+
commandBuffer[cmdIndex + 2],
309289
commandBuffer[cmdIndex + 3],
310290
commandBuffer[cmdIndex + 4],
311291
commandBuffer[cmdIndex + 5]
@@ -314,8 +294,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
314294
else
315295
{
316296
lastPath = new Path(
317-
commandBuffer[cmdIndex + 1],
318-
commandBuffer[cmdIndex + 2],
297+
commandBuffer[cmdIndex + 1],
298+
commandBuffer[cmdIndex + 2],
319299
commandBuffer[cmdIndex + 3],
320300
commandBuffer[cmdIndex + 4],
321301
commandBuffer[cmdIndex + 5]
@@ -327,8 +307,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
327307

328308
case Commands.MOVE_FX_TO:
329309
lastPath = new Path(
330-
commandBuffer[cmdIndex + 1],
331-
commandBuffer[cmdIndex + 2],
310+
commandBuffer[cmdIndex + 1],
311+
commandBuffer[cmdIndex + 2],
332312
commandBuffer[cmdIndex + 3],
333313
commandBuffer[cmdIndex + 4],
334314
commandBuffer[cmdIndex + 5]
@@ -385,6 +365,7 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
385365
break;
386366
}
387367
}
368+
388369
currentMatrix.loadIdentity();
389370
pathArray.length = 0;
390371
};

0 commit comments

Comments
 (0)