Skip to content

Commit

Permalink
Fixed some bugs with fx init and added a way to force init of prefabs…
Browse files Browse the repository at this point in the history
… without root2d/3d
  • Loading branch information
EspeuteClement committed Jan 19, 2024
1 parent 1d7787a commit f6c3833
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions hrt/prefab/ContextShared.hx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class ContextShared {
// Parent prefab if the object if it was created as a reference
public var parent : Prefab = null;

/**
Disable some checks at the prefab instanciation time. Used to initialize prefabs that
don't need locals2d/3d like shaders
**/
public var forceInstanciate : Bool = false;

var bakedData : Map<String, haxe.io.Bytes>;

public function new( ?res : hxd.res.Resource, ?root2d: h2d.Object = null, ?root3d: h3d.scene.Object = null) {
Expand Down
4 changes: 2 additions & 2 deletions hrt/prefab/Prefab.hx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Prefab {

// Create the hierarchy of heaps objects from this prefab. Can only be done on cloned prefabs or if forceInstanciate is true ()
public function instanciate() {
if (shared.root2d == null || shared.root3d == null)
if (shared.root2d == null && shared.root3d == null && !shared.forceInstanciate)
throw "Can't instanciate a template prefab.";

var old2d = shared.current2d;
Expand Down Expand Up @@ -557,7 +557,7 @@ class Prefab {
*/

function shouldBeInstanciated() : Bool {
if (shared.root2d == null || shared.root3d == null)
if (shared.root2d == null && shared.root3d == null && !shared.forceInstanciate)
throw "Prefab is missing a shared context for instanciation";

if (!enabled) return false;
Expand Down
5 changes: 2 additions & 3 deletions hrt/prefab/fx/FX.hx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class FXAnimation extends h3d.scene.Object {
}

function initObjAnimations(elt: PrefabElement) {
if(!elt.enabled) return;
if(@:privateAccess !elt.shouldBeInstanciated()) return;
if(Std.downcast(elt, hrt.prefab.fx.Emitter) == null) {
// Don't extract animations for children of Emitters
for(c in elt.children) {
Expand Down Expand Up @@ -335,8 +335,7 @@ class FXAnimation extends h3d.scene.Object {

var ap : AdditionalProperies = null;
var local3d = Object3D.getLocal3d(elt);
if (local3d == null)
trace("break");

if( Std.isOfType(local3d, h3d.scene.pbr.PointLight)) {
ap = PointLight(makeColor("color"), makeVal("power", null), makeVal("size", null), makeVal("range", null) );
}
Expand Down

0 comments on commit f6c3833

Please sign in to comment.