Search code examples
actionscript-3papervision3d

Very small 3d rendering


I'm writing a small piece of code on 3D model rendition based on this post: http://active.tutsplus.com/tutorials/3d/quick-tip-displaying-a-3d-model-with-papervision3d/

I downloaded a free DAE file (car_shell_001.dae) and a texture (vehicle_texture.jpg).

I just copied the code from example, changing file pointer to my files. Here's the code:

public class Tarini extends BasicView
    {
        [Embed(source="Assets/car_shell_001.dae", mimeType="application/octet-stream")]
        private var bikeModelClass:Class;

        [Embed(source="./Assets/vehicle_texture.jpg")]
        private var bikeTextureClass:Class;

        private var bikeModelDAE:DAE;

        public function Tarini() 
        {
            this.loaderInfo.addEventListener ( Event.COMPLETE, onFullyLoaded ) ;
        }

        private function onFullyLoaded(e:Event):void 
        {
                var bitmap:Bitmap = new bikeTextureClass ( ) ;

                var bitmapMaterial:BitmapMaterial = new BitmapMaterial ( bitmap.bitmapData ) ;

                var materialsList:MaterialsList = new MaterialsList ( ) ;
                materialsList.addMaterial ( bitmapMaterial, "all" ) ;

                var byteArray:ByteArray = new bikeModelClass ( ) ;

                bikeModelDAE = new DAE ( ) ;
                bikeModelDAE.load ( byteArray, materialsList ) ;

                this.scene.addChild ( bikeModelDAE ) ;

                this.camera.z = 500;

                this.startRendering ( ) ;
        }

    }

This is so simple and I like it. I compile with mxmlc and I've got no compilation errors. When I open the generated swf I obtain a veeeeery small rendition in the centre of the browser.

What's the problem? I need to force dimensions in some way? If you think that having dae and jpg file will be useful, tell me :)


Solution

  • It's very common for the measurement units to be different between a 3D engine and 3D editor (actually just between editor you can observe that: simply export a cube from Blender for example and check it in Sketchup/3dsmax/etc.)

    Simplest thing you can do is scale the model up after initializing it:

    bikeModelDAE.scale = 10;//or any other value that works best for you
    

    Another valid option is to play with the camera zoom/focus options. If you only have a model to display you can use either method (object scale, camera properties), but if you have multiple models, it's probably best to make sure you use a similar scale between models.

    A bit off topic, I asume you know that Papervision has not been updated since 2010. I recommend trying an engine that is still developed, like Away3D for example.