storing extra info in a 3dobject

Software: Away3D 4.x

Avatar
maddog, Sr. Member
Posted: 15 November 2011 05:33 AM   Total Posts: 118

Is there a way to store extra information in a object.

for example:
plane.info1 = “red”;
plane.info2 = 22;
plane.info3 = material1;

This could be really handy if you wanted to store extra info about a 3d object in itself instead of externally.

This is how a non 3d object in programing works so why is this not applied to the 3d objects or maybe it is?

Thanks for any help.

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 November 2011 06:03 AM   Total Posts: 344   [ # 1 ]

I’m not on my computer with my work on at the mo, but you can do that with a 3d object (and with many other objects in as3) by asigning a .extra.whateveryouwanttocallit to it..

So in your example you’d have plane.extra.info1 and so on.

I’m sure someone will swing past with an example in the meantime, but if you reply to this so I get an email tomorrow I’ll post you an example..

   

Avatar
maddog, Sr. Member
Posted: 15 November 2011 03:21 PM   Total Posts: 118   [ # 2 ]

sweet could you show me an example.

   

Piwie, Newbie
Posted: 15 November 2011 05:26 PM   Total Posts: 4   [ # 3 ]

plane.extra.info1 = “red”;
plane.extra.info2 = 22;
plane.extra.info3 = material1;

That’s all you need.

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 November 2011 07:25 PM   Total Posts: 344   [ # 4 ]
Materials = new BitmapMaterial (BitmapData);

var 
p:Cube = new CubeMaterialswhd111true);
p.extra {
info1
: new Number,
info2: new String,
info3Boolean,
info4MovieClip
}

//and then you can just do
p.extra.info1 30;
p.extra.info2 "red";
p.extra.info3 false;
p.extra.info4 testMC

I’ve just typed this here referenceing working code but not testing the above, but it should get you started.


Like I say, the “.extra.——-” method works with movieClips, ObjectContainer3D, and I should imagine lots of other stuff in AS3..

   

Alex Bogartz, Sr. Member
Posted: 15 November 2011 08:01 PM   Total Posts: 216   [ # 5 ]

At least in the version I have, extra defaults as null, so if you try to simply say object.extra.foo=“bar”; it will throw an exception.

You have to first say object.extra={}; or do what Margaret Scratcher did above.

   

Avatar
Darcey, Moderator
Posted: 15 November 2011 09:36 PM   Total Posts: 209   [ # 6 ]

Why don’t you create a base class for your objects eg:

file CustomCube.as

public class CustomCube extends Cube
{
  public var infoVariableName1:Number = 0;
  public var infoVariableName2:String = “”;
  public var infoVariableName3:Boolean = false;

  public function CustomCube()
  {
  }
}

Then you can simply:

var c1:CustomCube = new CustomCube();
c1.material = yourMaterialVariable;
c1.infoVariableName1 = 30;
c1.infoVariableName2 = “bluey greeny mixed with a dash of yellow”;
c1.infoVariableName3 = true;

trace(“c1.infoVariableName1 = ” + c1.infoVariableName1);
trace(“c1.infoVariableName2 = ” + c1.infoVariableName2);
trace(“c1.infoVariableName3 = ” + c1.infoVariableName3);

   

Avatar
maddog, Sr. Member
Posted: 15 November 2011 10:10 PM   Total Posts: 118   [ # 7 ]

Doing this works for me. I was getting errors because i failed to do the first line of code. I like simple because I’m simple.

3dObject.extra = [];
3dObject.extra.info1 = 38;
3dObject.extra.info2 = true;
3dObject.extra.info3 = “tester”;
3dObject.extra.info4 = material;

Thanks for all the Ideas!!!!

   

Avatar
maddog, Sr. Member
Posted: 15 November 2011 10:16 PM   Total Posts: 118   [ # 8 ]

my next question is. How do you set one object to be the pivot point of another object. I am storing the name of the object that is the axis for the others in those objects through the use of 3dObject.extra.info1 = “cube1”;
Thanks for the help!!!

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 November 2011 11:19 PM   Total Posts: 344   [ # 9 ]

Yeah, making a custom class seems a bit overkill, especially as it doen’t seem, to me at least, to offer any advantages over doing it on the fly, as you would any other ActionScript object..


As for your problem above, after you store the name of the object like that, does

trace (3dObject.extra.info1) return the name, or (from memory again) object[cube] or whatever the object actually was?

   

Avatar
maddog, Sr. Member
Posted: 16 November 2011 12:06 AM   Total Posts: 118   [ # 10 ]

I am just storing the name of the 3dObject. I would access it by using assetlibrary. although I could probably store a pointer to that object in 3dObject.extra.info1

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X