Texture upside down on model

Software: Away3D 4.x

Monguron, Newbie
Posted: 11 November 2011 07:08 PM   Total Posts: 27

Hello Guys,

I was using a sample .as script to load an .obj model and to put a texture onto it (or two later).

The model is loaded, the texture is loaded, but as I see, it’s on the model in the wrong direction, as it’s upside down (see attached picture).

Any idea, how to fix it?

Thanks in advance!

 

   

Avatar
80prozent, Sr. Member
Posted: 11 November 2011 08:15 PM   Total Posts: 430   [ # 1 ]

hi
to vertical mirror your uvs, loop trough UVData like this:

for (var i:uint=1i<UVData.length;i+=2){
      UVData[i]
=1-UVData[i];

to mirror horizontal start with i=0 instead of i=1


hope that helps

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Monguron, Newbie
Posted: 12 November 2011 07:37 AM   Total Posts: 27   [ # 2 ]

Thanks for your help, but I’m totally noob, so I don’t know what UVdata means smile

This is the short code. What would you change in it to solve the problem?

Thanks in advance!

package
{
 import away3d
.containers.View3D;
 
import away3d.debug.AwayStats;
 
import away3d.entities.Mesh;
 
import away3d.events.LoaderEvent;
 
import away3d.lights.PointLight;
 
import away3d.loaders.Loader3D;
 
import away3d.loaders.misc.AssetLoaderContext;
 
import away3d.loaders.parsers.OBJParser;
 
import away3d.materials.BitmapMaterial;
 
import away3d.materials.methods.BasicDiffuseMethod;
 
import away3d.materials.methods.BasicSpecularMethod;
 
import away3d.materials.methods.FresnelSpecularMethod;
 
import away3d.materials.methods.SubsurfaceScatteringDiffuseMethod;
 
import away3d.tools.Mirror;

 
import flash.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;
 
import flash.events.KeyboardEvent;

 
[SWF(width="1280"height="720"frameRate="60"backgroundColor="0x000000")]
 
public class adria extends Sprite
 {
  
private var _view View3D;
  private var 
_loader Loader3D;

  private var 
_light PointLight;

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

  
[Embed(source="/../embeds/adria/Adria_A_diff.png")]
  
private var Albedo : Class;

  
[Embed(source="/../embeds/adria/Adria_A_spec.png")]
  
private var Specular : 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 
adria()
  
{
   _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.addEventListener(KeyboardEvent.KEY_UPonKeyUp);
   
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;

  
}

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

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

   
_material = new BitmapMaterial(new Albedo().bitmapData);
   
_subsurfaceMethod = new SubsurfaceScatteringDiffuseMethod(20482);
   
_diffuseMethod = new BasicDiffuseMethod();
   
_fresnelMethod = new FresnelSpecularMethod(true);
   
_specularMethod = new BasicSpecularMethod();

   
_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 _subsurfaceMethod;
   
_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(100);
    
mesh.material _material
   }
  }

  
private function onKeyUp(event KeyboardEvent) : void
  {
   _material
.diffuseMethod _material.diffuseMethod == _diffuseMethod _subsurfaceMethod _diffuseMethod;
//            _material.specularMethod = _material.specularMethod == _specularMethod? _fresnelMethod : _specularMethod;
  
}

  
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
80prozent, Sr. Member
Posted: 12 November 2011 12:25 PM   Total Posts: 430   [ # 3 ]

hi

you would have to change this code:

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

into this:

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

for (var j:uint=0;j<mesh.geometry.subGeometries.length;j++){
for (var k:uint=1;k<mesh.geometry.subGeometries[j].UVData;k+=2){
      mesh
.geometry.subGeometries[j].UVData[k]=1-mesh.geometry.subGeometries[j].UVData[k];
}
mesh
.geometry.subGeometries[j].updateUVData(mesh.geometry.subGeometries[j].UVData)
}

   }
  } 

i didnt test this code, but i think it should work

 

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Monguron, Newbie
Posted: 12 November 2011 03:15 PM   Total Posts: 27   [ # 4 ]

I get this error meassage:

C:\3D\away3d-away3d-examples-broomstick-20a270c\src\adria.as(119): col: 19 Error: Comparison between a value with static type uint and a possibly unrelated type __AS3__.vec:Vector.<Number>.


line 119 is:

for (var k:uint=1;k

 

   

Avatar
80prozent, Sr. Member
Posted: 12 November 2011 04:19 PM   Total Posts: 430   [ # 5 ]

sorry

try this:

for (var k:uint=1;k

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Monguron, Newbie
Posted: 12 November 2011 04:52 PM   Total Posts: 27   [ # 6 ]

Thanks 80prozent! You are a God!

It’s working, so the texture is properly fit to the model.

I only have two problems left:

1) when the light is moving around the model, it generates strange orange surface on the poligons (see picture).

2) I would like to see the model from an upper left corner, and to simply rotate it with the mouse only horizontally (at the moment the sample .as file I use rotates it quite funny)

 

   

Avatar
80prozent, Sr. Member
Posted: 12 November 2011 05:24 PM   Total Posts: 430   [ # 7 ]

for the orange light: i think that is because of the material you are using.

change this:

_material = new BitmapMaterial(new Albedo().bitmapData);
   
_subsurfaceMethod = new SubsurfaceScatteringDiffuseMethod(20482);
   
_diffuseMethod = new BasicDiffuseMethod();
   
_fresnelMethod = new FresnelSpecularMethod(true);
   
_specularMethod = new BasicSpecularMethod();

   
_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 _subsurfaceMethod;
   
_material.specularMethod _fresnelMethod

into this:

_material = new BitmapMaterial(new Albedo().bitmapData);
   
_diffuseMethod = new BasicDiffuseMethod();
   
_specularMethod = new BasicSpecularMethod();

   
_material.specularMap = new Specular().bitmapData;
   
_material.lights [ _light ];
   
_material.gloss 10;
   
_material.specular 3;
   
_material.ambientColor 0x303040;
   
_material.ambient 1;
   
_material.specularMethod _fresnelMethod


for moving your object: right now you are not moving your object, you use the HoverDragController to move the Camera. try using a normal camera instead.
replace:

_camController = new HoverDragController(_view.camerastage); 

with

_view.camera.x=200;
_view.camera.y=200;
_view.camera.z=200;
_view.camera.lookAt(new Vector3D(0,0,0)); 

than you only have to make your mesh rotate on mouse-move.

 

 

 

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Monguron, Newbie
Posted: 12 November 2011 06:10 PM   Total Posts: 27   [ # 8 ]

I cannot express how thankful I am. Its cool, so now the model and the textures are OK.

About the camera:

I received this message after changing the one row to your code:

C:\3D\away3d-away3d-examples-broomstick-20a270c\src\adria.as(63): col: 28 Error: Call to a possibly undefined method Vector3D.
_view.camera.lookAt(new Vector3D(0,0,0));

 

   

Avatar
80prozent, Sr. Member
Posted: 12 November 2011 06:33 PM   Total Posts: 430   [ # 9 ]

thats because you havent imported the Vector3D class.

just add this to the other imports in your sample.as:

import flash.geom.Vector3D

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Monguron, Newbie
Posted: 13 November 2011 10:40 AM   Total Posts: 27   [ # 10 ]

Cheers!

The model now shows propely with the texture (only the 2nd texture is not shown (Adria_A_spec.png).

The other funny thing is, that I cannot position the model into the right place and angle ... and cannot rotate it smile

 

   

Monguron, Newbie
Posted: 13 November 2011 10:41 AM   Total Posts: 27   [ # 11 ]

The actual code is, according to 80prozent’s hints:

package
{
 import away3d
.containers.View3D;
 
import away3d.debug.AwayStats;
 
import away3d.entities.Mesh;
 
import away3d.events.LoaderEvent;
 
import away3d.lights.PointLight;
 
import away3d.loaders.Loader3D;
 
import away3d.loaders.misc.AssetLoaderContext;
 
import away3d.loaders.parsers.OBJParser;
 
import away3d.materials.BitmapMaterial;
 
import away3d.materials.methods.BasicDiffuseMethod;
 
import away3d.materials.methods.BasicSpecularMethod;
 
import away3d.materials.methods.FresnelSpecularMethod;
 
import away3d.materials.methods.SubsurfaceScatteringDiffuseMethod;
 
import away3d.tools.Mirror;
 
 
import flash.geom.Vector3D;  
 
import flash.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;
 
import flash.events.KeyboardEvent;

 
[SWF(width="500"height="400"frameRate="60"backgroundColor="0xd7d7d7")]
 
public class adria extends Sprite
 {
  
private var _view View3D;
  private var 
_loader Loader3D;

  private var 
_light PointLight;

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

  
[Embed(source="/../embeds/adria/Adria_A_diff.png")]
  
private var Albedo : Class;
  
// adria/Adria_A_diff.png

  
[Embed(source="/../embeds/adria/Adria_A_spec.png")]
  
private var Specular : Class;
  
  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 
adria()
  
{
   _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.camera, stage);
   
   //new camera
   
_view.camera.x=800;
   
_view.camera.y=-1000;
   
_view.camera.z=-500;
   
_view.camera.lookAt(new Vector3D(000));  

   
//addChild(new AwayStats(_view));
   
initMesh();

   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
stage.addEventListener(KeyboardEvent.KEY_UPonKeyUp);
   
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;

  
}

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

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

   
_material = new BitmapMaterial(new Albedo().bitmapData);
   
_diffuseMethod = new BasicDiffuseMethod();
   
_specularMethod = new BasicSpecularMethod();

   
_material.specularMap = new Specular().bitmapData;
   
_material.lights [ _light ];
   
_material.gloss 10;
   
_material.specular 3;
   
_material.ambientColor 0x303040;
   
_material.ambient 1;
   
_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(100);
    
mesh.material _material

   
for (var j:uint 0mesh.geometry.subGeometries.lengthj++)
   
{
    
for (var k:uint 1mesh.geometry.subGeometries[j].UVData.length+= 2)
    
{
    mesh
.geometry.subGeometries[j].UVData[k]=1-mesh.geometry.subGeometries[j].UVData[k];
    
}
    mesh
.geometry.subGeometries[j].updateUVData(mesh.geometry.subGeometries[j].UVData)
   
}

   }
  }  

  
private function onKeyUp(event KeyboardEvent) : void
  {
   _material
.diffuseMethod _material.diffuseMethod == _diffuseMethod _subsurfaceMethod _diffuseMethod;
//            _material.specularMethod = _material.specularMethod == _specularMethod? _fresnelMethod : _specularMethod;
  
}

  
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();
  
}
 }

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X