Away4 - BitmapTexture

Software: Away3D 4.x

Tempy111, Sr. Member
Posted: 23 August 2016 10:43 AM   Total Posts: 133

Back after being busy for some time, and i’m now (depending on the project) using FlashDevelop so I can use Away3D 4.

But.. i’m not getting the hang of something.. most guides I can find say i’m doing it right.. but it’s not doing it right so.. confused a bit ^_^; some simple error i’m sure.

I’ve created a plane via the mesh->planeGeometry option. When I give it a ColorMaterial, it displays fine, When I give it a TextureMaterial which is casted from an embedded jpg, it doesn’t display any polygons. Debug stats even go from 2 Polys to 0.

since bugger all has been done so far, here is the code (based on one tutorial) i’m using right now:

package
{
import away3d
.containers.*;
 
import away3d.entities.*;
 
import away3d.materials.*;
 
import away3d.primitives.*;
 
import away3d.utils.*;
 
import away3d.debug.AwayStats;
 
import away3d.textures.*;
 
 
import flash.display.*;
 
import flash.events.*;
 
import flash.geom.Vector3D;

 
[SWF(backgroundColor="#000000"frameRate="60")]
 
 
public class Main extends Sprite
 {
  
//plane texture
  
[Embed(source="Assets/Textures/Grass.jpg")]
  
public static var GrassFloor:Class; 
  
//engine variables
  
private var _view:View3D;
  
  
//scene objects
  
private var _plane:Mesh;
  
  public function 
Main()
  
{
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
//setup the view
   
_view = new View3D();
   
addChild(_view);
   
   
// add away3d debugger 
   
addChild(new AwayStats(_view)); 
   
   
//setup the camera
   
_view.camera.= -200;
   
_view.camera.200;// 500;
   
_view.camera.lookAt(new Vector3D());
   
   
//setup the scene
   //var material:ColorMaterial = new ColorMaterial(0x009EE1);
   
var material:TextureMaterial = new TextureMaterial(Cast.bitmapTexture(GrassFloor));
   
material.bothSides true;
   
   
_plane = new Mesh(new PlaneGeometry(200200), material);
   
_view.scene.addChild(_plane);
   
   
//setup the render loop
   
addEventListener(Event.ENTER_FRAME_onEnterFrame);
   
stage.addEventListener(Event.RESIZEonResize);
   
onResize();
   
   
  
}
  
  
/**
   * render loop
   */
  
private function _onEnterFrame(e:Event):void
  {
   _plane
.rotationY += 1;
   
   
_view.render();
  
}
  
  
/**
   * stage listener for resize events
   */
  
private function onResize(event:Event null):void
  {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
  
}
 }

the Grass bitmap IS in the correct location, checked by embedded it via the embed code option so that’s all fine.

any idea what stupid thing I’ve done wrong?

   

Avatar
Fabrice Closier, Administrator
Posted: 24 August 2016 03:59 PM   Total Posts: 1265   [ # 1 ]

var map:BitmapData = new BitmapData(128,128,0xff000);
var bt:BitmapTexture = new BitmapTexture(map);
var material:TextureMaterial = new TextureMaterial(bt);

if this shows a red plane, you need next to check your map or cast

then adapt your code for the map the “hard” way vs using Cast

[Embed(source=“Assets/Textures/Grass.jpg”)]
private var ImageSRC: Class;

var map:BitmapData = Bitmap(new ImageSRC()).bitmapData;

   

Tempy111, Sr. Member
Posted: 24 August 2016 06:09 PM   Total Posts: 133   [ # 2 ]

Thanks ^_^

var map:BitmapData = new BitmapData(128,128,false,0xff000);

forgot the transparency Boolean ^_^

anyway..

Shows .. green? RGB with only red filled in is green? weird..

still.. for some reason, doesn’t want to load..

extra information if useful, the debug stats say ‘DRIV: DirectX1’.. probably no use..

nothing appears wrong with the image file.. changed from png to jpg and same problems both ways… it’s 100x100 so fairly small but should be fine..

   

Avatar
Fabrice Closier, Administrator
Posted: 25 August 2016 10:00 AM   Total Posts: 1265   [ # 3 ]

typed too fast, misses a zero for red… 0xFF0000

The prob is now explained in this reply: you say your image is 100x100.
and that’s probably where you forgot to say that you got error messages, assuming you compile in debug mode, that tells you that your image must be power of 2. So resize your image to 128, 256, 512, 1024, 2048. You can use size different per side, like 128x256.

   

Tempy111, Sr. Member
Posted: 25 August 2016 03:00 PM   Total Posts: 133   [ # 4 ]

bugger… Thanks!

Why do I always forgot power of 2… major blind spot.. works fine afterwords…

I did say it was something stupid ^_^;

I even started to think something to do with the image size but didn’t follow through on that..

Thanks again.. I’m sure something else will come up at some point.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X