Using Papervision Object Parsers
Jan.29, 2009 in
3D, AS3, Flash, Papervision, Tutorials
Sketchup Parser
What is a Sketchup file?
While I was unable to get this parser to properly read the kmz file, I was able to extract the content of the kmz and load the Sketchup DAE file without a probem. To do this, just follow the instructions from the DAE parser above.
Sketchup Parsing Example
-
package {
-
import flash.events.Event;
-
import org.papervision3d.lights.PointLight3D;
-
import org.papervision3d.materials.shadematerials.GouraudMaterial;
-
import org.papervision3d.materials.utils.MaterialsList;
-
import org.papervision3d.objects.parsers.DAE;
-
import org.papervision3d.view.BasicView;
-
-
public class SketchupParser_v1 extends BasicView {
-
// create a class-level var for the collada scene
-
private var _dae:DAE;
-
// create the light
-
private var _light:PointLight3D;
-
-
public function SketchupParser_v1() {
-
lights();
-
init3d();
-
}
-
-
private function lights():void {
-
// create the light to the scene
-
_light = new PointLight3D(true, true);
-
// place it in the same position as the camera (0, 0, -1000);
-
_light.copyPosition(camera);
-
}
-
-
private function init3d():void {
-
// create a materials list and add the wireframe material
-
var knotMaterialsList:MaterialsList = new MaterialsList();
-
// we are now going to use a gouraud material for shading
-
var knotMaterial:GouraudMaterial = new GouraudMaterial(_light);
-
knotMaterialsList.addMaterial(knotMaterial, "all");
-
// instantiate the DAE obj and load the knot object
-
// apply the material and scale to 0.05
-
_dae = new DAE();
-
_dae.load("assets/sketchup/knot.dae", knotMaterialsList);
-
_dae.scale = 1;
-
camera.z = -5;
-
// add the DAE file to the scene
-
scene.addChild(_dae);
-
// start rendering (activated onRenderTick)
-
startRendering();
-
}
-
-
override protected function onRenderTick(event:Event = null):void {
-
// rotate the object
-
_dae.yaw(1);
-
super.onRenderTick();
-
}
-
}
-
}
This, you may notice, is identical to the DAE loader. That is because it is just loading the DAE extracted from the Sketchup kmz file.
Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9
Related Posts











