Search code examples
actionscript-3flashflash-cs5away3d

AS#3 changing material Textures


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


Solution

  • 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