KMZ
KMZ, or Keyhole Markup Zipped, is a parsed Google Earth file.
KMZ material names, and child names, are located in a .dae file within the .kmz file. The .dae file can be found by renaming the .kmz file extension to a .zip file extension and then opening the .zip file and models folder.
Note: This tutorial is currently working through revision 910 ONLY.
Example
Instructions
- Import
import org.papervision3d.objects.parsers.KMZ;
- Declare
private var object :KMZ;
- Initialize
object = new KMZ(name);
Parameter Default Description name null name - Scale
object.scale = number;
- Load
object.load(asset, materials);
Parameter Default Description asset NONE Google Earth file materials null material list properties - Add
scene.addChild(object);
Code
package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.cameras.Camera3D; import org.papervision3d.events.FileLoadEvent; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.special.CompositeMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.parsers.KMZ; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; public class Papervision3DKMZ extends Sprite { private var scene :Scene3D; private var camera :Camera3D; private var viewport :Viewport3D; private var renderer :BasicRenderEngine; private var material :CompositeMaterial; private var materials :MaterialsList; private var object :KMZ; public function Papervision3DKMZ() { scene = new Scene3D(); camera = new Camera3D(); viewport = new Viewport3D(); viewport.autoScaleToStage = true; viewport.interactive = true; addChild(viewport); renderer = new BasicRenderEngine(); material = new CompositeMaterial(); material.doubleSided = true; material.interactive = true; material.addMaterial(new ColorMaterial(0x000000, 0.5)); material.addMaterial(new WireframeMaterial(0x000000)); materials = new MaterialsList(); materials.addMaterial(material, "material_0_0"); object = new KMZ(); object.scale = 0.85; object.load("Cube.kmz", materials); scene.addChild(object); object.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete); } private function handleLoadComplete(e:FileLoadEvent):void { object.removeEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete); var child :DisplayObject3D = object.getChildByName("mesh1", true); child.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver); child.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut); child.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPress); addEventListener(Event.ENTER_FRAME, handleEnterFrame); } private function handleEnterFrame(e:Event):void { object.yaw(1); renderer.renderScene(scene, camera, viewport); } private function handleObjectOver(e:InteractiveScene3DEvent):void { viewport.containerSprite.buttonMode = true; } private function handleObjectOut(e:InteractiveScene3DEvent):void { viewport.containerSprite.buttonMode = false; } private function handleObjectPress(e:InteractiveScene3DEvent):void { var color :uint = Math.random() * 0xFFFFFF; material.removeAllMaterials(); material.addMaterial(new ColorMaterial(color, 0.5)); material.addMaterial(new WireframeMaterial(color)); object.replaceMaterialByName(material, "material_0_0"); } } }