ObjectContainer3D objects disappearing?

Software: Away3D 4.x

OEGInc, Newbie
Posted: 02 April 2014 02:30 PM   Total Posts: 27

I know I’m doing something wrong, if someone might be able to point me in the right direction I’d appreciate it.

What I’m trying to do is create a base class that holds the code for my “generic” enemy (Ie: loading meshes, animations, textures, performing movement, etc) called genericEnemy.  Then for specific enemies, I created a class that extends genericEnemy calling super(modelName, textureName) to load the model & texture specific to that enemy.  So far so good….

Here is where I think the problem is, genericEnemy extends ObjectContainer3D (I’m not familiar with all of the various classes in Away3D but that seemed the most appropriate).  Everything works GREAT!  (As long as I only have one enemy on the screen…)  As soon as I create the second enemy, the first one disappears.

I think this has something to do with the ObjectContainer3D using scene partitions?

So my two questions are, does it make sense to use ObjectContainer3D as I thought, or is there something better?

And how can I make ObjectContainer3D not clear the existing scene when added?

Thanks!
—Rob

   

Avatar
mrpinc, Sr. Member
Posted: 02 April 2014 07:39 PM   Total Posts: 119   [ # 1 ]

You’re going to need to supply some sample code in order for us to give you some help.

I imagine when you say 1 enemy appears the other disappears you are talking about enemies that share the same 3d model.  Most likely what is happening is that both enemies share the same Mesh instance.  What you might need to do is create new mesh objects, while sharing the same underlying geometry.

So for example if you load 3d model called box.obj but you need to replicate that model, you would create a new Mesh() for each instance you need to see on screen and you would pass the original box.obj geometry to each mesh.

   

OEGInc, Newbie
Posted: 02 April 2014 08:26 PM   Total Posts: 27   [ # 2 ]

I really appreciate you taking the time to respond.  For some reason my brain is in the fog right now and I can use a second set of eyes…

Here is the WorkerBase.as class:  WorkerBase.as

And here is a WorkerTest.as class:  WorkerTest.as

And then I call it from my application as:

_worker1 = new WorkerTest();
_worker1.x = xPos1;
_worker1.z = zPos1;
_view.scene.addChild(_worker1);

_worker2 = new WorkerTest();
_worker2.x = xPos2;
_worker2.z = zPos2;
_view.scene.addChild(_worker2);

And as soon as _worker2 pops into the scene, _worker1 disappears.

Thanks!
—Rob

   

Avatar
mrpinc, Sr. Member
Posted: 02 April 2014 08:37 PM   Total Posts: 119   [ # 3 ]

It looks like it is precisely as I said.  Both instances of WorkerTest() are using the same underlying Mesh instance.  You will need to create a new Mesh for each instance and re-use the loaded geometry.

   

OEGInc, Newbie
Posted: 02 April 2014 09:02 PM   Total Posts: 27   [ # 4 ]
mrpinc - 02 April 2014 08:37 PM

It looks like it is precisely as I said.  Both instances of WorkerTest() are using the same underlying Mesh instance.  You will need to create a new Mesh for each instance and re-use the loaded geometry.

Cool, thanks!  I think that fixed it..  I wasn’t away that the model loader was able to provide the geometry, I thought only the mesh…

Now the better question, does what I am doing make any sense to you, or am I completely off base?  smile

Thanks for your help!
—Rob

 

   

Avatar
mrpinc, Sr. Member
Posted: 02 April 2014 09:13 PM   Total Posts: 119   [ # 5 ]

I’ve seen much worse code but the general rule is favor composition over inheritance so rather than having each enemy type creating a new class you might be better off with creating a single entity class and add/remove behaviors via a component system.  But that is a design decision, using inheritance can work very well if the scope of your game is small.  If you are planning a lot of features you might want to look into an Entity/Component model.

   

OEGInc, Newbie
Posted: 03 April 2014 12:02 PM   Total Posts: 27   [ # 6 ]

I was actually working on implementing my own rudimentary version of something resembling an entity system, but then I stumbled across ASH.

Have you seen this framework yet?  It’s a little confusing at first, but I think I’m starting to understand it.  After reading a few of the comments though, some are complaining about it not being a “true” Entity/Component system and I’m afraid I don’t know enough about them to judge either way.

Is there any particular library you would/could recommend, or should I just continue to roll-my-own (which seems very redundant at this point).

Thanks!
—Rob

   

Avatar
mrpinc, Sr. Member
Posted: 03 April 2014 12:16 PM   Total Posts: 119   [ # 7 ]

Ash is tremendous.

   

OEGInc, Newbie
Posted: 04 April 2014 10:54 PM   Total Posts: 27   [ # 8 ]

Question:

So I’ve created a RenderSystem to render 2D objects in the game (HUD, scores, etc), and I created a RenderSystem3D to handle all of the 3D objects in the game.

I then created a GroundPlane component and a GroundPlaneView to create the ground.  I call it like:

groundPlane:Entity = new Entity()
  .add(new GroundPlane(320, 320))
  .add(new Position3D(0, 0, 0))
  .add(new Display3D(new GroundPlaneView()))

And it seems to work well (320 x 320 is the size in case you were wondering).  So GroundPlane class (component) just holds the ground size variables.  GroundPlaneView takes care of what the 3D model of the ground looks like.  And any entities that have a Position3D and Display3D property are rendered by the RenderSystem3D.

The problem is, how do I pull the values out of GroundPlane from within GroundPlaneView in an ASH’ist way?  Right now, just for testing, I hardcoded the 320x320 into the GroundPlaneView…

Thanks!
—Rob

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X