(Flex 3d) papervision3d loading Dae example

Source: Internet
Author: User
Tags addchild

Because of project requirements, we need to display 3D building models in the browser. After a period of technical selection, we feel that flex is a mature technology that shows 3D models in browsers. Our workflow is to create a 3D model for the Dae file based on the actual object or scenario. Flex uses the papervision3d engine to load Dae model presentation and interaction.

3D model loading source code:

<? XML version = "1.0" encoding = "UTF-8"?> <View: basesimplecontainer xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx" xmlns: view = "com. shine. framework. core. view. * "creationcomplete =" {complete ()} "xmlns: view1 =" com. shine. framework. papervision3d. view. * "> <view: layout> <s: basiclayout/> </View: layout> <FX: SCRIPT> <! [CDATA [import MX. controls. alert; import MX. events. moveevent; import Org. papervision3d. cameras. camera3d; import Org. papervision3d. cameras. springcamera3d; import Org. papervision3d. events. fileloadevent; import Org. papervision3d. events. interactivescene3devent; import Org. papervision3d. lights. pointlight3d; import Org. papervision3d. objects. displayobject3d; import Org. papervision3d. objects. parsers. dae; import Org. papervision3d. objects. primitives. plane; import Org. papervision3d. render. basicrenderengine; import Org. papervision3d. scenes. scene3d; import Org. papervision3d. view. viewport3d; private var daefilepath: string; // 3D Window private var viewport: viewport3d; // 3D scene private var scene: scene3d; // 3D camera private var camera: camera3d; // locate private var Renderer: basicrenderengine; private var Dae: dae; private var controldisplayobject3d: displayobject3d; private var omousex: Number; private var omousey: Number; private var tmousex: number; private var tmousey: Number; private var camerax: Number; private var cameray: Number; private var target: displayobject3d; private var configfilepath: string; [bindle] private var Debug: Boolean; private function complete (): void {//} public function changedebug (value: Boolean): void {This. DEBUG = value;} // load Dae filepublic function loaddaefile (value: string): void {This. daefilepath = value; initdae3d ();} public function loadconfigfile (value: string): void {This. configfilepath = value;} // painting 3 dprivate function initdae3d (): void {Dae = new Dae (); dae. load (this. daefilepath); dae. addeventlistener (fileloadevent. load_complete, handleloadcomplete); dae. addeventlistener (fileloadevent. load_error, handleloaderror); dae. addeventlistener (fileloadevent. load_progress, handleprogress); dae. addeventlistener (fileloadevent. security_load_error, handlesecurity); dae. addeventlistener (fileloadevent. collada_materials_done, handlematerialsdone);} // load collad1_vate function handleloadcomplete (E: Event): void {This. completeloading (); initviewport (); // messagetext. TEXT = "Collada load complete";} private function handleloaderror (E: Event): void {} private function handleprogress (E: Event): void {} private function handlesecurity (E: event): void {} private function handlematerialsdone (E: Event): void {// initviewport ();} private function initviewport (): void {// setup viewport, add to stageviewport = new viewport3d (this. width, this. height, false, false); canvas. rawchildren. addchild (viewport); // setup rendererrenderer = new basicrenderengine (); // setup cameracamera = new camera3d (); camera. FOV = 18; camera. X = 0; camera. y = 0; camera. z =-1000; target = new container get = target; // setup scenescene = new scene3d (); // setup container, add Dae to container, add container to scene. scene. addchild (DAE); // alert. show (DAE. childrenlist (); // alert. show (DAE. getchildbyname ("collada_scene "). childrenlist (); // alert. show (DAE. getchildbyname ("collada_scene "). getchildbyname ("pyramid001 "). childrenlist (); // dae. getchildbyname ("collada_scene "). getchildbyname ("pyramid001 "). addeventlistener (interactivescene3devent. object_click, onclick); // dae. getchildbyname ("collada_scene", true ). addeventlistener (interactivescene3devent. object_press, onclick); dae. addeventlistener (interactivescene3devent. object_press, onclick); placeposition (); render ();} private function onclick (Event: interactivescene3devent): void {} private function placeposition (): void {dae. X = 0; dae. y = 0; dae. rotationz = 0;} private function render (): void {Renderer. renderscene (scene, camera, viewport);} // set the camera position public function setcameraposition (X: Number, Y: Number, Z: Number): void {Camera. X = x; camera. y = y; camera. z = z; render ();} private function setcamerafov (value: Number): void {Camera. FOV = value; render ();} private function zoomadd (): void {Camera. moveforward (100); render ();} private function zoomremove (): void {Camera. movebackward (100); render ();} private function zoomup (): void {Camera. moveup (100); render ();} private function zoomdown (): void {Camera. movedown (100); render ();} private function zoomleft (): void {Camera. moveleft (100); render ();} private function zoomright (): void {Camera. moveright (100); render ();} private function zoomtargetup (): void?target.x=camera.target.x?target.y=camera.target.y=10020.target.z?camera.tar get. z; label. TEXT = target. X + "," + target. Y + "," + target. z; render ();} private function zoomtargetdown (): void1_target.x?camera.target.x=target.y?camera.target.y-1001_target.z?camera.tar get. z; label. TEXT = target. X + "," + target. Y + "," + target. z; render ();} private function zoomtargetleft (): void+target.x?camera.target.x-10020.target.y?camera.target.y=target.z?camera.tar get. z; label. TEXT = target. X + "," + target. Y + "," + target. z; render ();} private function zoomtargetright (): void1_target.x?camera.target.x=1001_target.y?camera.target.y=target.z?camera.tar get. z; label. TEXT = target. X + "," + target. Y + "," + target. z; render ();} private function reset (): void {target. X = 0; target. y = 0; target. z = 0; label. TEXT = 0 + "," + 0 + "," + 0; camera. X = 0; camera. y = 0; camera. z =-1000; render () ;}]> </FX: SCRIPT> <mx: canvas id = "canvas" width = "100%" Height = "100%"/> <view1: edgecontainer id = "topedge" width = "100%" Height = "20" Click = "{zoomtargetup ()}"/> <view1: edgecontainer id = "downedge" Y = "{This. height-20} "width =" 100% "Height =" 20 "Click =" {zoomtargetdown ()} "/> <view1: edgecontainer id = "leftedge" width = "20" Height = "100%" Click = "{zoomtargetleft ()}"/> <view1: edgecontainer id = "rightedge" x = "{This. width-20} "width =" 20 "Height =" 100% "Click =" {zoomtargetright ()} "/> <s: vgroup id = "group" x = "{This. width-120} "Y =" 0 "width =" 120 "Height =" 100 "> <s: button label =" zoom in "Click =" {zoomadd ()} "/> <s: button label =" zoom out "Click =" {zoomremove ()} "/> <s: button label =" TOP "Click =" {zoomup ()} "/> <s: button label =" lower "Click =" {zoomdown ()} "/> <s: button label =" Left "Click =" {zoomleft ()} "/> <s: button label =" right "Click =" {zoomright ()} "/> <s: button label =" reset "Click =" {reset ()} "/> <s: Label id =" label "text =" 0, 0 "/> </S: vgroup> </View: basesimplecontainer>

