Can’t get textures on model

Software: Away3D 4.x

Qbrain, Member
Posted: 15 August 2011 01:11 PM   Total Posts: 92

Hey There,

Sorry for this absolute noobish question, but I am working on this for 2 days now and I don’t get this stupid thing to work (lol).

I have 3DS max 2011, and created a model in it. (just a simple object, no biped or anything) I gave it a texture. Simple as it is…

Now, when I export it as .3DS , and use the example from the GitHub source. My own model won’t load.

And when I export it as .OBJ, the model loads but there is absolutely no way to get the textures on it…

my question is: How to give the .obj model textures in as3. What to do? Am I exporting the model wrong? (I looked up the export settings in another topic, so my guess is that I’m not doing something right in the AS3 part…)

A simple example from 3dsmax to working SWF would be legendary, but I understand that takes time, so I would already be very happy with only an example code in as3 how to map the textures on my model, or a way to export the .3ds so i can use that filetype..

thanks in advance!

-Q

   

Avatar
Apprentice, Jr. Member
Posted: 15 August 2011 01:18 PM   Total Posts: 45   [ # 1 ]

Have you checked the Away3D example folder (from Git)? LoaderOBJTest.as in particular.

—Apprentice

 

   

Qbrain, Member
Posted: 15 August 2011 01:20 PM   Total Posts: 92   [ # 2 ]

deffinetly. The LoaderOBJTest works. But when I change the obj it loads to my obj, and strip the code to just have a diffuse map, it does load the obj, but won’t put the textures on the model.

Thx for quick awnser btw.

-Q

 

   

Avatar
Apprentice, Jr. Member
Posted: 15 August 2011 01:28 PM   Total Posts: 45   [ # 3 ]

Attached are the obj export options I’m using.
You could also open your .obj file and check if there are sensible texture coordinates. They start with a “vt” tag and 3 numbers behind it of which the third is usually 0 (unless you have a 3D texture I suppose). The first 2 numbers are between 0.0 and 1.0.

—Apprentice

 

   

Qbrain, Member
Posted: 15 August 2011 01:41 PM   Total Posts: 92   [ # 4 ]

Hey Apprentice,

I checked my export settings, but as I expected, they were the same as I already had (except precision which was 4 instead of 5..) I exported my model again but now it won’t even load…

here is the stripped sourcecode I use, probably there is some noob mistake I make which will make me laugh in several months wink 

—-code removed, check post below..—-

 

   

Qbrain, Member
Posted: 15 August 2011 02:05 PM   Total Posts: 92   [ # 5 ]

Ok, I stripped my own source even more to this and now the model is loading in the SWF, so my mistake must be somewhere near the material…

Can anyone tell me what to do to give the hallo.obj the diffuse texture (ground.jpg) ?

public class Test1 extends Sprite
 {
  
private var _view View3D;
  private var 
_loader Loader3D;

  private var 
_light PointLight;

  
[Embed(source="hallo.obj"mimeType="application/octet-stream")]
  
private var OBJData : Class;

  
//[Embed(source="ground.jpg")]
  //private var Albedo : Class;

  //[Embed(source="/../embeds/head/Images/Map-spec.jpg")]
  //private var Specular : Class;

  //[Embed(source="/../embeds/head/Images/Infinite-Level_02_Tangent_NoSmoothUV.jpg")]
  //private var Normal : Class;

  //signature variables
  
private var Signature Sprite;

  private var 
_camController HoverDragController;
  private var 
_count Number 0;
  private var 
_subsurfaceMethod SubsurfaceScatteringDiffuseMethod;
  private var 
_diffuseMethod BasicDiffuseMethod;
  private var 
_material BitmapMaterial;
  private var 
_fresnelMethod FresnelSpecularMethod;
  private var 
_specularMethod BasicSpecularMethod;

  public function 
Test1()
  
{
   _view 
= new View3D();
   
_view.antiAlias 4;
   
this.addChild(_view);

   
_light = new PointLight();
   
_light.15000;
   
_light.15000;
   
_light.color 0xffddbb;
   
_view.scene.addChild(_light);
   
_camController = new HoverDragController(_view.camerastage);
   
addChild(new AwayStats(_view));
   
initMesh();

   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
stage.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
stage.addEventListener(Event.RESIZEonStageResize);
  
}

  
private function onStageResize(event Event) : void
  {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;

   
Signature.stage.stageHeight Signature.height;
  
}

  
private function initMesh() : void
  {
   Loader3D
.enableParser(OBJParser);

   
_loader = new Loader3D();
   
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
_loader.parseData(OBJDatanull, new AssetLoaderContext(false));
   
_loader.= -50;
   
_view.scene.addChild(_loader);

   
//_material = new BitmapMaterial(new Albedo().bitmapData);
   //_subsurfaceMethod = new SubsurfaceScatteringDiffuseMethod(2048, 2);
   //_diffuseMethod = new BasicDiffuseMethod();
   //_fresnelMethod = new FresnelSpecularMethod(true);
   //_specularMethod = new BasicSpecularMethod();
   //_material.normalMap = new Normal().bitmapData;
   //_material.specularMap = new Specular().bitmapData;
   //_material.lights = [ _light ];
   //_material.gloss = 10;
   //_material.specular = 3;
   //_material.ambientColor = 0x303040;
   //_material.ambient = 1;
   //_subsurfaceMethod.scatterColor = 0xff7733; //0xff9966;
   //_subsurfaceMethod.scattering = .05;
   //_subsurfaceMethod.translucency = 4;
   //_material.diffuseMethod = _diffuseMethod;
   //_material.specularMethod = _fresnelMethod;
  
}

  
private function onResourceComplete(event LoaderEvent) : void
  {
   
var mesh Mesh;
   for (var 
int 0_loader.numChildren; ++i{
    mesh 
Mesh(_loader.getChildAt(i));
    
mesh.geometry.scale(10);
    
//mesh.material = _material
   
}
  }


  
private function onEnterFrame(ev Event) : void
  {
   _count 
+= .003;
//   _container.rotationY += .3;

   
_light.Math.sin(_count) * 150000;
   
_light.1000;
   
_light.Math.cos(_count) * 150000;

   
_view.render();
  
}
 }

 

   

Avatar
Choons, Sr. Member
Posted: 15 August 2011 03:22 PM   Total Posts: 281   [ # 6 ]

I noticed a while back that OBJ files I exported from Blender as models I had created but never assigned any materials to contained mtl null lines all through the file that prevented any materials from being assigned. What worked was opening the OBJ file in notepad++ searching for ‘mtl’ and deleting every line that referenced a material.

 

   

mndexp, Newbie
Posted: 15 August 2011 03:59 PM   Total Posts: 10   [ # 7 ]

check your mtl file, you need a relative path, my version of 3dsmax export with absolute path.. i had this probleme before !

 

   

Qbrain, Member
Posted: 15 August 2011 08:55 PM   Total Posts: 92   [ # 8 ]

hey everyone,

Thanks for all the help so far! I am still working on this since even with all the help, the textures simple won’t load. Ofcourse I am doing something totally wrong, but still…

Anyways thanks for the tip about the relative path. I found some stuff though which could be helpfull:

- once I comment the ‘mtllib’ parameter in the .obj file, the object model does load into the swf, once i uncomment it, it won’t load in the swf.

- I tried using a colorMaterial instead of BitmapMaterial, and that worked as well, so the problem deffinetly is in the BitmapMaterial / how to use it..

 

 

   

mndexp, Newbie
Posted: 15 August 2011 09:42 PM   Total Posts: 10   [ # 9 ]

if you are using more than 1 texture it wont load.. ive also had that problem before where u comment the mttlib line

 

   

Qbrain, Member
Posted: 15 August 2011 09:45 PM   Total Posts: 92   [ # 10 ]

nice try wink But i currently use only 1 texture. (need to start simple wink ) I also resized the texture to 512 * 512 to make sure the whole multiple of 2 thing is also no issue… Can’t find what it is, yet…

-Q

 

   

Avatar
Choons, Sr. Member
Posted: 16 August 2011 01:27 AM   Total Posts: 281   [ # 11 ]

remove all mtl lines from your model

 

   

Avatar
Apprentice, Jr. Member
Posted: 16 August 2011 09:12 AM   Total Posts: 45   [ # 12 ]

There should be no mtl lines if the obj export options ‘Export materials’ and ‘Create mat-library’ are unchecked.

Perhaps you got it working by now? If not, have you tried exporting a very simple model (a tetrahedron for example) with a texture? And after exporting the obj in Max3D, have you tried opening the obj file in Max3D again? I reckon it should look be the same. (Export with mtl options enabled)

—Apprentice

 

   

Fab4ce, Jr. Member
Posted: 16 August 2011 09:58 AM   Total Posts: 44   [ # 13 ]

I found out that textures didnĀ“t work for my OBJs because of the filepath. Try put your textures into the same folder as your obj file and export it again. Worked in my case.

 

   

Qbrain, Member
Posted: 17 August 2011 11:38 AM   Total Posts: 92   [ # 14 ]

Hey Everyone,

Thanks for all the tips so far, but I still haven’t been able to fix this.. I know, its noobish, but everyone has to learn it raspberry
Anyway I zipped my source and included it here, so if you are able to help me with this I would be very very glad, and maybe we can use the working source as a (very) beginners example.

some notes:
* I commented the mtllib in the .obj , so that if you check the current .html file, you will see the object without the texture.
* I would love to know what I did wrong, the only thing I need is the friggin’ texture to be on the block. It must be some small stupid thing… after years of programming in php and AS3 this really freaks me out raspberry

thanks in advance!

—link removed—

edit: oops, forgot the HoverDragController.as class…. here is the link to the new zip:

http://www.mijnbestand.nl/Bestand-Q7EOTVTDLGQZ.zip (click the download button)

 

   

Avatar
Apprentice, Jr. Member
Posted: 22 August 2011 10:37 AM   Total Posts: 45   [ # 15 ]

I think I’ve located your problem and it’s pretty weird…
First of all your code seems fine and so does your OBJ.
The problem I noticed was in the following code:

var mesh Mesh;
for (var 
int 0_loader.numChildren; ++i{
 mesh 
Mesh(_loader.getChildAt(i));
 
mesh.geometry.scale(100);
 
mesh.material _material

When I put a break point on the ‘for’-statement I noticed it had 0 children and thus no materials (or scale) were applied to your mesh.

I then tried with an object of my own: a simple 3DS Max plane with length segments = width segments = 5.
Again there were 0 children.
I then tried again with a plane with length segments = width segments = 30 and using the same export settings.
And now it did have 1 child and so the material was applied and it appeared correctly.

It appears to me this is a bug within Away3D (unless I’m missing something). It’s as if with very small objects it could bug and say it has 0 children. Very nasty for you to start with as a beginner.

—Apprentice

 

   
   
‹‹ Context3D error

X

Away3D Forum

Member Login

Username

Password

Remember_me



X