Poskusin
08-10-2009, 09:33 PM
Hey guys.
I'm not sure if this is directly hardware related or not. I've just started playing around with papervision 3d and I threw together this map floor and test sprite to see how it would look. The problem is, whenever I have a large portion or the map in my viewport, IT LAGS LIKE CRAZY. I was just wondering if maybe:
a) my code is horrid
b) my computer is a piece
c) papervision3d is just bad for 3d
I mean the concept is simple, there's nothing fancy going on and I'm only using planes. Maybe it's because I'm using 25x25 of them? I'm new to 3d so any help would be awesome. Is there a better path to use 3D than paper3d? Anyways, here's the code. Thanks guys.
//import files
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.VirtualM ouse;
var press_left:Boolean = false;
var press_right:Boolean = false;
var press_up:Boolean = false;
var press_down:Boolean = false;
var press_space:Boolean = false;
var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
addChild(viewport);
var renderer:BasicRenderEngine = new BasicRenderEngine();
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
//Set up initial view
//camera.zoom = 1;
//camera.focus = 100;
camera.x = 384;
camera.y = 120;
camera.z = 10;
camera.rotationX = 10;
//Textures
var mm:MovieMaterial = new MovieMaterial(tile1);
mm.smooth = true;
mm.animated = false;
var mm2:MovieMaterial = new MovieMaterial(sprite1, true);
mm2.smooth = true;
mm2.animated = true;
//Map floor
for (var i:uint = 0; i < 25; i++){
for (var j:uint = 0; j < 25; j++){
var p:Plane = new Plane(mm, 32, 32, 2, 2);
p.rotationX = 90;
p.x = j * 32;
p.z = i * 32;
scene.addChild(p);
}
}
//Test sprite
p = new Plane(mm2, 32, 32, 2, 2);
p.y = 32;
p.x = 304;
p.z = 304;
scene.addChild(p);
addEventListener(Event.ENTER_FRAME, gameLoop);
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);
stage.addEventListener(KeyboardEvent.KEY_UP, key_up);
function gameLoop(e:Event):void
{
// keyboard stuff
if (press_left){camera.x -= 10;}
if (press_right){camera.x += 10;}
if (press_up){camera.z += 10;}
if (press_down){camera.z -= 10;}
renderer.renderScene(scene, camera, viewport);
}
//Key Down and Up
function key_down(event:KeyboardEvent):void
{
if (event.keyCode == 32){press_space = true;}
if (event.keyCode == 37){press_left = true;}
if (event.keyCode == 38){press_up = true;}
if (event.keyCode == 39){press_right = true;}
if (event.keyCode == 40){press_down = true;}
}
function key_up(event:KeyboardEvent):void
{
if (event.keyCode == 32){press_space = false;}
if (event.keyCode == 37){press_left = false;}
if (event.keyCode == 38){press_up = false;}
if (event.keyCode == 39){press_right = false;}
if (event.keyCode == 40){press_down = false;}
}
I'm not sure if this is directly hardware related or not. I've just started playing around with papervision 3d and I threw together this map floor and test sprite to see how it would look. The problem is, whenever I have a large portion or the map in my viewport, IT LAGS LIKE CRAZY. I was just wondering if maybe:
a) my code is horrid
b) my computer is a piece
c) papervision3d is just bad for 3d
I mean the concept is simple, there's nothing fancy going on and I'm only using planes. Maybe it's because I'm using 25x25 of them? I'm new to 3d so any help would be awesome. Is there a better path to use 3D than paper3d? Anyways, here's the code. Thanks guys.
//import files
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.VirtualM ouse;
var press_left:Boolean = false;
var press_right:Boolean = false;
var press_up:Boolean = false;
var press_down:Boolean = false;
var press_space:Boolean = false;
var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
addChild(viewport);
var renderer:BasicRenderEngine = new BasicRenderEngine();
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
//Set up initial view
//camera.zoom = 1;
//camera.focus = 100;
camera.x = 384;
camera.y = 120;
camera.z = 10;
camera.rotationX = 10;
//Textures
var mm:MovieMaterial = new MovieMaterial(tile1);
mm.smooth = true;
mm.animated = false;
var mm2:MovieMaterial = new MovieMaterial(sprite1, true);
mm2.smooth = true;
mm2.animated = true;
//Map floor
for (var i:uint = 0; i < 25; i++){
for (var j:uint = 0; j < 25; j++){
var p:Plane = new Plane(mm, 32, 32, 2, 2);
p.rotationX = 90;
p.x = j * 32;
p.z = i * 32;
scene.addChild(p);
}
}
//Test sprite
p = new Plane(mm2, 32, 32, 2, 2);
p.y = 32;
p.x = 304;
p.z = 304;
scene.addChild(p);
addEventListener(Event.ENTER_FRAME, gameLoop);
stage.addEventListener(KeyboardEvent.KEY_DOWN, key_down);
stage.addEventListener(KeyboardEvent.KEY_UP, key_up);
function gameLoop(e:Event):void
{
// keyboard stuff
if (press_left){camera.x -= 10;}
if (press_right){camera.x += 10;}
if (press_up){camera.z += 10;}
if (press_down){camera.z -= 10;}
renderer.renderScene(scene, camera, viewport);
}
//Key Down and Up
function key_down(event:KeyboardEvent):void
{
if (event.keyCode == 32){press_space = true;}
if (event.keyCode == 37){press_left = true;}
if (event.keyCode == 38){press_up = true;}
if (event.keyCode == 39){press_right = true;}
if (event.keyCode == 40){press_down = true;}
}
function key_up(event:KeyboardEvent):void
{
if (event.keyCode == 32){press_space = false;}
if (event.keyCode == 37){press_left = false;}
if (event.keyCode == 38){press_up = false;}
if (event.keyCode == 39){press_right = false;}
if (event.keyCode == 40){press_down = false;}
}