Different textures to a face of single mesh using Away3d 4

Software: Away3D 4.x

Mafiy, Newbie
Posted: 02 August 2012 08:21 PM   Total Posts: 15

Hi,
Could you help me please?

How can I add different textures to a face of single mesh using Away3d 4.0.7?
Example is in the attach.

How can I select a face of mesh by mouse click?

The idea is to make map editor.
PlaneMesh is split on segments e.g. 10x10. Texture or mesh is added to cell by mouse click.

 

   

Richard Olsson, Administrator
Posted: 03 August 2012 08:30 AM   Total Posts: 1192   [ # 1 ]

Different textures for different triangles/faces is not something that Away3D (or a GPU) can support. However, you should probably not try to use different texture objects for different faces anyway, but rather try to use a single texture object and draw your different texture bitmaps into that one texture.

If you are only using planes, you can get the UV position from the mouse event, and use that to figure out what segment the mouse click hit. Use that to calculate where in your texture you need to update the pixels, and just use BitmapData.copyPixels() or draw() to copy pixels from your source texture to the rendered texture.

After you’ve updated the texture bitmap, make sure to invoke invalidateContent() on your texture object.

This entire procedure is a little bit tough on the GPU, but if you only do it on mouse interaction (as opposed to every frame) you should be fine!

   

Mafiy, Newbie
Posted: 03 August 2012 06:20 PM   Total Posts: 15   [ # 2 ]

Can several textures be overlayed to an object by moving them on UV coordinates? One cell has size 64x64 pixels. Maximal texture size is 2048. So, the map can consist of 2048/64=32 cells. But can I overlay one more texture to a deficient part of mesh, in case I have to enlarge the map?

   

Richard Olsson, Administrator
Posted: 04 August 2012 08:14 AM   Total Posts: 1192   [ # 3 ]

I’m not sure I understand the question. Maybe you can elaborate on what you are actually trying to achieve (instead of guessing ways to achieve it) and we can suggest the most suitable approach?

If I am understanding you, you want to have square “cells” of textures that you can plot anywhere on a larger “grid” of such cells. If that’s the case, then you can definitely use UV mapping for that. That is in fact the entire purpose of UV mapping—being able to map a certain part of a large texture to a small part of a mesh.

So, say you have 32x32 cells. That means that in the UV space (if your entire plane is 1x1 UV units, which is what it should be) each cell is 1/32 wide and high.

So, if someone clicks at a point where U=0.5 and V=0.23, you just have to figure out which cell they clicked in, by dividing with 1/32.

cellDim 1/32;
cellX 0.5 cellDim;
cellY 0.23 cellDim

You’ll find that the click was in square 16 (from left) and 7 (from bottom), because cellX is 16 and cellY is 7.36.

So, now you just have to draw your cell texture into the larger texture at the correct position. And that can be calculated by just multiplying the cell width in the texture with the cell index, i.e.:

texX Math.floor(cellX) * 32;
texY Math.floor(cellY) * 32

And then you can just use these values through a Matrix with BitmapData.draw() or through a Point with BitmapData.copyPixels() to draw your cell texture into the grid at the right position.

   

Mafiy, Newbie
Posted: 04 August 2012 06:40 PM   Total Posts: 15   [ # 4 ]

Richard, thank you for helping me.

There is one more unsolved problem.
Away supports maximal texture size 2048x2048.
My cell size should be 64 pixels.
Under these conditions the size of the map can not be more than 32x32 cells.
How can I increase map size to e.g. 50x50 cells without reducing cell size?

   

Richard Olsson, Administrator
Posted: 05 August 2012 08:04 AM   Total Posts: 1192   [ # 5 ]

The 2048x2048 limitation is in Stage3D (and on a lot of hardware) so it’s not something that Away3D just happens to be imposing.

This means that you can’t possibly have textures larger than that. If you want to cover an area that is too big to look good with a 2048x2048 texture, you have to split it up into sub-areas.

So, the simplest here would be to simply divide the plane in half along both axes, creating four planes for each quadrant, and applying different materials (with different textures) to each. That way you can cover an area that is four times bigger (2x2) than your original area, with the same texture resolution.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X