PDA

View Full Version : [AS3][Away3D] Splitting my map off to a seperate .as



maltech
July 17th, 2009, 08:34 PM
Hello I have been trying to split my map off to a seperate .as file. I have several reasons for doing it, but the problem is I can not get the images to load.

this is my Map1.as (after the imports are done)


public class Map1 extends Object3D
{
//load skins for planets
[embed(source="sunmap.jpg")]
private var sunskin:BitmapFileMaterial;
[embed(source="mars_1k_color.jpg")]
private var marsskin:BitmapFileMaterial;
[embed(source="venusmap.jpg")]
private var venusskin:BitmapFileMaterial;
[embed(source="earthmap1k.jpg")]
private var earthskin:BitmapFileMaterial;
[embed(source="mercurymap.jpg")]
private var mercuryskin:BitmapFileMaterial;
[embed(source="jupitermap.jpg")]
private var jupiterskin:BitmapFileMaterial;
[embed(source="saturnmap.jpg")]
private var saturnskin:BitmapFileMaterial;
[embed(source="uranusmap.jpg")]
private var uranusskin:BitmapFileMaterial;
[embed(source="neptunemap.jpg")]
private var neptuneskin:BitmapFileMaterial;
[embed(source="plutomap1k.jpg")]
private var plutoskin:BitmapFileMaterial;

//load moon texture
[embed(source="moonmap1k.jpg")]
private var moonskin:BitmapFileMaterial;

private var sun:Sphere;
private var mercury:Sphere;
private var venus:Sphere;
private var earth:Sphere;
private var mars:Sphere;
private var jupiter:Sphere;
private var saturn:Sphere;
private var uranus:Sphere;
private var neptune:Sphere;
private var mapview:View3D;


public function Map1()
{
mapview = new View3D();

sunskin = new BitmapFileMaterial("sunmap.jpg");
sun = new Sphere({material:sunskin, radius:2000, segmentsH:16, segmentsW:16});
sun.bothsides = true;

mercuryskin = new BitmapFileMaterial("mercurymap.jpg");
mercury = new Sphere({material:mercuryskin, radius:240, segmentsH:16, segmentsW:16, z:5800});

venusskin = new BitmapFileMaterial("venusmap.jpg");
venus = new Sphere({material:venusskin, radius:600, segmentsH:16, segmentsW:16, z:18000});
//make star skybox
// create a temporary container-sprite to add stars into
var mc:Sprite = new Sprite();
mc.graphics.beginFill(0);
mc.graphics.drawRect(0,0,2048,2048);
mc.graphics.endFill();
// add 2000 star-sprites to the container
var s:Sprite, r:Number;
for( var i:uint=0; i<2000; i++ )
{
r = Math.random()*Math.random();
s = new Sprite();
s.graphics.beginFill(0xFFFFFF,0.9);
s.graphics.drawCircle(0,0,r);
s.graphics.endFill();
s.x = r + (mc.width - 2*r)*Math.random();
s.y = r + (mc.height - 2*r)*Math.random();
mc.addChild(s);
}

// render the container-sprite to a bitmap
var bmd:BitmapData = new BitmapData(mc.width, mc.height, false, 0);
bmd.draw(mc);
// create a 2x2 tiled material from the bitmap
var mat:TransformBitmapMaterial = new TransformBitmapMaterial(bmd, {
smooth: true, precision:0,
repeat: true, scaleX: 0.5, scaleY: 0.5 });
// create a skybox using that material on all 6 sides
var box:Skybox = new Skybox( mat,mat,mat,mat,mat,mat );
}
}
}


and this is the Game.as (the one that runs the game)


public class Game extends Sprite
{
private var map:Map1;
private var view:View3D;
private var cam:Camera3D;

public function Game()
{
view = new View3D();
cam = new Camera3D();
addChild(view);
view.camera = cam;
cam.z = 10000;

map = new Map1();
view.scene.addChild(map);
view.render();
}
}
}what am I missing here?

I need to remove the embed lines, the format I am using now does not require them. I use away3d for my engine and BitmapFileMaterial imports directly from the url and requires no embed. So please do not tell me I am using embed wrong by not having a variable:Class. I know that part of the code is good I have tested it in a single file and it works.

