0

I cant seem to find a solution, anyways basically im trying to add a new dynamic texture to a 3D model using Away3d engine with flash

   var myImage:BitmapData = new BitmapData(256, 256, true,0xFFFFFFFF);

   // i cant seem to reference this to my 3D model in the example: Myevent(enter frame):

   myModel.material = new TextureMaterial(new BitmapTexture(myImage))

I have tried different things along the above method, i have checked the away3d docs and cant find something similar for my current situation:

Im using the latest Away3d lib, and flash player 11...all my models works and load with there original embedded materialtTextures, im just trying to change them to a bitmap or texture that i have dynamically created

joshua
  • 676
  • 1
  • 5
  • 19
  • what error are you gettting? – Gone3d Nov 29 '12 at 14:16
  • damm i thought you had an answer been stuck on this for a day , its driving me insane.... im getting no errors, just my material is not changing , iv tried render(); and updating methods.....nothing working i got no idea – joshua Nov 29 '12 at 14:19

2 Answers2

2

Take a look here:

https://github.com/away3d/away3d-tutorials-fp11/blob/master/tutorials/materials/basic_shading/src/Basic_Shading.as

They use Away3D’s Cast utility class to create BitmapTexture objects and they also add a bunch of different texture maps - hopefully this helps

** EDIT --- This Tutorial Does Work **

Added

public bmt:BtiMapTexture;

....
private function initMaterials():void {
    this.bmt = new BitmapTexture(new BitmapData(256,256, true, 0x222277FF));
    sphereMaterial = new TextureMaterial(Cast.bitmapTexture(this.bmt));
    sphereMaterial.specularMap = Cast.bitmapTexture(this.bmt);
    sphereMaterial.lightPicker = lightPicker;
}

And I got a nice blue sphere

Gone3d
  • 1,189
  • 1
  • 8
  • 20
  • nah, this doesnt help at all, that example is just loading in images(jpegs) to add to a mesh or objects, where i dont have any jpegs im just trying to make my model material change to the bitmap that i had created dynamically.... – joshua Nov 29 '12 at 14:26
  • var myImage:BitmapData = new BitmapData(256, 256, true,0xFFFFFFFF); this is my image that i want on to my model – joshua Nov 29 '12 at 14:26
  • Do you need it to be a texture or can you do this with ColorMaterial instead? – Gone3d Nov 29 '12 at 15:09
  • it has to be a texturematerial, i tried using the above, again theres no errors but also nothing is happening... difference is i have an embedded model with a texture on it, then im trying to replace it at runtime – joshua Nov 29 '12 at 23:13
  • I got it to work on the tutorial code with what I posted above - see what you have different see if it fixes it - you probably have to use Cast.bitmapTexture() – Gone3d Nov 30 '12 at 00:34
  • var bitmapData:BitmapData = new BitmapData(256, 256, false,0xFF0000); var texture:BitmapTexture = new BitmapTexture(bitmapData); body.material = new TextureMaterial(Cast.bitmapTexture(texture)); – joshua Nov 30 '12 at 00:48
  • i advertise this on free lancer, for $30-50, i understand what your saying , but im trying to overlay ontop of an existing embedded mesh which already has textures – joshua Nov 30 '12 at 00:50
  • can you post your code - I'll look at it and see if I can get it to work – Gone3d Nov 30 '12 at 00:51
  • give me 10 minutes i will upload it all to my server so you have a good idea what im talking about – joshua Nov 30 '12 at 00:53
  • view here http://www.parele.com/carhdtest.html right click view source to view action script – joshua Nov 30 '12 at 01:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20362/discussion-between-gone3d-and-parele) – Gone3d Nov 30 '12 at 01:42
  • hey again , i tried your suggestions, it still doesnt take effect, iv contacted the admin for sea3d and still no solution, im guessing im gonna give up on this library, and just use the standard away3d lib...dissapointing but theres not enough documentation on this format "sea3d".... – joshua Nov 30 '12 at 10:23
  • Did you ever run my code as I used it? I had no problem getting it to work. – Gone3d Nov 30 '12 at 13:25
  • your example is fine, all the tuts online work fine...but theres no examples on loading models meshes and changing there materials at runtime, i have even made a new complete test file with source code: http://www.parele.com/plane.html – joshua Nov 30 '12 at 14:04
  • Then you should accept this answer and ask a new one specifically for the SEA model. That was the underlying issue and it wasn't until you provided more info that we found it. Good luck. – Gone3d Nov 30 '12 at 14:07
0

My solution is:

var mesh:Mesh = 'the mesh for changing'
for each (var item:SubMesh in mesh.subMeshes) {
item.material = null;
}
mesh.material = new ColorMaterial(0xFF00FF); 
Maxim Firsoff
  • 2,038
  • 22
  • 28