How to put each poly from a SphereGeometry in different submesh?

Software: Away3D 4.x

Ontheronix, Jr. Member
Posted: 03 March 2012 02:09 PM   Total Posts: 37

Hello people,
I’m trying to make a sphere of wich each poly is skinnable with a different texture. So what I’m trying to do is to get each poly of a SphereGeometry in a different SubMesh.
I’m stuck on the vertexNormalData and the UV’s, I don’t see the cohesion of the number of poly’s and the number of vertexNormalData and UV’s.

The code below works, and the AwayStats tool tells me the correct number of poly’s is on the stage, but I don’t see anything. As I understand I need too add the UV’s and normalData also.

Can somebody help me out? Thanks in advance! smile

var indexData:Vector.<uint> = sph.subGeometries[0].indexData;
var 
vertexData:Vector.<Number> = sph.subGeometries[0].vertexData;
var 
UVData:Vector.<Number> = sph.subGeometries[0].UVData;
var 
vertexNormalData:Vector.<Number> = sph.subGeometries[0].vertexNormalData;
  
var 
newIndexData:Vector.<uint> = new Vector.<uint>();
newIndexData.push(0,1,2,3,4,5,6,7,8);
var 
newVertexData:Vector.<Number> = new Vector.<Number>();
var 
newVertexNormalData:Vector.<Number> = new Vector.<Number>();
   
trace (indexData.length " " vertexNormalData.length +" "sph.subGeometries[0].numVertices +" "sph.subGeometries[0].numTriangles +" "+  UVData.length);
       
       
for(var 
i:int 0i  indexData.length 3; ++i){//each i is one triangle
     
var v0index:int indexData[i 3] 3;//3 numbers per vertex, so index 1, starts at index 3 in the vector
     
var v1index:int indexData[i 1] 3;
     var 
v2index:int indexData[i 2] 3;
     var 
v0:Vertex = new Vertex(
      
vertexData[v0index],//x
      
vertexData[v0index+1],//y
      
vertexData[v0index+2]);//z
     
var v1:Vertex = new Vertex(
      
vertexData[v1index],//x
      
vertexData[v1index+1],//y
      
vertexData[v1index+2]);//z
     
var v2:Vertex = new Vertex(
      
vertexData[v2index],//x
      
vertexData[v2index+1],//y
      
vertexData[v2index+2]);//z  
     
     
newVertexData.push(v0.x,v0.y,v0.z,v1.x,v1.y,v1.z,v2.x,v2.y,v2.z);
      
    var 
sub:SubGeometry = new SubGeometry();
    
sub.updateIndexData(newIndexData);
    
sub.updateVertexData(newVertexData);
    
//sub.updateUVData(UVData);
    //sub.updateVertexNormalData(vertexNormalData);
    
msh.geometry.addSubGeometry(sub);
    
    
newVertexData = new Vector.<Number>();
   
}
   View
.scene.addChild(msh); 
   

John Brookes, Moderator
Posted: 03 March 2012 02:50 PM   Total Posts: 732   [ # 1 ]

Wouldn’t the better way be to use just a single sphere and single subgeometry and draw on the bitmap at the UV positions you get from the face indices.
Otherwise you end up with loads of materials being pushed to the gpu.

 

   

Ontheronix, Jr. Member
Posted: 03 March 2012 03:19 PM   Total Posts: 37   [ # 2 ]

Would it be possible to preserve a hard, pixel-thin edge between the poly’s (or faces)? Because with textures, things tend to get stretched or blurred real fast. (I don’t have experience with it, it’s from what I have seen in examples)

Curious about further comments! :D

 

   

John Brookes, Moderator
Posted: 03 March 2012 06:07 PM   Total Posts: 732   [ # 3 ]

Probably not smile

OK an easy hack for what your trying to do.

Get the Explode class (its in tools/commands)

Duplicate it and rename it to something, SuperFlashySubgSplitter
look for
private static const LIMIT:uint =65535;

and change it to 9.

Then…

var dlight:DirectionalLight = new DirectionalLight();
scene.addChild(dlight);
var 
slp:StaticLightPicker = new StaticLightPicker([dlight]);

var 
cm:ColorMaterial = new ColorMaterial(0xff0000);
var 
sgeom:SphereGeometry = new SphereGeometry(1001812);
var 
sphere:Mesh = new Mesh(sgeomcm);

scene.addChild(sphere);

//Explode.apply(sphere);
SuperFlashySubgSplitter.apply(sphere)

for (var 
i:int 0sphere.subMeshes.lengthi++)
{
 
var mat:ColorMaterial = new ColorMaterial(Math.random() * 0xffffff)
 
mat.lightPicker slp;
 
sphere.subMeshes[i].material mat;

 

   

Alex Bogartz, Sr. Member
Posted: 03 March 2012 07:11 PM   Total Posts: 216   [ # 4 ]

I kind of second John’s suggestion of using a single texture file and swapping out portions using copyPixels.

So create a sphere in your 3D program, unwrap, and arrange the faces in a grid formation with equal widths and heights.

In Flash, swap out the textures at various rows and columns, then apply the final texture to the sphere.  You can even do an animated texture this way (although I’m not sure how well it’d perform).

 

   

Ontheronix, Jr. Member
Posted: 03 March 2012 09:09 PM   Total Posts: 37   [ # 5 ]

Thanks for the quick replies!
I will try the hack John is presenting first and see what the performance is, (because I’m not familiar with UV’s and texturing.)

 

   

Alex Bogartz, Sr. Member
Posted: 03 March 2012 09:39 PM   Total Posts: 216   [ # 6 ]

Super easy with Blender and of course, free!

http://www.youtube.com/watch?v=0M2utKKOHZk

 

   

Ontheronix, Jr. Member
Posted: 05 March 2012 01:27 PM   Total Posts: 37   [ # 7 ]

Looking good, but the problem is that I have to get the underlying color of the point on wich has been clicked on MouseEvent.
So I think that will be hard / nearly impossible with 1 texture?

 

   

John Brookes, Moderator
Posted: 05 March 2012 02:46 PM   Total Posts: 732   [ # 8 ]

You should be able to get the UV position of the mouse click.
Used to be
yourmesh.mouseDetails = true
would give you the uv position of the click.
Then you could use that to sample the bitmap.
Not played with the mouse on the new Beta yet so not 100%

Also using mouse details also slows things a bit (or did), but Im guessing its still not as slow as individual shaders.

 

   

Ontheronix, Jr. Member
Posted: 06 March 2012 02:48 PM   Total Posts: 37   [ # 9 ]

Thanks, looks a valiable solution. I’ll try it out today/tommorow.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X