Skip to main content
Participating Frequently
December 5, 2011
Answered

Smoothing

  • December 5, 2011
  • 2 replies
  • 939 views

Hello everybody,

With away3d I import 3d models into flash builder 4.5 as follows:

package
{
      import models.example;

      public class model extends Sprite
      {
           public var model_example:example = new example;

           public function model()
           {
                view.scene.addChild(model_example);
           }
      }
}

In the file 'models.example.as' a jpg is used as texture for the model:

[Embed(source="picture.jpg")]
private var Obj_000001_Bitmap_Bitmap:Class;

Picture.jpg is a picture of some text and it's not displayed very well.

I found something about smoothing on this site:  http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=4&aid=121

The text on my model is just as the text on the right cube in that article. I would like to have it as on the left cube but it seems that it does not work in my case.

Could anybody help me further?

This topic has been closed for replies.
Correct answer _spoboyle

well i get the smoothing effect you need to set smooth = true on your materials and as far as i can see you are not doing that

set inside applyMaterialToMesh

meshes.material.smooth = true

however I am no Away3D expert and I can't say for certain this will fix you issue with out your fullproject you can't attached a zip file here you'd have to email it me

2 replies

Participating Frequently
December 6, 2011

Thanks! It's working correct!

I never thought it's that easy.

I have an other ac3 problem which I still can't solve. Maybe it's also easy for you.

You have two discs, an frontdisc and an backdics. These discs are parallel. The backdisc contains text and the frontdisc has a window so you can see the text on the backdisc through the window.

When you click on the frontdisc with the mouse, the backdisc is turning 360 degrees.

You also can turn the complete model (frontdisc and backdisc) with your mouse. If you do that, you see that you have a depth sorting problem. You can see the text on the backdisc through the frontdisc (not the window).

Is it possible to make the text on the backdisc invisible and make it only visible when it's behind the window? I think I can solve the depth problem in this way.

I think it has to do with masking but I have no idea how to do that.

Maybe you don't have any idea what I'm talking about. I can mail you this complete project and you will see directly what I mean.

By the way, maybe it's better to start a new discussion.

_spoboyle
Inspiring
December 9, 2011

This one isn't going to be so easy for me to fix.

I have seen other people have similar issues though and their problem was a matter of scale.

Do you still have a problem is you increase the distance between the dics?

try increasing the size of the model that might fix the problem

Participating Frequently
December 9, 2011

Thanks for reply.

Yes, I still have the problem if I increase the scale of the model.

By the way, I started a new discussion about this problem: http://forums.adobe.com/thread/933832

_spoboyle
Inspiring
December 6, 2011

we are going to have to see the rest of your code to help

Participating Frequently
December 6, 2011

Here's the complete code.

I also would like to attach a zip of the complete project but I don't know how to do that.

package

{

    import away3d.cameras.HoverCamera3D;

    import away3d.containers.*;

    import away3d.events.MouseEvent3D;

    import fl.controls.Button;

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.events.MouseEvent;

    import flash.events.TimerEvent;

    import flash.text.TextField;

    import flash.text.TextFieldAutoSize;

    import flash.utils.*;

    import model.text.text;

    [SWF(width="600", height="600", frameRate="60", backgroundColor="#000000")]

    public class model extends Sprite

    {

        public var view:View3D;

        private var cam:HoverCamera3D;   

        private var move:Boolean = false;

        private var lastPanAngle:Number;

        private var lastTiltAngle:Number;

        private var lastMouseX:Number;

        private var lastMouseY:Number;

        public var model_text:text = new text;

        public function model()

        {

            example();       

            view.scene.addChild(model_text);

        }

        public function example(): void

        {

            cam = new HoverCamera3D({zoom:1, focus:7});

            cam.panAngle = cam.panAngle = 0;

            cam.tiltAngle = cam.tiltAngle = 0;

            cam.hover(true);

            view = new View3D({x:300,y:300,camera:cam});

            addChild(view);

            view.camera.y = 300;

            view.camera.zoom = 150;

            this.addEventListener(Event.ENTER_FRAME,update);

            stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);

            stage.addEventListener(MouseEvent.MOUSE_UP, MouseUp);

        }

        public function update(e:Event):void

        {

            var cameraSpeed:Number = 0.5;

            if (move)

            {

                cam.panAngle = cameraSpeed*( stage.mouseX - lastMouseX) + lastPanAngle;

                cam.tiltAngle = cameraSpeed*(- stage.mouseY + lastMouseY) + lastTiltAngle;

            }

            cam.hover();

            view.render();

        }

        private function MouseDown(event:MouseEvent):void

        {

            lastPanAngle = cam.panAngle;

            lastTiltAngle = cam.tiltAngle;

            lastMouseX = stage.mouseX;

            lastMouseY = stage.mouseY;

            move = true;

        }

        private function MouseUp(event:MouseEvent):void

        {

            move = false;

        }

    }

}

