Where to put removeChild (Away3d 4.x)
hey guys need on how change primitives , removing previous primitive showing in scene , changing materials on primitive click of button.
mainly put removechild.
this away3d
package
{
import away3d.cameras.*;
import away3d.containers.*;
import away3d.controllers.*;
import away3d.core.base.subgeometry;
import away3d.core.base.data.vertex;
import away3d.debug.*;
import away3d.entities.mesh;
import away3d.extrusions.*;
import away3d.filters.*;
import away3d.lights.*;
import away3d.materials.*;
import away3d.materials.lightpickers.*;
import away3d.materials.methods.*;
import away3d.primitives.*;
import away3d.textures.*;
import away3dplus.controllers.simplehovercontroller;
import flash.display.bitmap;
import flash.display.bitmapdata;
import flash.display.sprite;
import flash.display.stagealign;
import flash.display.stagescalemode;
import flash.events.event;
import flash.events.mouseevent;
import flash.geom.vector3d;
import flash.text.textfield;
import flash.text.textfieldautosize;
import flash.text.textformat;
[swf(backgroundcolor="#000000",framerate="30",quality="low")]
public class main extends sprite
{
//engine variables
private var view:view3d;
private var scene:scene3d;
// debug
private var awaystats:awaystats;
//light objects
private var pointlight:pointlight;
private var lightpicker:staticlightpicker;
//material objects
private var redcolormaterial:colormaterial;
private var skyboxcubetexture:bitmapcubetexture;
//buttons
private var btncube:sprite = new sprite
private var btnsphere:sprite = new sprite
private var btncylinder:sprite = new sprite
private var btntorus:sprite = new sprite
private var btnmaterial:sprite = new sprite
private var btnwireframe:sprite = new sprite
public function main() {
init();
}
private function init():void {
initengine();
initlights();
initcamera();
initmaterials();
initobjects();
initlisteners();
drawbutton()
btncube.addeventlistener(mouseevent.click, changecube);
btncube.x = 400;
btncube.y = 25;
addchild(btncube);
btnsphere.addeventlistener(mouseevent.click, changesphere);
btnsphere.x = 400;
btnsphere.y = 60;
addchild(btnsphere);
btncylinder.addeventlistener(mouseevent.click, changecylinder);
btncylinder.x = 400;
btncylinder.y = 95;
addchild(btncylinder);
btntorus.addeventlistener(mouseevent.click, changetorus);
btntorus.x = 400;
btntorus.y = 130;
addchild(btntorus);
//btnmaterial.addeventlistener(mouseevent.click, changematerial);
btnmaterial.x = 15;
btnmaterial.y = 95;
addchild(btnmaterial);
btnwireframe.addeventlistener(mouseevent.click, changewireframe);
btnwireframe.x = 15;
btnwireframe.y = 130;
addchild(btnwireframe);
}
/**
* initialise engine
*/
private function initengine():void {
//stage setup
stage.scalemode = stagescalemode.no_scale;
stage.align = stagealign.top_left;
// 3d view - window 3d scene
view = new view3d();
addchild(view);
// 3d scene.
scene = view.scene;
// stats
awaystats = new awaystats(view);
addchild(awaystats);
}
/**
* initialise lights
*/
private function initlights():void {
//point light
pointlight = new pointlight();
scene.addchild(pointlight);
lightpicker = new staticlightpicker([pointlight]);
}
private function initcamera():void {
var hovercameramanager:simplehovercontroller = new simplehovercontroller(view, 700, [pointlight]);
}
/**
* initialise buttons
*/
private function drawbutton():void {
var textlabel:textfield = new textfield()
btncube.graphics.clear();
btncube.graphics.beginfill(0xffffff); // white
btncube.graphics.drawroundrect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipsew, ellipseh
textlabel.text = "cube";
textlabel.x = 22;
textlabel.y = 4;
textlabel.selectable = false;
btncube.addchild(textlabel)
var textlabel01:textfield = new textfield()
btnsphere.graphics.clear();
btnsphere.graphics.beginfill(0xffffff); // white
btnsphere.graphics.drawroundrect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipsew, ellipseh
textlabel01.text = "sphere";
textlabel01.x = 18;
textlabel01.y = 3;
textlabel01.selectable = false;
btnsphere.addchild(textlabel01)
var textlabel03:textfield = new textfield()
btncylinder.graphics.clear();
btncylinder.graphics.beginfill(0xffffff); // white
btncylinder.graphics.drawroundrect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipsew, ellipseh
textlabel03.text = "cylinder";
textlabel03.x = 10;
textlabel03.y = 3;
textlabel03.selectable = false;
btncylinder.addchild(textlabel03)
var textlabel04:textfield = new textfield()
btntorus.graphics.clear();
btntorus.graphics.beginfill(0xffffff); // white
btntorus.graphics.drawroundrect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipsew, ellipseh
textlabel04.text = "torus";
textlabel04.x = 17;
textlabel04.y = 3;
textlabel04.selectable = false;
btntorus.addchild(textlabel04)
var textlabel05:textfield = new textfield()
btnmaterial.graphics.clear();
btnmaterial.graphics.beginfill(0xffffff); // white
btnmaterial.graphics.drawroundrect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipsew, ellipseh
textlabel05.text = "material";
textlabel05.x = 6;
textlabel05.y = 3;
textlabel05.selectable = false;
btnmaterial.addchild(textlabel05)
var textlabel06:textfield = new textfield()
btnwireframe.graphics.clear();
btnwireframe.graphics.beginfill(0xffffff); // white
btnwireframe.graphics.drawroundrect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipsew, ellipseh
textlabel06.text = "wireframe";
textlabel06.x = 2;
textlabel06.y = 3;
textlabel06.selectable = false;
btnwireframe.addchild(textlabel06)
}
/**
* initialise materials
*/
private function initmaterials():void {
// red color
redcolormaterial = new colormaterial(0xff0000, 0.8);
redcolormaterial.lightpicker = lightpicker;
//
skyboxcubetexture = new bitmapcubetexture(new envposx().bitmapdata, new envnegx().bitmapdata, new envposy().bitmapdata, new envnegy().bitmapdata, new envposz().bitmapdata, new envnegz().bitmapdata);
}
/**
* initialise scene objects
*/
private function initobjects():void {
var trident:trident = new trident(100);
trident.x = 0;
trident.y = 0;
scene.addchild(trident);
//geometry - geometry collection of subgeometries, each of contain actual geometrical data such vertices, normals, uvs, etc.
{
////primitivebase - primitivebase abstract base class mesh primitives, prebuilt simple meshes.
{
//cubegeometry cube primitive mesh.
var newcubegeometry:cubegeometry = new cubegeometry(200, 200, 200, 50, 50, 50, true);
//spheregeometry - uv sphere primitive mesh.
var newspheregeometry:spheregeometry = new spheregeometry(50, 16, 12, true);
//capsulegeometry uv capsule primitive mesh.
var newcapsulegeometry:capsulegeometry = new capsulegeometry(50, 100, 16, 12, true);
//conegeometry uv cone primitive mesh.
//var newconegeometry:conegeometry = new conegeometry(50, 100, 16, 1, true, true);
//cylindergeometry uv cylinder primitive mesh.
var newcylindergeometry:cylindergeometry = new cylindergeometry(50, 50, 100, 16, 1, true, true);
//planegeometry plane primitive mesh.
var newplanegeometry:planegeometry = new planegeometry(100, 100, 1, 1, true);
//regularpolygongeometry uv regularpolygon primitive mesh.
var newregularpoligongeometry:regularpolygongeometry = new regularpolygongeometry(100, 16, true);
//torusgeometry uv torus primitive mesh.
var newtorusgeomentry:torusgeometry = new torusgeometry(50, 50, 15, 8, true);
}
}
// entity - entity class provides abstract base class scene graph objects considered having "presence" in scene,
// in sense can considered actual object position , size (even if infinite or idealised), rather grouping.
{
//mesh - mesh agregates instance of geometry, augmenting presence in scene graph, material, , animations tate.
// consists out of submeshes, in turn correspond subgeometries. submeshes allow different parts of geometry assigned different materials.
//var cube:mesh = new mesh(newcubegeometry, redcolormaterial);
//cube.x = 100;
//cube.y = 100;
//cube.z = 100;
//scene.addchild(cube);
//var sphere:mesh = new mesh(newspheregeometry, redcolormaterial);
//sphere.x = -75;
//sphere.y = -150;
//scene.addchild(sphere);
//var capsule:mesh = new mesh(newcapsulegeometry, redcolormaterial);
//capsule.x = -200;
//capsule.y = -150
//scene.addchild(capsule);
//var cone:mesh = new mesh(newconegeometry, redcolormaterial);
//cone.x = -200;
//cone.y = 150;
//cone.showbounds = true;
//scene.addchild(cone);
//var cylinder:mesh = new mesh(newcylindergeometry, redcolormaterial);
//cylinder.x = -75;
//cylinder.y = 150;
//scene.addchild(cylinder);
//var plane:mesh = new mesh(newplanegeometry, redcolormaterial);
//plane.x = -75;
//plane.y = 275;
//scene.addchild(plane);
//var poligon:mesh = new mesh(newregularpoligongeometry, redcolormaterial);
//poligon.x = -275;
//poligon.y = 275;
//scene.addchild(poligon);
//var torus:mesh = new mesh(newtorusgeomentry, redcolormaterial);
//torus.x = -275;
//scene.addchild(torus);
//skybox skybox class used render sky in scene.
//var skybox:skybox = new skybox(skyboxcubetexture);
//scene.addchild(skybox);
// segmentset
{
//wireframeaxesgrid - class wireframeaxesgrid generates grid of lines on given planewireframeaxesgrid
//var wireframeaxesgrid:wireframeaxesgrid = new wireframeaxesgrid(4, 400, 1);
//scene.addchild(wireframeaxesgrid);
//wireframegrid class wireframegrid generates grid of lines on given planewireframegrid
//var wireframegrid:wireframegrid = new wireframegrid(10, 100, 5, 0x0000ff);
//wireframegrid.x = 75;
//wireframegrid.y = 275;
//scene.addchild(wireframegrid);
//wireframeprimitivebase
{
//wireframecube - class wireframegrid generates grid of lines on given planewireframegrid
//var wireframecube:wireframecube = new wireframecube(100, 100, 100, 0x0000ff, 5);
//wireframecube.x = 75;
//scene.addchild(wireframecube);
//wireframesphere - class wireframegrid generates grid of lines on given planewireframegrid
//var wireframesphere:wireframesphere = new wireframesphere(50, 16, 12, 0x0000ff, 5);
//wireframesphere.x = 75;
//wireframesphere.y = -150;
//scene.addchild(wireframesphere);
//wireframeplane
//var wireframeplane:wireframeplane = new wireframeplane(100, 100, 10, 10, 0x0000ff, 5);
//wireframeplane.x = 175;
//wireframeplane.y = 275;
//scene.addchild(wireframeplane);
}
}
}
}
/**
* initialise listeners
*/
private function initlisteners():void {
addeventlistener(event.enter_frame, onenterframe);
}
/**
* render loop
*/
private function onenterframe(event:event):void {
view.render();
}
/**
* intialise buttons events
*/
private function changecube(event:mouseevent):void {
var newcubegeometry:cubegeometry = new cubegeometry(200, 200, 200, 50, 50, 50, true);
var cube:mesh = new mesh(newcubegeometry, redcolormaterial);
cube.x = 100;
cube.y = 100;
cube.z = 100;
scene.addchild(cube);
}
private function changesphere(event:mouseevent):void {
var newspheregeometry:spheregeometry = new spheregeometry(50, 16, 12, true);
var sphere:mesh = new mesh(newspheregeometry, redcolormaterial);
scene.addchild(sphere);
}
private function changecylinder(event:mouseevent):void {
var newcylindergeometry:cylindergeometry = new cylindergeometry(50, 50, 100, 16, 1, true, true);
var cylinder:mesh = new mesh(newcylindergeometry, redcolormaterial);
scene.addchild(cylinder);
}
private function changetorus(event:mouseevent):void {
var newtorusgeomentry:torusgeometry = new torusgeometry(50, 50, 15, 8, true);
var torus:mesh = new mesh(newtorusgeomentry, redcolormaterial);
scene.addchild(torus);
}
private function changewireframe(event:mouseevent):void {
var wireframecube:wireframecube = new wireframecube(100, 100, 100, 0x0000ff, 5);
scene.addchild(wireframecube);
}
}
}
thanks, matthew
More discussions in Using Flash Builder
adobe
Comments
Post a Comment