Hi Fabrice,
Thanks for the advice, and I think your suspicions might be right, I
really didn't know what I was doing and half-assumed adding a light
might be enough.
Anyway, I went and did some research, using those tutorials and these
forums. I now have the lighting and shading working.
One problem I came across was that the loader would still read the mtl
file and load the original material over the shaded one, so I would
only get shading on the first few renders. I tried setting
loader.autoLoadTextures = false; but this didn't work, so I had to
move my mtl file out of the folder so that the loader couldn't read
it.
Here's how I did it in the end...
package
{
import away3d.cameras.Camera3D;
import away3d.containers.View3D;
import away3d.core.base.*;
import away3d.core.utils.Cast;
import away3d.events.Loader3DEvent;
import away3d.lights.DirectionalLight3D;
import away3d.loaders.Loader3D;
import away3d.loaders.Obj;
import away3d.materials.PhongBitmapMaterial;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Brush extends MovieClip
{
private var paintBrush:Loader3D;
private var object3d:Object3D;
private var stageRef:Stage;
private var view:View3D;
private var camera:Camera3D;
private var mesh:Mesh;
[Embed(source="3d/textures/finalTexture.jpg")]
private var paintBitmap:Class;
private var material:PhongBitmapMaterial=new PhongBitmapMaterial
(Cast.bitmap(paintBitmap));
public var ax:Number;
public function Brush()
{
init3D();
loadMyObjFile("3d/brush.obj");
}
private function init3D():void
{
camera=new Camera3D({zoom: 1, focus: 200, x: 0, y: 0,
z: -100});
view=new View3D({camera: camera});
addChild(view);
view.x=view.y=250;
this.mouseEnabled=false;
this.mouseChildren=false;
var light:DirectionalLight3D=new DirectionalLight3D();
view.scene.addChild(light);
light.y=500;
light.x=-300;
light.z=-200;
}
private function loadMyObjFile(url:String):void
{
var loader:Loader3D=Obj.load(url, {material: material});
loader.autoLoadTextures=false;
loader.addEventListener(Loader3DEvent.LOAD_SUCCESS,
onLoaderSuccess);
}
private function onLoaderSuccess(e:Loader3DEvent):void
{
object3d=e.loader.handle;
view.scene.addChild(object3d);
view.render();
addEventListener(Event.ENTER_FRAME, renderUpdate);
}
private function renderUpdate(e:Event):void
{
view.render();
}
}
}
Thanks again for your help.
Leon
On Nov 30, 9:28 pm, Fabrice3D <[email protected]> wrote:
> Hi Leon,
> if you model is loaded correctly and displays the maps as you have set
> them in your 3d app
> You can now declare/change/alter the meshes materials by code as you
> wish.
>
> but from your question its not obvious to me where it goes wrong.
> I have the strong feeling you do expect that placing a light will do
> it...
>
> I do suggest you take a look at these excellent
> tutorialshttp://www.flashmagazine.com/Tutorials/detail/away3d_basics_6_-_mater...
>
> http://www.flashmagazine.com/Tutorials/detail/away3d_basics_6_-_bitma...
>
> Due to legacy, many good reasons and the way the engine and Flash have
> evolved: at the moment not all lights
> work with every materials. some do not even react to it, or accept
> just a certain type of light.
> So you need to choose the one that translate the best what you are
> trying to achieved
> and work from there.
>
> of course if I'm wrong, please, add more details on the way you have
> done so far.
>
> Fabrice
>
> On Nov 30, 2009, at 10:11 PM, Leon.nk wrote:
>
> > I've got a .obj file made in Maya with a mtl and a jpeg for the
> > textures. These all import in one go using the obj loader.
>
> > However, I cannot work out how to get lighting and shaing on my
> > textures. I have tried all the light classes and none of them make
> > any difference. Is lighting supported if importing textures this way?
> > Or do I need to import them separately from the obj?
>
> > Thanks
> > Leon
>
>