|
-
help: remove Plane from scene (papervision3d)
I am working with papervision3d to display photos from a gallery. With the code below, it is straight forward to load a single image at a time into the 3d renderer.
The problem is: When a new photo is loaded, it only partially loads atop the previous photo. I need some way to remove the previous photo/plane.
PHP Code:
public function load_image():void {
photo_loader = new Loader();
photo_loader.load(new URLRequest(gallery_list[photo_num]));
photo_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, image_loading);
photo_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, image_loaded);
}
public function image_loaded(e:Event):void {
mat = new BitmapFileMaterial(gallery_list[photo_num]);
plane = new Plane(mat, 600, 450, 4, 4);
scene.addChild(plane);
camera.zoom = 100;
renderer.renderScene(scene, camera, viewport);
}
public function image_loading(e:ProgressEvent):void {}
I've tried
PHP Code:
scene.removeChild(plane);
Thanks,
-
The scene.removeChild(plane); should work if it is placed in the correct spot. How does the rest of your code look?
-
I've tried putting removeChild in various places. It seems to remove the Plane for good, so that I can't see any image at all.
PHP Code:
package Gallery{
import flash.display.*;
import flash.events.*;
import flash.xml.*;
import flash.text.*;
import flash.net.*;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.BitmapColorMaterial;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.scenes.*;
public class Gallery extends MovieClip {
private var _stage:Stage;
private var xml_loader:URLLoader;
private var photo_loader:Loader;
private var photo_num:Number = 0;
private var width_list:XMLList;
private var gallery_xml:XML;
private var gallery_list:XMLList;
private var viewport:Viewport3D = new Viewport3D(1000, 600, true, true);
private var renderer:BasicRenderEngine = new BasicRenderEngine();
private var scene:Scene3D = new Scene3D();
private var camera:Camera3D = new Camera3D();
private var mat:BitmapFileMaterial;
private var plane:Plane;
public function Gallery(mc:MovieClip, stage:Stage):void
{
_stage = stage;
load_xml(null);
_stage.addEventListener(MouseEvent.CLICK, inc_photo);
_stage.addEventListener(Event.ENTER_FRAME, OnEnterFrame);
_stage.addChild(viewport);
}
//**********LOAD XML
public function load_xml(e:Event):void
{
xml_loader = new URLLoader();
xml_loader.addEventListener(Event.COMPLETE, load_gallery);
xml_loader.load(new URLRequest("Gallery/gallery.xml"));
}
//**********PARSE XML
public function load_gallery(xml_event:Event):void {
gallery_xml = new XML(xml_event.target.data);
gallery_list = gallery_xml.section.(@name == section).photo.attribute("url");
width_list = gallery_xml.section.(@name == section).photo.attribute("width");
load_image();
}
//**********LOAD IMAGE
public function load_image():void {
photo_loader = new Loader();
photo_loader.load(new URLRequest(gallery_list[photo_num]));
photo_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, image_loading);
photo_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, image_loaded);
}
//**********SETUP PLANE & RENDER
public function image_loaded(e:Event):void {
mat = new BitmapFileMaterial(gallery_list[photo_num]);
mat.smooth = true;
mat.interactive = true;
plane = new Plane(mat, width_list[photo_num], 450, 4, 4);
scene.addChild(plane);
camera.zoom = 100;
renderer.renderScene(scene, camera, viewport);
}
//**********WHILE LOADING....
public function image_loading(e:ProgressEvent):void {}
//**********FRAME HEAD
public function OnEnterFrame(stage_event:Event):void {}
//**********INCREMENT PHOTO (PREV/NEXT)
public function inc_photo(click_event:MouseEvent):void
{
if(mouseX > _stage.stageWidth/2){photo_num += 1;}
if(mouseX < _stage.stageWidth/2){photo_num -= 1;}
if(photo_num <= 0 || photo_num >= gallery_list.length()){photo_num = 0;} //reset to 0
load_image();
}
}
}
-
um... ok I may not be able to help after all. Sorry. The only other thing I can think of is you may need to add some code that puts the gallery images in to a sprite or movieClip that then gets added to the plane. That way you can remove the image holder, while still keeping your plane intact. Not sure it this would work. Good luck : )
-
 Originally Posted by word2yerMom
um... ok I may not be able to help after all. Sorry. The only other thing I can think of is you may need to add some code that puts the gallery images in to a sprite or movieClip that then gets added to the plane. That way you can remove the image holder, while still keeping your plane intact. Not sure it this would work. Good luck : )
This is actually what I had originally done. It worked fine once the image was loaded, but during the load (progressEvent) weird things happened with the images. I wasn't able to get the loading sequence I wanted.
I thought that adding the image directly to a bitmapMaterial would make things easier, but I've had no luck. Thanks for your thoughts!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|