Skip to content

Commit a5b86c1

Browse files
committed
Adding predicate to renderTargets
1 parent 5a00f2c commit a5b86c1

File tree

12 files changed

+438
-398
lines changed

12 files changed

+438
-398
lines changed

dist/preview release/babylon.core.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/preview release/babylon.d.ts

Lines changed: 286 additions & 290 deletions
Large diffs are not rendered by default.

dist/preview release/babylon.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/preview release/babylon.max.js

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21167,6 +21167,9 @@ var BABYLON;
2116721167
if (isCube === void 0) { isCube = false; }
2116821168
_super.call(this, null, scene, !generateMipMaps);
2116921169
this.isCube = isCube;
21170+
/**
21171+
* Use this list to define the list of mesh you want to render.
21172+
*/
2117021173
this.renderList = new Array();
2117121174
this.renderParticles = true;
2117221175
this.renderSprites = false;
@@ -21346,6 +21349,17 @@ var BABYLON;
2134621349
}
2134721350
delete this._waitingRenderList;
2134821351
}
21352+
// Is predicate defined?
21353+
if (this.renderListPredicate) {
21354+
this.renderList.splice(0); // Clear previous renderList
21355+
var sceneMeshes = this.getScene().meshes;
21356+
for (var index = 0; index < sceneMeshes.length; index++) {
21357+
var mesh = sceneMeshes[index];
21358+
if (this.renderListPredicate(mesh)) {
21359+
this.renderList.push(mesh);
21360+
}
21361+
}
21362+
}
2134921363
if (this.renderList && this.renderList.length === 0) {
2135021364
return;
2135121365
}
@@ -36473,6 +36487,15 @@ var BABYLON;
3647336487
enumerable: true,
3647436488
configurable: true
3647536489
});
36490+
IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
36491+
for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
36492+
var cur = _a[_i];
36493+
if (cur.prim === prim) {
36494+
return cur.intersectionLocation;
36495+
}
36496+
}
36497+
return null;
36498+
};
3647636499
// Internals, don't use
3647736500
IntersectInfo2D.prototype._exit = function (firstLevel) {
3647836501
if (firstLevel) {
@@ -36877,9 +36900,8 @@ var BABYLON;
3687736900
this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
3687836901
};
3687936902
Prim2DBase.prototype.addChild = function (child) {
36880-
child._siblingDepthOffset = (this._children.length + 1) * this.owner.hierarchySiblingZDelta;
36881-
child._depthLevel = this._depthLevel + 1;
36882-
child._hierarchyDepthOffset = child._depthLevel * this.owner.hierarchyLevelZFactor;
36903+
child._hierarchyDepthOffset = this._hierarchyDepthOffset + ((this._children.length + 1) * this._siblingDepthOffset);
36904+
child._siblingDepthOffset = this._siblingDepthOffset / this.owner.hierarchyLevelMaxSiblingCount;
3688336905
this._children.push(child);
3688436906
};
3688536907
Prim2DBase.prototype.dispose = function () {
@@ -36907,15 +36929,15 @@ var BABYLON;
3690736929
return true;
3690836930
};
3690936931
Prim2DBase.prototype.getActualZOffset = function () {
36910-
return this._zOrder || 1 - (this._siblingDepthOffset + this._hierarchyDepthOffset);
36932+
return this._zOrder || (1 - this._hierarchyDepthOffset);
3691136933
};
3691236934
Prim2DBase.prototype.onPrimBecomesDirty = function () {
3691336935
if (this._renderGroup) {
3691436936
this._renderGroup._addPrimToDirtyList(this);
3691536937
}
3691636938
};
3691736939
Prim2DBase.prototype._needPrepare = function () {
36918-
return this._visibilityChanged && (this._modelDirty || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep));
36940+
return this._visibilityChanged || this._modelDirty || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
3691936941
};
3692036942
Prim2DBase.prototype._prepareRender = function (context) {
3692136943
this._prepareRenderPre(context);
@@ -39013,6 +39035,10 @@ var BABYLON;
3901339035
}
3901439036
return res;
3901539037
};
39038+
Sprite2D.prototype.levelIntersect = function (intersectInfo) {
39039+
// If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
39040+
return true;
39041+
};
3901639042
Sprite2D.prototype.setupSprite2D = function (owner, parent, id, position, texture, spriteSize, spriteLocation, invertY) {
3901739043
this.setupRenderablePrim2D(owner, parent, id, position, true);
3901839044
this.texture = texture;
@@ -39353,6 +39379,10 @@ var BABYLON;
3935339379
text2d.setupText2D(parent.owner, parent, id, new BABYLON.Vector2(x, y), fontName, text, areaSize, defaultFontColor || new BABYLON.Color4(0, 0, 0, 1), vAlign, hAlign, tabulationSize);
3935439380
return text2d;
3935539381
};
39382+
Text2D.prototype.levelIntersect = function (intersectInfo) {
39383+
// For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
39384+
return true;
39385+
};
3935639386
Text2D.prototype.createModelRenderCache = function (modelKey, isTransparent) {
3935739387
var renderCache = new Text2DRenderCache(this.owner.engine, modelKey, isTransparent);
3935839388
return renderCache;
@@ -39590,15 +39620,13 @@ var BABYLON;
3959039620
}
3959139621
this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
3959239622
this._cachingStrategy = cachingstrategy;
39593-
this._depthLevel = 0;
39594-
this._hierarchyMaxDepth = 100;
39595-
this._hierarchyLevelZFactor = 1 / this._hierarchyMaxDepth;
39596-
this._hierarchyLevelMaxSiblingCount = 1000;
39597-
this._hierarchySiblingZDelta = this._hierarchyLevelZFactor / this._hierarchyLevelMaxSiblingCount;
3959839623
this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
3959939624
this._capturedPointers = new BABYLON.StringDictionary();
3960039625
this._pickStartingPosition = BABYLON.Vector2.Zero();
3960139626
this.setupGroup2D(this, null, name, BABYLON.Vector2.Zero(), size, this._cachingStrategy === Canvas2D.CACHESTRATEGY_ALLGROUPS ? BABYLON.Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE : BABYLON.Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY);
39627+
this._hierarchyLevelMaxSiblingCount = 100;
39628+
this._hierarchyDepthOffset = 0;
39629+
this._siblingDepthOffset = 1 / this._hierarchyLevelMaxSiblingCount;
3960239630
this._scene = scene;
3960339631
this._engine = engine;
3960439632
this._renderingSize = new BABYLON.Size(0, 0);
@@ -39628,6 +39656,13 @@ var BABYLON;
3962839656
// this._supprtInstancedArray = false; // TODO REMOVE!!!
3962939657
this._setupInteraction(enableInteraction);
3963039658
};
39659+
Object.defineProperty(Canvas2D.prototype, "hierarchyLevelMaxSiblingCount", {
39660+
get: function () {
39661+
return this._hierarchyLevelMaxSiblingCount;
39662+
},
39663+
enumerable: true,
39664+
configurable: true
39665+
});
3963139666
Canvas2D.prototype._setupInteraction = function (enable) {
3963239667
var _this = this;
3963339668
// No change detection
@@ -39915,12 +39950,11 @@ var BABYLON;
3991539950
ii.pickPosition = ppi.canvasPointerPos.clone();
3991639951
ii.findFirstOnly = false;
3991739952
_this.intersect(ii);
39918-
if (ii.isIntersected) {
39919-
var iprim = ii.topMostIntersectedPrimitive.prim;
39920-
if (iprim.actionManager) {
39953+
if (ii.isPrimIntersected(prim) !== null) {
39954+
if (prim.actionManager) {
3992139955
if (_this._pickStartingTime !== 0 && ((new Date().getTime() - _this._pickStartingTime) > BABYLON.ActionManager.LongPressDelay) && (Math.abs(_this._pickStartingPosition.x - ii.pickPosition.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._pickStartingPosition.y - ii.pickPosition.y) < BABYLON.ActionManager.DragMovementThreshold)) {
3992239956
_this._pickStartingTime = 0;
39923-
iprim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
39957+
prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
3992439958
}
3992539959
}
3992639960
}
@@ -40147,30 +40181,6 @@ var BABYLON;
4014740181
throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
4014840182
}
4014940183
};
40150-
Object.defineProperty(Canvas2D.prototype, "hierarchySiblingZDelta", {
40151-
/**
40152-
* Read-only property that return the Z delta to apply for each sibling primitives inside of a given one.
40153-
* Sibling Primitives are defined in a specific order, the first ones will be draw below the next ones.
40154-
* This property define the Z value to apply between each sibling Primitive. Current implementation allows 1000 Siblings Primitives per level.
40155-
* @returns The Z Delta
40156-
*/
40157-
get: function () {
40158-
return this._hierarchySiblingZDelta;
40159-
},
40160-
enumerable: true,
40161-
configurable: true
40162-
});
40163-
Object.defineProperty(Canvas2D.prototype, "hierarchyLevelZFactor", {
40164-
/**
40165-
* Return the Z Factor that will be applied for each new hierarchy level.
40166-
* @returns The Z Factor
40167-
*/
40168-
get: function () {
40169-
return this._hierarchyLevelZFactor;
40170-
},
40171-
enumerable: true,
40172-
configurable: true
40173-
});
4017440184
Canvas2D.prototype._updateCanvasState = function () {
4017540185
// Check if the update has already been made for this render Frame
4017640186
if (this.scene.getRenderId() === this._updateRenderId) {

dist/preview release/babylon.noworker.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/preview release/what's new.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- Added a dynamic [2D Bin Packing Algorithm](http://stackoverflow.com/questions/8762569/how-is-2d-bin-packing-achieved-programmatically), ([more info here](http://www.html5gamedevs.com/topic/22565-two-new-texture-types-fonttexture-and-maptexture/)) ([nockawa](https://github.com/nockawa))
2121
- Introduced Canvas2D feature: a 2D engine to render primitives, sprites in 2D, text. Canvas2D can be displayed in Screen Space (above the 3D scene) or in World Space to be a part of the Scene. [overview](http://doc.babylonjs.com/overviews/Using_The_Canvas2D), [tutorial](http://doc.babylonjs.com/tutorials/Using_the_Canvas2D) ([nockawa](https://github.com/nockawa))
2222
- **Updates**
23+
- Renderlists can now also be defined using predicates ([deltakosh](https://github.com/deltakosh))
2324
- Added support for various normal maps conventions ([deltakosh](https://github.com/deltakosh))
2425
- Added postprocess.enablePixelPerfectMode to avoid texture scaling/stretching when dealing with non-power of 2 resolutions. cannot be used on post-processes chain ([deltakosh](https://github.com/deltakosh))
2526
- Enabled other post processes to be used when also using a 3D Rig ([jcpalmer](https://github.com/Palmer-JC))

src/Canvas2d/babylon.canvas2d.js

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,13 @@ var BABYLON;
107107
}
108108
this.__engineData = engine.getOrAddExternalDataWithFactory("__BJSCANVAS2D__", function (k) { return new Canvas2DEngineBoundData(); });
109109
this._cachingStrategy = cachingstrategy;
110-
this._depthLevel = 0;
111-
this._hierarchyMaxDepth = 100;
112-
this._hierarchyLevelZFactor = 1 / this._hierarchyMaxDepth;
113-
this._hierarchyLevelMaxSiblingCount = 1000;
114-
this._hierarchySiblingZDelta = this._hierarchyLevelZFactor / this._hierarchyLevelMaxSiblingCount;
115110
this._primPointerInfo = new BABYLON.PrimitivePointerInfo();
116111
this._capturedPointers = new BABYLON.StringDictionary();
117112
this._pickStartingPosition = BABYLON.Vector2.Zero();
118113
this.setupGroup2D(this, null, name, BABYLON.Vector2.Zero(), size, this._cachingStrategy === Canvas2D.CACHESTRATEGY_ALLGROUPS ? BABYLON.Group2D.GROUPCACHEBEHAVIOR_DONTCACHEOVERRIDE : BABYLON.Group2D.GROUPCACHEBEHAVIOR_FOLLOWCACHESTRATEGY);
114+
this._hierarchyLevelMaxSiblingCount = 100;
115+
this._hierarchyDepthOffset = 0;
116+
this._siblingDepthOffset = 1 / this._hierarchyLevelMaxSiblingCount;
119117
this._scene = scene;
120118
this._engine = engine;
121119
this._renderingSize = new BABYLON.Size(0, 0);
@@ -145,6 +143,13 @@ var BABYLON;
145143
// this._supprtInstancedArray = false; // TODO REMOVE!!!
146144
this._setupInteraction(enableInteraction);
147145
};
146+
Object.defineProperty(Canvas2D.prototype, "hierarchyLevelMaxSiblingCount", {
147+
get: function () {
148+
return this._hierarchyLevelMaxSiblingCount;
149+
},
150+
enumerable: true,
151+
configurable: true
152+
});
148153
Canvas2D.prototype._setupInteraction = function (enable) {
149154
var _this = this;
150155
// No change detection
@@ -432,12 +437,11 @@ var BABYLON;
432437
ii.pickPosition = ppi.canvasPointerPos.clone();
433438
ii.findFirstOnly = false;
434439
_this.intersect(ii);
435-
if (ii.isIntersected) {
436-
var iprim = ii.topMostIntersectedPrimitive.prim;
437-
if (iprim.actionManager) {
440+
if (ii.isPrimIntersected(prim) !== null) {
441+
if (prim.actionManager) {
438442
if (_this._pickStartingTime !== 0 && ((new Date().getTime() - _this._pickStartingTime) > BABYLON.ActionManager.LongPressDelay) && (Math.abs(_this._pickStartingPosition.x - ii.pickPosition.x) < BABYLON.ActionManager.DragMovementThreshold && Math.abs(_this._pickStartingPosition.y - ii.pickPosition.y) < BABYLON.ActionManager.DragMovementThreshold)) {
439443
_this._pickStartingTime = 0;
440-
iprim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
444+
prim.actionManager.processTrigger(BABYLON.ActionManager.OnLongPressTrigger, BABYLON.ActionEvent.CreateNewFromPrimitive(prim, ppi.primitivePointerPos, eventData));
441445
}
442446
}
443447
}
@@ -664,30 +668,6 @@ var BABYLON;
664668
throw Error("Can't use Canvas Background with the caching strategy TOPLEVELGROUPS");
665669
}
666670
};
667-
Object.defineProperty(Canvas2D.prototype, "hierarchySiblingZDelta", {
668-
/**
669-
* Read-only property that return the Z delta to apply for each sibling primitives inside of a given one.
670-
* Sibling Primitives are defined in a specific order, the first ones will be draw below the next ones.
671-
* This property define the Z value to apply between each sibling Primitive. Current implementation allows 1000 Siblings Primitives per level.
672-
* @returns The Z Delta
673-
*/
674-
get: function () {
675-
return this._hierarchySiblingZDelta;
676-
},
677-
enumerable: true,
678-
configurable: true
679-
});
680-
Object.defineProperty(Canvas2D.prototype, "hierarchyLevelZFactor", {
681-
/**
682-
* Return the Z Factor that will be applied for each new hierarchy level.
683-
* @returns The Z Factor
684-
*/
685-
get: function () {
686-
return this._hierarchyLevelZFactor;
687-
},
688-
enumerable: true,
689-
configurable: true
690-
});
691671
Canvas2D.prototype._updateCanvasState = function () {
692672
// Check if the update has already been made for this render Frame
693673
if (this.scene.getRenderId() === this._updateRenderId) {

src/Canvas2d/babylon.prim2dBase.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ var BABYLON;
207207
enumerable: true,
208208
configurable: true
209209
});
210+
IntersectInfo2D.prototype.isPrimIntersected = function (prim) {
211+
for (var _i = 0, _a = this.intersectedPrimitives; _i < _a.length; _i++) {
212+
var cur = _a[_i];
213+
if (cur.prim === prim) {
214+
return cur.intersectionLocation;
215+
}
216+
}
217+
return null;
218+
};
210219
// Internals, don't use
211220
IntersectInfo2D.prototype._exit = function (firstLevel) {
212221
if (firstLevel) {
@@ -611,9 +620,8 @@ var BABYLON;
611620
this._children.splice(prevIndex + 1, 0, this._children.splice(childIndex, 1)[0]);
612621
};
613622
Prim2DBase.prototype.addChild = function (child) {
614-
child._siblingDepthOffset = (this._children.length + 1) * this.owner.hierarchySiblingZDelta;
615-
child._depthLevel = this._depthLevel + 1;
616-
child._hierarchyDepthOffset = child._depthLevel * this.owner.hierarchyLevelZFactor;
623+
child._hierarchyDepthOffset = this._hierarchyDepthOffset + ((this._children.length + 1) * this._siblingDepthOffset);
624+
child._siblingDepthOffset = this._siblingDepthOffset / this.owner.hierarchyLevelMaxSiblingCount;
617625
this._children.push(child);
618626
};
619627
Prim2DBase.prototype.dispose = function () {
@@ -641,15 +649,15 @@ var BABYLON;
641649
return true;
642650
};
643651
Prim2DBase.prototype.getActualZOffset = function () {
644-
return this._zOrder || 1 - (this._siblingDepthOffset + this._hierarchyDepthOffset);
652+
return this._zOrder || (1 - this._hierarchyDepthOffset);
645653
};
646654
Prim2DBase.prototype.onPrimBecomesDirty = function () {
647655
if (this._renderGroup) {
648656
this._renderGroup._addPrimToDirtyList(this);
649657
}
650658
};
651659
Prim2DBase.prototype._needPrepare = function () {
652-
return this._visibilityChanged && (this._modelDirty || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep));
660+
return this._visibilityChanged || this._modelDirty || (this._instanceDirtyFlags !== 0) || (this._globalTransformProcessStep !== this._globalTransformStep);
653661
};
654662
Prim2DBase.prototype._prepareRender = function (context) {
655663
this._prepareRenderPre(context);

src/Canvas2d/babylon.sprite2d.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ var BABYLON;
201201
}
202202
return res;
203203
};
204+
Sprite2D.prototype.levelIntersect = function (intersectInfo) {
205+
// If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
206+
return true;
207+
};
204208
Sprite2D.prototype.setupSprite2D = function (owner, parent, id, position, texture, spriteSize, spriteLocation, invertY) {
205209
this.setupRenderablePrim2D(owner, parent, id, position, true);
206210
this.texture = texture;

src/Canvas2d/babylon.text2d.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ var BABYLON;
248248
text2d.setupText2D(parent.owner, parent, id, new BABYLON.Vector2(x, y), fontName, text, areaSize, defaultFontColor || new BABYLON.Color4(0, 0, 0, 1), vAlign, hAlign, tabulationSize);
249249
return text2d;
250250
};
251+
Text2D.prototype.levelIntersect = function (intersectInfo) {
252+
// For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
253+
return true;
254+
};
251255
Text2D.prototype.createModelRenderCache = function (modelKey, isTransparent) {
252256
var renderCache = new Text2DRenderCache(this.owner.engine, modelKey, isTransparent);
253257
return renderCache;

0 commit comments

Comments
 (0)