Call example

<? XML version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx" xmlns: papervision3d = "com. shine. framework. papervision3d. * "> <FX: declarations> <! -- Place non-visual elements (such as services and value objects) Here --> </FX: declarations> <papervision3d: papervision3dfordaecontainer id = "papervision3dcontainer" width = "100%" Height = "100%" creationcomplete = "{papervision3dcontainer. loaddaefile ('room/house-new.DAE ')} "/> </S: Application>

Dae source code:

<?xml version="1.0" encoding="utf-8"?><COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">  <asset>    <contributor>      <author>Administrator</author>      <authoring_tool>OpenCOLLADA for 3ds Max;  Version: 1.2.5;  Revision: 68731:68732;  Platform: x64;  Configuration: Release Max2011</authoring_tool>      <source_data>file:///E:/%E9%99%86%E8%90%8D/3D/3Dmax%E7%BB%83%E4%B9%A0/house.max</source_data>    </contributor>    <created>2012-07-05T14:47:24</created>    <modified>2012-07-05T14:47:24</modified>    <unit name="millimeter" meter="0.001"/>    <up_axis>Z_UP</up_axis>  </asset>  <library_effects>    <effect id="____">      <profile_COMMON>        <newparam sid="house_jpg-surface">          <surface type="2D">            <init_from>house_jpg</init_from>          </surface>        </newparam>        <newparam sid="house_jpg-sampler">          <sampler2D>            <source>house_jpg-surface</source>          </sampler2D>        </newparam>        <technique sid="common">          <blinn>            <emission>              <color>0 0 0 1</color>            </emission>            <ambient>              <color>0.5960785 0.5960785 0.5960785 1</color>            </ambient>            <diffuse>              <texture texture="house_jpg-sampler" texcoord="CHANNEL1"/>            </diffuse>            <specular>              <color>0.9 0.9 0.9 1</color>            </specular>            <shininess>              <float>9.999999</float>            </shininess>            <reflective>              <color>0 0 0 1</color>            </reflective>            <transparent opaque="A_ONE">              <color>1 1 1 1</color>            </transparent>            <transparency>              <float>1</float>            </transparency>          </blinn>        </technique>      </profile_COMMON>      <extra>        <technique profile="OpenCOLLADA3dsMax">          <extended_shader>            <apply_reflection_dimming>0</apply_reflection_dimming>            <dim_level>0</dim_level>            <falloff_type>0</falloff_type>            <index_of_refraction>1.5</index_of_refraction>            <opacity_type>0</opacity_type>            <reflection_level>3</reflection_level>            <wire_size>1</wire_size>            <wire_units>0</wire_units>          </extended_shader>          <shader>            <ambient_diffuse_lock>1</ambient_diffuse_lock>            <ambient_diffuse_texture_lock>1</ambient_diffuse_texture_lock>            <diffuse_specular_lock>0</diffuse_specular_lock>            <soften>0.1</soften>            <use_self_illum_color>0</use_self_illum_color>          </shader>        </technique>      </extra>    </effect>  </library_effects>  <library_materials>    <material id="____-material" name="____">      <instance_effect url="#____"/>    </material>  </library_materials>  <library_geometries>    <geometry id="geom-Pyramid001" name="Pyramid001">      <mesh>        <source id="geom-Pyramid001-positions">          <float_array id="geom-Pyramid001-positions-array" count="18">0 0 1836.045 -663.0164 -2320.557 0 663.0164 -2320.557 0 663.0164 2320.557 0 -663.0164 2320.557 0 0 0 0</float_array>          <technique_common>            <accessor source="#geom-Pyramid001-positions-array" count="6" stride="3">              <param name="X" type="float"/>              <param name="Y" type="float"/>              <param name="Z" type="float"/>            </accessor>          </technique_common>        </source>        <source id="geom-Pyramid001-normals">          <float_array id="geom-Pyramid001-normals-array" count="51">0 -0.6204822 0.7842206 0 -0.6204822 0.7842205 0 -0.6204822 0.7842205 0.9405539 0 0.3396445 0.9405539 0 0.3396445 0.9405539 0 0.3396445 0 0.6204822 0.7842206 0 0.6204822 0.7842205 0 0.6204822 0.7842205 -0.9405539 0 0.3396445 -0.9405539 0 0.3396445 -0.9405539 0 0.3396445 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 -1</float_array>          <technique_common>            <accessor source="#geom-Pyramid001-normals-array" count="17" stride="3">              <param name="X" type="float"/>              <param name="Y" type="float"/>              <param name="Z" type="float"/>            </accessor>          </technique_common>        </source>        <source id="geom-Pyramid001-map1">          <float_array id="geom-Pyramid001-map1-array" count="51">0.9014655 0.3870191 0 0.8135806 0.3851358 0 0.7504084 0.6062383 0 0.6872362 0.387019 0 0.6872362 0.8292241 0 0.8135806 0.8273408 0 0.2524371 0.2311026 0 0.4273754 0.01 0 0.4273754 0.4522052 0 0.2524371 0.6897829 0 0.4273754 0.4686803 0 0.07317217 0.9686654 0 0.01 0.7475629 0 0.1363443 0.7475629 0 0.4273754 0.9108855 0 0.9646376 0.6081216 0 0.8382932 0.6081216 0</float_array>          <technique_common>            <accessor source="#geom-Pyramid001-map1-array" count="17" stride="3">              <param name="S" type="float"/>              <param name="T" type="float"/>              <param name="P" type="float"/>            </accessor>          </technique_common>        </source>        <source id="geom-Pyramid001-map1-textangents">          <float_array id="geom-Pyramid001-map1-textangents-array" count="51">-1 0 0 -1 0 0 -1 0 0 0.3396445 5.50797e-8 -0.9405539 0.3396445 5.50797e-8 -0.9405539 0.3396445 5.50797e-8 -0.9405539 -1 0 0 -1 0 0 -1 0 0 -0.3396445 -1.60232e-7 -0.9405539 -0.3396445 -1.60232e-7 -0.9405539 -0.3396445 -1.60232e-7 -0.9405539 -0.999944 0.007483723 0 -0.9998334 0.01490172 0 -0.999722 0.02238306 0 -0.9997229 0.02231972 0 -0.9999449 0.00742038 0</float_array>          <technique_common>            <accessor source="#geom-Pyramid001-map1-textangents-array" count="17" stride="3">              <param name="X" type="float"/>              <param name="Y" type="float"/>              <param name="Z" type="float"/>            </accessor>          </technique_common>        </source>        <source id="geom-Pyramid001-map1-texbinormals">          <float_array id="geom-Pyramid001-map1-texbinormals-array" count="51">0 0.7842205 0.6204822 0 0.7842205 0.6204822 0 0.7842205 0.6204822 1.87075e-8 -1 -5.18054e-8 1.87075e-8 -1 -5.18054e-8 1.87075e-8 -1 -5.18054e-8 0 0.7842205 -0.6204822 0 0.7842205 -0.6204822 0 0.7842205 -0.6204822 -5.44219e-8 1 -1.50707e-7 -5.44219e-8 1 -1.50707e-7 -5.44219e-8 1 -1.50707e-7 -0.007483933 -0.999972 0 -0.01490255 -0.999889 0 -0.02238368 -0.9997495 0 -0.02232034 -0.9997509 0 -0.007420584 -0.9999725 0</float_array>          <technique_common>            <accessor source="#geom-Pyramid001-map1-texbinormals-array" count="17" stride="3">              <param name="X" type="float"/>              <param name="Y" type="float"/>              <param name="Z" type="float"/>            </accessor>          </technique_common>        </source>        <vertices id="geom-Pyramid001-vertices">          <input semantic="POSITION" source="#geom-Pyramid001-positions"/>        </vertices>        <triangles material="_____1" count="8">          <input semantic="VERTEX" source="#geom-Pyramid001-vertices" offset="0"/>          <input semantic="NORMAL" source="#geom-Pyramid001-normals" offset="1"/>          <input semantic="TEXCOORD" source="#geom-Pyramid001-map1" offset="2" set="1"/>          <input semantic="TEXTANGENT" source="#geom-Pyramid001-map1-textangents" offset="3" set="1"/>          <input semantic="TEXBINORMAL" source="#geom-Pyramid001-map1-texbinormals" offset="3" set="1"/>          <p>0 0 0 0 1 1 15 1 2 2 16 2 0 3 6 3 2 4 7 4 3 5 8 5 0 6 11 6 3 7 12 7 4 8 13 8 0 9 9 9 4 10 10 10 1 11 14 11 1 12 1 12 5 13 2 13 2 14 3 14 2 14 3 14 5 13 2 13 3 15 4 15 3 15 4 15 5 13 2 13 4 16 5 16 4 16 5 16 5 13 2 13 1 12 1 12</p>        </triangles>      </mesh>    </geometry>  </library_geometries>  <library_lights>    <light id="EnvironmentAmbientLight" name="EnvironmentAmbientLight">      <technique_common>        <ambient>          <color>0 0 0</color>        </ambient>      </technique_common>    </light>  </library_lights>  <library_images>    <image id="house_jpg">      <init_from>./images/house.jpg</init_from>    </image>  </library_images>  <library_visual_scenes>    <visual_scene id="MaxScene">      <node name="EnvironmentAmbientLight">        <instance_light url="#EnvironmentAmbientLight"/>      </node>      <node id="node-Pyramid001" name="Pyramid001">        <matrix>2.023743 0 0 1331.657 0 0.9331092 0 2349.663 0 0 1 2324.805 0 0 0 1</matrix>        <instance_geometry url="#geom-Pyramid001">          <bind_material>            <technique_common>              <instance_material symbol="_____1" target="#____-material">                <bind_vertex_input semantic="CHANNEL1" input_semantic="TEXCOORD" input_set="1"/>              </instance_material>            </technique_common>          </bind_material>        </instance_geometry>        <extra>          <technique profile="Alternativa3D">            <instance xmlns="http://alternativaplatform.com/a3d/Instance">              <instance_mesh url="#Pyramid001-mesh"/>            </instance>          </technique>        </extra>      </node>    </visual_scene>  </library_visual_scenes>  <scene>    <instance_visual_scene url="#MaxScene"/>  </scene>  <extra>    <technique profile="Alternativa3D">      <library xmlns="http://alternativaplatform.com/a3d/Library">        <library_meshes>          <mesh id="Pyramid001-mesh"/>        </library_meshes>        <version>2.4</version>      </library>    </technique>  </extra></COLLADA>

Actual results:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.