Hello,
I need to switch textures on a 3D model whenever the model is clicked
on.
I use an XML file with the image url's to point out the location of
the texture. The problem is that I can't access the bitmapData this
way. Or at least I don't know how to.
Embedding the images won't work for me because the images should be
loaded at runtime.
Is there a way to load textures via XML or do I have to embed them? Or
maybe I'm totally on the wrong track and there is another way to
change textures easily?
I exported my 3D model as Stoel1.as from Prefab. I changed the
buildMaterials function inside that file. I use a global variable to
trigger the buildMaterials function from the main.as file and I use
another global.StoelTexnaam variable to give the image url.
Here is the code I use to build my material:
private function buildMaterials():void
{
var obj_0_0_Bitmap:Bitmap;
var className:Class = getDefinitionByName(new this
[global.StoelTexnaam]) as Class;
obj_0_0_Bitmap = new className();
applyMaterialToMesh("obj_0_0",
obj_0_0_Bitmap.bitmapData);
}
Whenever the model is clicked it triggers the buildMaterial function
to build the material with another image url. Right now I get this
error when I run the project:
ReferenceError: Error #1069: Property images/stoel1tex2.jpg not found
on Stoel1 and there is no default value.
at Stoel1/buildMaterials()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.inruntime.utils::Global/http://www.adobe.com/2006/actionscript/
flashproxy::callProperty()
at MethodInfo-1811()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at away3d.core.base::Object3D/dispatchMouseEvent()
at away3d.containers::View3D/bubbleMouseEvent()
at away3d.containers::View3D/fireMouseEvent()
at away3d.containers::View3D/onMouseDown()
Any ideas to solve my problem or to point out a better way to change
the textures?
Thanks in advance,
Jochem