Sure ;) Please notice, that this is just some testcode, so it's not nice to
read ;P
I've deleted some hundred lines of code, the complete main class can be
found here:
http://die-beiden.com/_temp/broomstick/Away3dtest.as
The main view is called "_view", the second view is "_egoView"...
Many thanks for your help!
public function Away3dtest()
{
addEventListener(Event.ADDED_TO_STAGE, doStart);
}
private function doStart(e:Event):void
{
initViewport();
}
private function initViewport():void
{
_scene = new Scene3D();
_egoView = new View3D(_scene);
_egoView.width = 200;
_egoView.height = 200;
_egoView.x = 0;
_egoView.y = stage.stageHeight - 200;
_view = new View3D(_scene);
_view.camera = new RTSCamera3D();
addChild(_view);
addChild(_egoView);
_view.x = 0;
_view.y = 0;
world = new ObjectContainer3D();
_view.backgroundColor = 0x0000;
_egoView.backgroundColor = 0x000000;
_scene.addChild(world);
_egoView.scene = _scene;
_view.scene = _scene;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
private function doSomething(e:Event):void
{
_light = new PointLight();
_light.color = 0xffffff;
_light.fallOff = 1000;
world.addChild(_light);
world.addChild(SunLight.light);
_light.radius = 1000;
_light.specular = 0.1;
_light.diffuse = 1000;
_view.camera.z = -2000;
_view.camera.x = 200;
_view.camera.y = 2000;
_view.camera.lens.far = 6650;
_view.camera.lens.near = 400;
_egoView.camera.position = _view.camera.position;
_egoView.camera.lens.far = 6650;
_egoView.camera.lens.near = 400;
_egoView.camera.lookAt(new Vector3D(0, -600, 0));
ResourceManager.instance.addEventListener(ResourceEvent.RESOURCE_RETRIEVED,
onThingsLoaded);
myobj = new ObjectContainer3D();
myobj =
ObjectContainer3D(ResourceManager.instance.getResource("maptest.obj"));
mycube = new ObjectContainer3D();
mycube =
ObjectContainer3D(ResourceManager.instance.getResource("cubesphere.obj"));
mybase = new ObjectContainer3D();
mybase =
ObjectContainer3D(ResourceManager.instance.getResource("base.obj"));
mytank = new ObjectContainer3D();
mytank =
ObjectContainer3D(ResourceManager.instance.getResource("tank.obj"));
mobileUnits = new Vector.<MobileUnit>();
mobileUnits.push(new MobileUnitTank(_view));
mobileUnits.push(new MobileUnitTank(_view));
addChild(mobileUnits[0]);
addChild(mobileUnits[1]);
world.addChild(mycube);
world.addChild(myobj);
world.addChild(mybase);
world.addChild(mobileUnits[0].container);
world.addChild(mobileUnits[1].container);
mobileUnits[0].setObjOnTile(new Point(26, 31));
mobileUnits[1].setObjOnTile(new Point(37, 31));
planeMaterial = new ColorMaterial(0x5555AA );
planeMaterial.lights = [SunLight.light, _light];
planeMaterial.bothSides = false;
planeMaterial.specular = 0.2;
planeMaterial.shadowMethod = new
SoftShadowMapMethod(SunLight.light, 0.001);
fog = new FogMethod(6640, 0x000);
fog.linearFallOff = false;
planeMaterial.addMethod(fog);
//..deleted adding some more materials...
_egoView.mouseEnabled = false;
}
private function onThingsLoaded(e:ResourceEvent):void
{
var mesh : Mesh;
for (var i : int = 0; i <
ObjectContainer3D(e.resource).numChildren; ++i) {
mesh = Mesh(ObjectContainer3D(e.resource).getChildAt(i));
if (e.uri == "maptest.obj")
{
mesh.geometry.scale(8);
mesh.material = matTerrain;
Mesh(myobj.getChildAt(0)).mouseEnabled = true;
Mesh(myobj.getChildAt(0)).mouseDetails = true;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
} else if(e.uri == "cubesphere.obj")
{
mesh.geometry.scale(0.4);
Mesh(ObjectContainer3D(e.resource).getChildAt(1)).material = glowMaterial;
}
else if(e.uri == "tank.obj")
{
mesh.geometry.scale(0.89);
mesh.mouseEnabled = true;
Mesh(ObjectContainer3D(e.resource).getChildAt(i)).material = tankMaterial;
}
else if(e.uri == "base.obj")
{
mesh.geometry.scale(0.75);
Mesh(ObjectContainer3D(e.resource).getChildAt(i)).material = hullMaterial;
}
}
if (e.uri == "maptest.obj")
{
mesh.addEventListener(MouseEvent3D.CLICK, onClickOnGround);
}
if (e.uri == "tank.obj")
{
initTanks(ObjectContainer3D(e.resource));
}
}
private function onClickOnGround(e:MouseEvent3D):void
{
// main part - getting the uvs
var tx:uint = Math.floor(e.uv.x * 64);
var ty:uint = Math.floor(e.uv.y * 64);
text_debug.text = "tileX: " + tx + " | uv.x: "+e.uv.x;
text_debug.appendText("\ntileY: " + ty + " | uv.y: " + e.uv.y);
//now highlight the tile
var tpoint:Point = new Point(tx, ty);
var tvec:Vector.<Point> = new Vector.<Point>();
tvec[0] = tpoint;
MovieClip(materialTerrainLoader.content).setGreen(tvec);
matTerrain.bitmapData =
MovieClip(materialTerrainLoader.content).getBitmapData();
matTerrain.updateTexture();
}
private function onEnterFrame(e:Event):void {
mycube.rotationX++;
sunLight.update();
//some more light and obj-calculations...
RTSCamera3D(_view.camera).doUpdate();
_egoView.camera.position = _view.camera.position;
_egoView.camera.lookAt(mycube.position);
_egoView.camera.rotationY = mycube.rotationY;
_egoView.render();
_view.render();
}