February 2nd, 2009 at 4:50 am
If your looking for some tutorials on Papervision you can check out http://hubpages.com/hub/Papervision-3D-programming-tutorial-Depth-of-Field and http://hubpages.com/hub/Papvervision-3D-programming-tutorial-Casting-Shadows
February 3rd, 2009 at 5:11 pm
nice article. it has been a huge help in getting me going. thanks for taking the time to write it.
February 5th, 2009 at 3:00 pm
The latest SVN branch is http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/
February 7th, 2009 at 11:27 am
Thank you very much!
February 15th, 2009 at 5:45 am
after setting up the primitives, i dont see any objects when i test the movie, just background without anything objects.
i script and import onto the main FLA, what did i missed? O_o
February 15th, 2009 at 12:41 pm
Hi,
I am a beginner who just started learning papervision3D. I am using Flex builder for it.
So far I found your article very nice until I encountered the statement, “One thing to note is the use of the MovieAssetMaterial, for this I had to create a MovieClip in the Flash library and export it for actionscript (Linkage). Once defined, the materials can be used on any object, over and over again”.
Could you please tell me or point me to a tutorial which describes how to create a MovieClip in the Flash Library and export it for actionscript (linkage).
February 15th, 2009 at 2:05 pm
In flex i believe that you can just use the [Embed] metatag and point it to a swf. Give it an id and then use that as a movieassetmaterial, take a look here: http://www.bit-101.com/blog/?p=853.
February 15th, 2009 at 9:04 pm
Super helpful tutorial. Thanks Matthew.
When I try to compile HelloMaterials.as in Flex Builder 3 using [Embed(source="spheremat1.swf", symbol='spheremat')] to give sphereMaterial a texture i keep getting this in the Problems panel:
“An Embed variable must not have an existing value.”
February 16th, 2009 at 7:54 am
Just a little thing I noticed:
I checked out revision 876 today and tryed these tutorials with flash cs4 and I had to add opacity to this line to make it work:
var planeMaterial:ColorMaterial = new ColorMaterial(0×55FF11, 100);
February 17th, 2009 at 5:45 am
Yes! in this line:
var planeMaterial:ColorMaterial = new ColorMaterial(0×55FF11);
I have the same error… why??
1084: Error de sintaxis: se esperaba rightparen antes de 55.
February 17th, 2009 at 11:31 am
very odd errors with the materials because the constructor doesn’t even require a color. it is provided with a default:
public function ColorMaterial( color:Number=0xFF00FF, alpha:Number = 1, interactive:Boolean = false )
unfortunately I don’t have a copy of CS4 but i might be able to play around tonight to see if i can reproduce the issue
February 22nd, 2009 at 8:46 pm
Marc,
Is there a way to make it work with CS3 using an external swf for assets, like so:
[Embed(source="assets.swf", symbol="sphereMaterial")]
var sphereMaterial:MovieAssetMaterial = new MovieAssetMaterial(”sphereMaterial”);
February 22nd, 2009 at 8:53 pm
using an external file is done with the BitmapFileMaterial for images or the asset material with a swf. but you have to properly load it in. the embed tag that you are showing there is a flex meta tag that isn’t valid in CS3. you could just use a loader in cs3 and reference that movie once it has finished loading.
March 2nd, 2009 at 10:58 am
Hi Marc, I’m using papervision3d and flash cs3. How do I add a swf as an object/movieclip (just like any other primitives - sphere, cube, etc)? And I want this swf object appear at a highest index (so that it appears at the front)? Please advise. Thanks.
March 11th, 2009 at 4:43 pm
Thank you for your website and the tutorials Marc :), now all I have to do is learn Flash, Actionscript3 and Papervision3D
Porly G
March 14th, 2009 at 3:04 pm
Marc,
I am going to keep working on this my self, but in case you have any insight, I get the following error when publishing HelloMaterials:
INFO: Papervision3D 2.0.0 (March 12th, 2009)
INFO: Viewport autoScaleToStage : Papervision has changed the Stage scale mode.
ReferenceError: Error #1065: Variable sphereMaterial is not defined.
at global/flash.utils::getDefinitionByName()
at org.papervision3d.materials::MovieAssetMaterial/createMovie()
at org.papervision3d.materials::MovieAssetMaterial/set texture()
at org.papervision3d.materials::MovieAssetMaterial()
at HelloAnimation()
I’ve never seen a MovieClip referred to as a Class before. Is there a Script that goes with the MovieAssetMaterial MovieClip?
March 14th, 2009 at 3:53 pm
Figured this part out:
The Linkage to the empty MovieClip should be sphereMaterial… NOT MovieAssetMaterial
March 14th, 2009 at 8:13 pm
Hey Danny,
you have lost me. sphereMaterial is the linkage name of the movieclip in the library. I am applying it as a MovieAssetMaterial
March 17th, 2009 at 7:17 pm
Hello Marc !
Thank you a lot for this tutorial.
After lots of research on the web, I can’t fix my problem :
I Create a FLA files with HelloPapervision.as as Document CLASS, and I have my HelloPapervision.as with the first simple code.
When I extends BasiView, the flash compiler say :
TriangleMaterial.as, line 24 :
1020: Method marked override must override another method.
Is it the good way to lunch the application ?
Thank you for you help …
I still continue to search my nut
March 17th, 2009 at 7:53 pm
Ok it’s work … it was the mess in my org folder… sorry !!
Let’s go
March 31st, 2009 at 7:30 am
Hi! A very nice job!!
But if you cancel the rotationY of sphere and container in the overrided function in the “Controlling Objects with the Mouse” section, it will be better…
Bye!
April 7th, 2009 at 11:31 am
Very nice tutorials. Please, keep’em coming!! =)
July 9th, 2009 at 5:40 am
You’re so GOOD.
It works properly! Thanx
October 3rd, 2009 at 10:41 pm
Cool anybody knows how import or parse collada with animation and run it in PV3d ?
October 5th, 2009 at 7:17 am
Hey.. nice work..
I get the cam feed and such, but when I run I get error
1017: the definition of base class ObjectContainer3D was not found..
Any help…
February 20th, 2010 at 8:05 pm
I tried this code with Papervision 2 and it gives me a huge error in Papervision 2 code.
The Papervision version is Papervision3D_2.1.920
there about 20 compiler errors for package org.papervision3d.objects.parsers.Max3DS
like this one:
” 1178: Attempted access of inaccessible property _textureExtensionReplacements through a reference with static type org.papervision3d.objects.parsers:Max3DS. ”
also compiler errors for few more classes.
I took a look at the code, and I saw that some variables are declared later than they are used, for example in the class
org.papervision3d.objects.parsers.Max3DS ,
the variable
private var _textureExtensionReplacements:Object;
is declared in line 636, but the compiler error is in the line 41 - “1178: Attempted access of inaccessible property _textureExtensionReplacements through a reference with static type org.papervision3d.objects.parsers:Max3DS.”
I had this mistake in my work but PV3D2 developers knows better. Maybe I should contact them? Does anyone use PV3D 2 ? WHat results do you get?