Hi there, building external classes is something I’ve wanted to get my head around for a while, so I thought I’d start by trying to make a multi-Material Cube, as it’s something that I find I need quite often, and from a few similar posts it seems that others do too.
I’ve got it working as a function, taking
(height,width,depth,face1Mat,face2Mat,face3Mat,face4Mat,face5mat,face6Mat)
and making an appropriately sized and material’ed cube, but now what I want to do is take that and make it into a class, so I can just do
var multiCube:multiMatCube = new multiMatCube (height,width,depth,face1Mat,face2Mat,face3Mat,face4Mat,face5mat,face6Mat)
and get the same result.
At the moment i have it in the same folder as my base class, and so as I start typing multiMatCube it pops up, and appears in blue, and gives me hinst as I start to fill in the variables, so that bit is working, but what I get when I try to add it to the view is
Error: Implicit coercion of a value of type multiMatCube to an unrelated type away3d.containers:ObjectContainer3D.
How do I get it to return the container that all the planes are in?
Also, can I access the various faces from the bass class by doing
multiCube.face1 ? And say add event listeners?
The other things I’m not sure on is what I need to include - do things like eventlisteners need to be included, or is including them on the base class going to be okay? Same with materials..
Also, currently the class extends sprite, is that right? Does it have to extend anything?
What about namespace arcane - not sure what that even means…
Anyways, here it is:
package
{
import away3d.containers.ObjectContainer3D;
import away3d.entities.Mesh;
import away3d.entities.Entity;
import away3d.materials.MaterialBase;
import away3d.materials.TextureMaterial;
import away3d.textures.BitmapTexture;
import away3d.events.LoaderEvent;
import away3d.events.MouseEvent3D;
import away3d.materials.lightpickers.*;
import away3d.materials.methods.EnvMapMethod;
import away3d.materials.ColorMaterial;
import away3d.materials.DefaultMaterialBase;
import away3d.materials.BitmapMaterial;
import away3d.primitives.PlaneGeometry;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.system.LoaderContext;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.geom.Matrix;
import flash.system.Security;
//use namespace arcane;
public class multiMatCube extends Sprite
{
var planesContainer:ObjectContainer3D = new ObjectContainer3D;
var face1:Mesh;
var face2:Mesh;
var face3:Mesh;
var face4:Mesh;
var face5:Mesh;
var face6:Mesh;
public function multiMatCube(height,width,depth,face1Mat,face2Mat,face3Mat,face4Mat,face5mat,face6Mat):void
{
//trace ("creating multicube")
var faceGeometry:PlaneGeometry = new PlaneGeometry(1, 1, 1, 1 )
//Top
face1 = new Mesh(faceGeometry, face1Mat );
face1.scaleX = width;
face1.scaleZ = depth;
face1.rotationX = 0
face1.y = height / 2;
//Bottom
face2 = new Mesh(faceGeometry, face2Mat);
face2.scaleX = width;
face2.scaleZ = depth;
face2.rotationX = 180;
face2.y = -height/2;
//back
face3 = new Mesh (faceGeometry, face3Mat);
face3.scaleX = width;
face3.scaleZ = height;
face3.rotationX = 90
face3.z = depth / 2;
//front
face4 = new Mesh (faceGeometry, face4Mat);
face4.scaleX = width;
face4.scaleZ = height;
face4.rotationX = 270
face4.z = -depth / 2;
//right
face5 = new Mesh (faceGeometry, face5mat);
face5.scaleX = depth;
face5.scaleZ = height;
face5.rotationX = -90
face5.rotationY = -90
face5.x = width / 2;
//left
face6 = new Mesh (faceGeometry, face6Mat);
face6.scaleX = depth;
face6.scaleZ = height;
face6.rotationX = -90
face6.rotationY = 90
face6.x = -width / 2;
planesContainer.addChild(face1);
planesContainer.addChild(face2);
planesContainer.addChild(face3);
planesContainer.addChild(face4);
planesContainer.addChild(face5);
planesContainer.addChild(face6);
}
//public override function get assetType() : String
//{
//return AssetType.OBJECTCONTAINER3D;
//}
}
}
(Obviously at this stage there’s loads of includes which most likely don’t need to be there, I’ll start pruning once it’s working…)
Also, this seems like something quite a few people have asked for, is it the kind of thing that if it was coded nicely could be added into away3d? If so, what are the guidelines for making something to be considered for that?