The normalmapGenerator is there to generate the normalmap... not the colour information,

basically your code is ok, but you need to pass a source to the dot3material also the map, even if available before the trace starts, its not traced yet, so may be you want to wait until its traced. Note that using f10, you can save this map, at dev time, then use it for the runtime.
in case of a cylinder you do not need a map that big.

here an example of the flow

first your generate the normal map

mapgen = new NormalMapGenerator(myCylinder, 512, 512);
mapgen.addOnTraceProgress(traceProgress);
mapgen.addOnTraceComplete(traceComplete);


private function traceComplete(e:TraceEvent):void
{
      myMapIsReady(); --> generate dot3material
}
                        
private function traceProgress(e:TraceEvent):void
{
     trace(Math.round(e.percent)+"%");
}

private function traceProgress(e:TraceEvent):void
{
var coloursource:BitmapData = getMyNiceImage(); --> the texture, coloursource var mat:Dot3BitmapMaterial = new Dot3BitmapMaterial(coloursource, mapgen.normalmap); --> make material with the map
    (myCylinder as Mesh).material = mat; --> apply the material

        --> render
}


if you want show before, you can like in your code apply at start.

what you forgot however is to give a source of light...
so in your complete or at init of your class you need to generate a light source:


private function traceComplete(e:TraceEvent):void
{
        initLights(); --> generate the lights
         myMapIsReady(); --> and then generate dot3material
}

private function initLights():void
                        {
light = new DirectionalLight3D({color:0xFFFFFF, ambient:0.25, diffuse:0.75, specular:0.9});
                                light.x = 5000;
                                light.z = 0;
                                light.y = 5000;
                                scene.addChild( light );
                        }


The normalmap, like the heightmap or the prebaking requires unique mapping. the means that a model must have faces mapped in a way where no faces uv refference overlap each other.
using most primitives it will not be a problem.
Some do require a variable, for instance the Cube class, repeat standard all face uv mapping. this means that the trace will trace 6 times the same area of the map, in the end, all faces of the cube will ave same light influence of the light. in case of the cube, you need to pass map6:true. The mapping will be then unique.

here an example of unique mapping, and where the normalmap is applied as dotmaterial before its fully traced

http://www.closier.nl/playground/normalmaps_after.html


there are more important factors for a successfull trace of a normalmap, but I do not want overload you with info (which I probably already did :)) )

I hope at least this clarifies a bit the NM generation/use.


Fabrice




On Jun 24, 2009, at 7:45 PM, DesignByLefty wrote:


I have a collada object (a cocacola bottle) and starting with basic
demos and
code i found here and there, but i'm not totally sure to understand
what i'm doing.
So i load the collada object and launch the normal map generator but
then
i'm not sure what to do to apply this to a cylinder

here is the full code, i'm pretty sure there is thing not needed, and
thing to
add but i'have no idea what and how.

****************************************************************************
// import containers
import away3d.containers.*;
// import core library
import away3d.core.base.*;
// import geometry primitives
import away3d.primitives.*;
 import away3d.cameras.HoverCamera3D;
 import away3d.containers.ObjectContainer3D;
 import away3d.containers.Scene3D;
 import away3d.containers.View3D;
 import away3d.core.render.Renderer;
 import away3d.core.utils.Cast;
 import away3d.lights.DirectionalLight3D;
 import away3d.materials.Dot3BitmapMaterial;
 import away3d.materials.EnviroBitmapMaterial;
 import away3d.primitives.Plane;
 import away3d.primitives.Sphere;
 import away3d.loaders.Collada;
   import away3d.loaders.Object3DLoader;
        import away3d.materials.utils.NormalMapGenerator;

 import flash.display.Bitmap;
 import flash.display.BitmapData;
 import flash.display.Sprite;
 import flash.display.StageAlign;
 import flash.display.StageScaleMode;
 import flash.events.Event;
 import flash.events.MouseEvent;

// create a 3D-viewport
var view:View3D = new View3D({x:300, y:200});
addChild(view);

// create primitives
var loader:Object3DLoader = Collada.load('coke.dae',
{autoLoadTextures:false});
var mesh:Mesh = Mesh((loader.handle as
ObjectContainer3D).getChildByName('Polygon'));
var mapgen:NormalMapGenerator = new NormalMapGenerator(mesh,1200,
1200, null, 0, 100);

var mat:Dot3BitmapMaterial = new Dot3BitmapMaterial
(mapgen.normalmap,mapgen.normalmap);

var plane:Object3D = new Plane({material:"yellow#", name:"plane",
y:-100, width:1000, height:1000, pushback:true});
var sphere:Object3D = new Cylinder({material:"red#", name:"sphere",
segmentsH:6,segmentsW:15,heigth:670,radius:70});
var cube:Object3D = new Cube({material:"blue#", name:"cube", x: 300, y:
160, z: -80, width:20, height:200, depth:200});
var torus:Object3D = new Torus({material:"limegreen#", name:"torus",
x:-250, y:160, z:-250, radius:15, tube:6, segmentsR:8, segmentsT:6});

// add primitives to the scene
view.scene.addChildren(sphere, cube, plane, torus);

// set camera in space
view.camera.moveTo(torus.x, torus.y, torus.z);
view.camera.lookAt(cube.position);
view.camera.moveBackward(1500);
view.camera.moveUp(1500);
view.camera.lookAt(plane.position);

// every frame
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
        // rerender viewport on each frame
        view.render();
}
*********************************************************************
i can find demo on the net, but no tutorial or example file
If my code is not too F***ed, somebody could help me ?

thanks

Reply via email to