TOdorus
July 18th, 2009, 12:04 AM
Hi Maltech, I see you've found these forums as well. Before anyone tries to wade through that big chunk of code, try formatting it with code tags. When making a post there shoulde be a # symbol in your menu. Please edit your post so that it is at least readable.



//Example
function example():void{
trace("example")
}

maltech
July 18th, 2009, 12:49 AM
sorry bout that, I did not see the go advanced button at the bottom that is why I did not code bracket I wasnt sure if it was accepted. I edited the post. I have this post on like 10 forums and noone seems to know the answer because I am getting no replies lol.

TOdorus
July 18th, 2009, 01:30 AM
I need to remove the embed lines, the format I am using now does not require them. I use away3d for my engine and BitmapFileMaterial imports directly from the url and requires no embed. So please do not tell me I am using embed wrong by not having a variable:Class. I know that part of the code is good I have tested it in a single file and it works.

You're getting defensive before anyone has said anything :)

But after reading that, what do you mean by loading? Loading into the swf, or loading it into the Away3D engine? If the latter is the case I had to look up the bitmapFileMaterial class (http://away3d.com/livedocs/away3d/materials/BitmapFileMaterial.html#propertySummary) on google. The only thing I can come up with is to ask you if you checked if the bitmapdata within the bitmapFileMaterial is loaded properly (copypixel bitmapFileMaterial.bitmap to a bitmap onscreen).

maltech
July 18th, 2009, 01:46 AM
You're getting defensive before anyone has said anything :)

But after reading that, what do you mean by loading? Loading into the swf, or loading it into the Away3D engine? If the latter is the case I had to look up the bitmapFileMaterial class (http://away3d.com/livedocs/away3d/materials/BitmapFileMaterial.html#propertySummary) on google. The only thing I can come up with is to ask you if you checked if the bitmapdata within the bitmapFileMaterial is loaded properly (copypixel bitmapFileMaterial.bitmap to a bitmap onscreen).

It works in this example

public class World extends Sprite {
private var moonskin:BitmapFileMaterial;
private var earthskin:BitmapFileMaterial;
private var cam:Camera3D;
private var lastKey:uint;
private var keyIsDown:Boolean = false;
private var view:View3D;
private var fighter:spaceship;
private var materialClass:Class;
private var materialMaterial:BitmapMaterial;
private var planet:Sphere;
private var ltarget:Sphere;
private var key:KeyObject;
private var light:DirectionalLight3D;
private var sky:Sphere;
private var moon:Sphere;

public function World()
{
// create a basic camera
cam = new Camera3D();
view = new View3D({x:250,y:200, renderer:Renderer.BASIC});
addChild(view);
view.camera = cam;

earthskin = new BitmapFileMaterial("http://branchdepartment.net/test/earthmap1k.jpg");
planet = new Sphere({material:earthskin, z:10000, radius:1000, segmentsH:12, segmentsW:18});
view.scene.addChild(planet);
moonskin = new BitmapFileMaterial("http://branchdepartment.net/test/moonmap1k.jpg");
moon = new Sphere({material:moonskin, z:10000, x:2250, radius:200, segmentsH:12, segmentsW:18});
view.scene.addChild(moon);
fighter = new spaceship();
view.scene.addChild(fighter);
light = new DirectionalLight3D();
light.specular = 1;
light.diffuse = 0.5;
light.ambient = 0.5;
view.scene.addChild(light);
ltarget = new Sphere({radius:2.5, material:"black#red"});
view.scene.addChild(ltarget);
key = new KeyObject(this.stage);
view.render();
// create a temporary container-sprite to add stars into
var mc:Sprite = new Sprite();
mc.graphics.beginFill(0);
mc.graphics.drawRect(0,0,2048,2048);
mc.graphics.endFill();
// add 2000 star-sprites to the container
var s:Sprite, r:Number;
for( var i:uint=0; i<2000; i++ )
{
r = Math.random()*Math.random();
s = new Sprite();
s.graphics.beginFill(0xFFFFFF,0.9);
s.graphics.drawCircle(0,0,r);
s.graphics.endFill();
s.x = r + (mc.width - 2*r)*Math.random();
s.y = r + (mc.height - 2*r)*Math.random();
mc.addChild(s);
}

// render the container-sprite to a bitmap
var bmd:BitmapData = new BitmapData(mc.width, mc.height, false, 0);
bmd.draw(mc);
// create a 2x2 tiled material from the bitmap
var mat:TransformBitmapMaterial = new TransformBitmapMaterial(bmd, {
smooth: true, precision:0,
repeat: true, scaleX: 0.5, scaleY: 0.5 });
// create a skybox using that material on all 6 sides
var box:Skybox = new Skybox( mat,mat,mat,mat,mat,mat );
// and finally add it to the scene
view.scene.addChild(box);

/*if(keyIsDown){

if(lastKey===87){fighter.moveForward(10);}
if(lastKey===83){fighter.moveBackward(5);}
if(lastKey===65){fighter.roll(2);}
if(lastKey===68){fighter.roll(-2);}
if(lastKey===Keyboard.UP){fighter.pitch(2);}
if(lastKey===Keyboard.DOWN){fighter.pitch(-2);}
if(lastKey===Keyboard.RIGHT){fighter.yaw(2);}
if(lastKey===Keyboard.LEFT){fighter.yaw(-2);}
}*/

this.stage.addEventListener(Event.ENTER_FRAME,onEn terFrame);
}
private function onEnterFrame(e:Event):void
{

if(key.isDown(87)){fighter.moveForward(20);}
if(key.isDown(83)){fighter.moveBackward(10);}
if(key.isDown(65)){fighter.roll(5);}
if(key.isDown(68)){fighter.roll(-5);}
if(key.isDown(key.UP)){fighter.pitch(.5);}
if(key.isDown(key.DOWN)){fighter.pitch(-.5);}
if(key.isDown(key.RIGHT)){fighter.yaw(.5);}
if(key.isDown(key.LEFT)){fighter.yaw(-.5);}


ltarget.transform = fighter.transform;
ltarget.moveForward(1000);
ltarget.moveDown(100);
view.camera.transform = fighter.transform;
view.camera.pitch(10);
view.camera.moveForward(28);
view.camera.moveUp(5);
view.render();
}
}
So I know that is not the issue.

The point is I am trying to split the objects that will be the map off and I cant get them to load, I get no errors but nothing shows on screen either. I did not want to discuss the embeding of the image because I know it is not the issue.

I clearly said in the origional post that that part of the code is good, so the issue needs to be researched on another aspect. If you have never done something like this you probably do not know the answer. The thread topic clearly states Away3D if you do not use that engine you will not understand the classes available in it so you will not be able to help me. To those people that fit those categories, please do not bother.

TOdorus
July 18th, 2009, 08:13 AM
Well you're going to hate me for saying all this then. Taking a stance like that is going to scare people of at an instant. You're basicly saying there are dumb answers, so people are going to be reluctant to help if there's a pretty big probability you will tag their answer as dumb (indirectly calling them dumb). Since you post on ten forums without getting an answer and not look at the way you ask questions is a bit easy.

Secondly you give one wad of code with a proces containing a lot of steps and saying, the result of the final step isn't what I want. I advised to break it down and check to see where your code starts to fail. The users of forums can't do the bughunting for you, so you have to give them the point of failure. Now the only thing you know is that it did work in that example and that it doesn't work here. That's not a whole lot knowledge to work with. The logical conclusion I can get of that is that it's not the same as in the example so all assumptions as to what it is are off. That is until you check and know. I've had countless of weird interactions to learn that the hard way.

Thridly Away3D isn't used that much as PaperVision, so people who know a 3D API are probably going to know PaperVision. I may not know Away3D, but I (and many others) do know about bitmapData and using custom classes for rendering. If you wish to dismiss that knowledge as irrelevant to your problem, then good luck to you sir.

SparK_BR
July 22nd, 2009, 10:40 AM
for each object that you are using in your class you should do
this.addChild(sun); for example, then your main class will render your object which has childs now and not only vars...