package model.text

{

    import away3d.containers.ObjectContainer3D;

    import away3d.containers.Scene3D;

    import away3d.materials.*;

    import away3d.core.base.*;

    import away3d.loaders.utils.*;

    import away3d.loaders.data.*;

    import flash.utils.Dictionary;

    import away3d.primitives.*;

    import flash.display.Bitmap;

    import flash.display.BitmapData;

    import flash.geom.*;

    public class text extends ObjectContainer3D

    {

        [Embed(source="images/text.jpg")]

        private var Obj_000001_Bitmap_Bitmap:Class;

        private var objs:Object = {};

        private var geos:Array = [];

        private var oList:Array =[];

        private var aC:Array;

        private var aV:Array;

        private var aU:Array;

        private var _scale:Number;

        public function text(scale:Number = 1)

        {

            _scale = scale;

            setSource();

            addContainers();

            buildMeshes();

            buildMaterials();

            cleanUp();

        }

        private function buildMeshes():void

        {

            var m0:Matrix3D = new Matrix3D();

            m0.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,-5*_scale,-15*_scale,0*_scale,1]);

            transform = m0;

            objs.obj0 = {name:"Obj_000001",  transform:m0, pivotPoint:new Vector3D(0,0,0), container:0, bothsides:false, material:null, ownCanvas:false, pushfront:false, pushback:false};

            objs.obj0.geo=geos[0];

            var ref:Object;

            var mesh:Mesh;

            var j:int;

            var av:Array;

            var au:Array;

            var v0:Vertex;

            var v1:Vertex;

            var v2:Vertex;

            var u0:UV;

            var u1:UV;

            var u2:UV;

            var aRef:Vector.<Face>;

            for(var i:int = 0;i<1;++i){

                ref = objs["obj"+i];

                if(ref != null){

                    mesh = new Mesh();

                    mesh.type = ".as";

                    mesh.bothsides = ref.bothsides;

                    mesh.name = ref.name;

                    mesh.pushfront = ref.pushfront;

                    mesh.pushback = ref.pushback;

                    mesh.ownCanvas = ref.ownCanvas;

                    if(aC[ref.container]!= null)

                        aC[ref.container].addChild(mesh);

                    oList.push(mesh);

                    mesh.transform = ref.transform;

                    mesh.movePivot(ref.pivotPoint.x, ref.pivotPoint.y, ref.pivotPoint.z);

                    if (ref.geo.geometry != null) {

                        mesh.geometry = ref.geo.geometry;

                        continue;

                    }

                    ref.geo.geometry = new Geometry();

                    mesh.geometry = ref.geo.geometry;

                    aRef = ref.geo.f;

                    for(j = 0;j<aRef.length;++j){

                        Face(aRef).material = ref.material;

                        ref.geo.geometry.addFace( Face(aRef));

                    }

                }

            }

        }

        private function setSource():void

        {

            var geo0vert:String ="-a19/-a19/50,0/-a19/50,-a19/-a19/-50,a19/-a19/50,a19/-a19/-50,0/-a19/-50,-a19/a19/50,-a19/0/50,-a19/a19/-50,-a19/-a19/50,-a19/-a19/-50,-a19/0/-50,a19/a19/50,0/a19/50,a19/a19/-50,-a19/a19/50,-a19/a19/-50,0/a19/-50,a19/-a19/50,a19/0/50,a19/-a19/-50,a19/a19/50,a19/a19/-50,a19/0/-50,a19/-a19/50,0/-a19/50,a19/0/50,-a19/-a19/50,-a19/0/50,-a19/a19/50,0/a19/50,a19/a19/50,-a19/-a19/-50,0/-a19/-50,-a19/0/-50,a19/-a19/-50,a19/0/-50,-a19/a19/-50,0/a19/-50,a19/a19/-50";

            var geo0uvs:String ="0.09c8a1eeb693fd/0.3294f337e9dca,0.09c8a1eeb693fd/0.194a799bf4ee5,0.01f4ed2fbe1d99/0.3294f337e9dca,0.09c8a1eeb693fd/0,0.01f4ed2fbe1d99/0,0.01f4ed2fbe1d99/0.194a799bf4ee5,0/0.3294f337e9dca,0/0.194a799bf4ee5,0.09c8a1eeb693fd/0.3294f337e9dca,0/0,0.09c8a1eeb693fd/0,0.09c8a1eeb693fd/0.194a799bf4ee5,0.02ef63c8b963f9/0.3294f337e9dca,0.02ef63c8b963f9/0.194a799bf4ee5,0.3e9da5f7c3b32/0.3294f337e9dca,0.02ef63c8b963f9/0,0.3e9da5f7c3b32/0,0.3e9da5f7c3b32/0.194a799bf4ee5,0.01f4ed2fbe1d99/0.3294f337e9dca,0.01f4ed2fbe1d99/0.194a799bf4ee5,0.02ef63c8b963f9/0.3294f337e9dca,0.01f4ed2fbe1d99/0,0.02ef63c8b963f9/0,0.02ef63c8b963f9/0.194a799bf4ee5,0.3e9da5f7c3b32/0.5,0.cc4eda986a8b4/0.5,0.3e9da5f7c3b32/0.ae73d3ed0d,0.22999b42d57c6/0.5,0.22999b42d57c6/0.ae73d3ed0d,0.22999b42d57c6/0.173fbbbb69,0.cc4eda986a8b4/0.173fbbbb69,0.3e9da5f7c3b32/0.173fbbbb69,0.3e9da5f7c3b32/0.b9b804769,0.3e9da5f7c3b32/0.3a0981650d,0.cc4eda986a8b4/0.b9b804769,0.3e9da5f7c3b32/0,0.cc4eda986a8b4/0,0.22999b42d57c6/0.b9b804769,0.22999b42d57c6/0.3a0981650d,0.22999b42d57c6/0";

            var geo0faces:String ="0,1,2,0,1,2,1,3,4,1,3,4,4,5,1,4,5,1,5,2,1,5,2,1,6,7,8,6,7,8,7,9,a,7,9,a,a,b,7,a,b,7,b,8,7,b,8,7,c,d,e,c,d,e,d,f,10,d,f,10,10,11,d,10,11,d,11,e,d,11,e,d,12,13,14,12,13,14,13,15,16,13,15,16,16,17,13,16,17,13,17,14,13,17,14,13,18,19,1a,18,19,1a,19,1b,1c,19,1b,1c,1c,1d,1e,1c,1d,1e,1e,1f,1a,1e,1f,1a,1a,19,1c,1a,19,1c,1c,1e,1a,1c,1e,1a,20,21,22,20,21,22,21,23,24,21,23,24,25,22,26,25,22,26,27,26,24,27,26,24,22,21,24,22,21,24,26,22,24,26,22,24";

            var geo0:FacesDefinition = new FacesDefinition();

            geo0.f = buildFaces( geo0faces.split(","),  buildVertices(read(geo0vert).split(",")), buildUVs(read(geo0uvs).split(",")) );

            geos.push(geo0);

        }

        private function buildFaces(aFaces:Array, vVerts:Vector.<Vertex>, vUVs:Vector.<UV>):Vector.<Face>

        {

            var vFaces:Vector.<Face> = new Vector.<Face>();

            var f:Face;

            for(var i:int = 0;i<aFaces.length;i+=6){

                f = new Face( vVerts[parseInt(aFaces, 16)],

                                    vVerts[parseInt(aFaces[i+1], 16)],

                                    vVerts[parseInt(aFaces[i+2], 16)],

                                    null,

                                    vUVs[parseInt(aFaces[i+3], 16)],

                                    vUVs[parseInt(aFaces[i+4], 16)],

                                    vUVs[parseInt(aFaces[i+5], 16)]);

                vFaces.push(f);

            }

            return vFaces;

        }

        private function buildVertices(aVerts:Array):Vector.<Vertex>

        {

            var tmpv:Array;

            var vVerts:Vector.<Vertex> = new Vector.<Vertex>();

            for(var i:int = 0;i<aVerts.length;i++){

                tmpv = aVerts.split("/");

                vVerts = new Vertex( parseFloat(tmpv[0])*_scale, parseFloat(tmpv[1])*_scale, parseFloat(tmpv[2])*_scale  );

            }

            return vVerts;

        }

        private function buildUVs(aUvs:Array):Vector.<UV>

        {

            var tmpv:Array;

            var vUVs:Vector.<UV> = new Vector.<UV>();

            for(var i:int = 0;i<aUvs.length;++i){

                tmpv = aUvs.split("/");

                vUVs = new UV(parseFloat(tmpv[0]), parseFloat(tmpv[1]));

            }

            return vUVs;

        }

        private function buildMaterials():void

        {

                var obj_000001_Bitmap:Bitmap = new Obj_000001_Bitmap_Bitmap();

                applyMaterialToMesh("Obj_000001", obj_000001_Bitmap.bitmapData);

        }

        private function applyMaterialToMesh(id:String, bmd:BitmapData):void

        {

            for(var i:int;i<meshes.length;++i){

                if(meshes.name == id){

                    if(!bmd){

                        trace("Embed of "+id+" failed! Check source path or if CS4 call 911!");

                    } else {

                    meshes.material = new BitmapMaterial(bmd);

                    }

                    break;

                }

            }

        }

        private function cleanUp():void

        {

            for(var i:int = 0;i<1;++i){

                objs["obj"+i] == null;

            }

            aV = null;

            aU = null;

        }

        private function addContainers():void

        {

            aC = [];

            aC.push(this);

            var m0:Matrix3D = new Matrix3D();

            m0.rawData = Vector.<Number>([1,0,0,0,0,1,0,0,0,0,1,0,0*_scale,0*_scale,0*_scale,1]);

            transform = m0;

            name = "main";

        }

        public function get containers():Array

        {

            return aC;

        }

        public function get meshes():Array

        {

            return oList;

        }

        private function read(str:String):String

        {

            var start:int= 0;

            var chunk:String;

            var end:int= 0;

            var dec:String = "";

            var charcount:int = str.length;

            for(var i:int = 0;i<charcount;++i){

                if (str.charCodeAt(i)>=44 && str.charCodeAt(i)<= 48 ){

                    dec+= str.substring(i, i+1);

                }else{

                    start = i;

                    chunk = "";

                    while(str.charCodeAt(i)!=44 && str.charCodeAt(i)!= 45 && str.charCodeAt(i)!= 46 && str.charCodeAt(i)!= 47 && i<=charcount){

                        i++;

                    }

                    chunk = ""+parseInt("0x"+str.substring(start, i), 16 );

                    dec+= chunk;

                    i--;

                }

            }

            return dec;

        }

    }

}

class FacesDefinition

{

    import away3d.core.base.Face;

    import away3d.core.base.Geometry;

    public var f:Vector.<Face>;

    public var geometry:Geometry;

}

_spoboyle
_spoboyleCorrect answer
Inspiring
December 6, 2011

well i get the smoothing effect you need to set smooth = true on your materials and as far as i can see you are not doing that

set inside applyMaterialToMesh

meshes.material.smooth = true

however I am no Away3D expert and I can't say for certain this will fix you issue with out your fullproject you can't attached a zip file here you'd have to email it me