Hexahedron

Software: Away3D 4.x

Avatar
Zielak, Newbie
Posted: 15 August 2012 05:32 PM   Total Posts: 5

Hi, i’m new to Away3D, but already know some basics.

Right now I’m facing problem. I’d like to have a hexahedron in A3D. I wanted every polygon on sphere to be almost the same size (width and height) and be connected to 4 other polygons (no more no less). It’s not possible with standard sphere, because on top and bottom of sphere each polygon gets narrower.

Is there any simple/convenient way of achieving that sphere? I’m going to try and figure out myself how to create it, though. Using 6 planes and curving them or something…

Hexahedron in attachment.

 

   

Avatar
80prozent, Sr. Member
Posted: 15 August 2012 08:14 PM   Total Posts: 430   [ # 1 ]

hi

why not export from a 3d package ?

this awd file contains some exportet Hexahedrons:

http://www.differentdesign.de/downloads/Hexahedrons.awd

Hope that helps.

 Signature 

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

   

Avatar
Zielak, Newbie
Posted: 17 August 2012 10:11 AM   Total Posts: 5   [ # 2 ]

Ouch, first I gotta learn how to use that file. I’ll look into it later, thanks for help.

One question before I do anything:
I’m making planet on a Cube right now (whoops). Script generates terrain-like texture on one big BitmapData, then cuts needed parts and attaches to each side of cube.
Can i attach textures on a Hexahedron using 6 separeted Bitmaps? Just like on a Cube.

// NOTE: the cube is in fact made of Planes, because I had a hard time getting materials to work with cube mesh.

   

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

Well, since Away3D doesn’t have any hexahedrons built-in, any answer to that question will be kinda pointless. It all depends on how the hexahedron geometry is constructed and what UV mapping it uses. And since you would have to create your own hexahedron, either procedurally or in a 3D tool from which you export it to Away3D, you are in charge of both the construction and the UV mapping.

So the short answer is yes you can, if you build the hexahedron to allow it.

   

Avatar
Zielak, Newbie
Posted: 17 August 2012 01:36 PM   Total Posts: 5   [ # 4 ]

I prefer having it made procedurally.
Allright, I’ll get my hands dirty then.

thanks.

   

Avatar
80prozent, Sr. Member
Posted: 17 August 2012 02:52 PM   Total Posts: 430   [ # 5 ]

hi
if you really wanna try building it procedually, here is how i would try doing it:

1 - start with a cube consising of 12 triangles.

2 - think of the cube as a mesh created with quad-faces (2 triangles = 1 quad).

3 - smooth-subdivide each quad (this is not implemented in away3d yet, so you would have to came up with a solution for this. if you google, you will find examples in other script languages).

4 - recalculate the scale of your object (the smooth subdivide will make your object get smaller)

5 - repeat step 3 and 4 until you have the number of seqments you need.

i would love to have a hexahedron-primitive in away3d, because it would depend on the same math as a smooth-subdivision function for meshes.

 

 Signature 

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

   

Avatar
Zielak, Newbie
Posted: 20 August 2012 08:06 PM   Total Posts: 5   [ # 6 ]

Need help. I’ve made some progress but I get some weird result.

I’m doing it the dumb way (the only one I thought Icould actually code). Class is based on CubePrimitive. Each point is calculated as usual but with addition of pumpIt() function, which pushes the point away from point (0,0,0) at distance of given _size (radius) to get spherical shape. The sphere looks about fine except for one thing:

http://zielak.pl/pub/hexahedron/
Source:
http://zielak.pl/pub/hexahedron/HexahedronGeometry.as
Colors are in no way related with coordinates, it’s just a gradient.

UV mapping is not touched, I wanted to fix the problem at x=0 before I even try to fix mapping. Everything at x=0 just gets z=0 too… Could anyone look into that? I know the code is probably a mess, sorry for that in advance wink My next step will be to get UV mapping

   

Avatar
80prozent, Sr. Member
Posted: 20 August 2012 08:32 PM   Total Posts: 430   [ # 7 ]

hi

looks like you getting somewhere.

cant help you very much, since i only took a brief look on youre code and its way over my head ight now (i am stuck on very similar problems with my code right now).
maybe its some logical eroor with the sinus & co functions your using.
x = 0 becoming z = 0 somehow sounds like something in that direction…

[edit:] very clever approach…didnt think of that

 Signature 

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

   

Avatar
80prozent, Sr. Member
Posted: 20 August 2012 08:50 PM   Total Posts: 430   [ # 8 ]

thought about the approach you came up with:

i do not really understand your code, but here is how i think it would work:

- calculate the radius R (the distance of one of the corner points of the cube to the center of the cube)

- for each point of the cube calculate its normal vn as if it where pointing exactly away from the center of the cube. ( i think this is the nomalized version of the vertex of the point)

- calculate the distance Pdis of each point to the center of the cube.

- move each point along its previous calculated normal vn
- for the movement use the value M = R - Pdis

newVertexPosition.x=oldVertexPosition.x + (vn.x * M)
newVertexPosition.y=oldVertexPosition.y + (vn.y * M)
newVertexPosition.z=oldVertexPosition.z + (vn.z * M)


hope that make sense and helps

 Signature 

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

   

Avatar
80prozent, Sr. Member
Posted: 20 August 2012 10:27 PM   Total Posts: 430   [ # 9 ]

hi

here is a class “Spheremaker.as” that turns any mesh into a sphere.


http://www.differentdesign.de/downloads/SphereMaker.as

jus add this class next to your “main.as”, and include something like this in your “main.as”:

var testCubeGeo:CubeGeometry = new CubeGeometry(100100100101010);
   var 
testMesh:Mesh = new Mesh(testCubeGeo);
   
SphereMaker.makeSphere(testMesh,1)
   
_view.scene.addChild(testMesh); 

you can controll the amount of “smoothing” that is applied via the weight-parameter. (weight=0 mesh stays the same, weight=1 mesh becomes sphere).

uv stays untouched so that should be ok.

normals get merged between the original normal (weight=0) and the “spherical normal” (weight=1).

for me it works fine.

most credits going to you because of the idea.

 Signature 

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

   

Avatar
Zielak, Newbie
Posted: 21 August 2012 05:57 PM   Total Posts: 5   [ # 10 ]

Your code is PERFECT! Thank you for spending some time on investigating it :D

I believe we could even use the SphereMaker class on other primitives, not only a cube! But Cube is all I need right now.

Hint: click AwayStats to re-generate the world.
http://zielak.pl/pub/hexahedron2/

Now I can go on with creating whole galaxies and other stuff.

   

Avatar
80prozent, Sr. Member
Posted: 21 August 2012 06:26 PM   Total Posts: 430   [ # 11 ]

thanks

it came down really easy once i understood your approach with using the distance.

i think this will work fine for most primitives, but as soon as you have faces on top of each other (in regard to the objects center) the resulting sphere gets messy. to handle that we would have to implement some logic that modifies the indexdata to end up with a closed sphere again.

another enhancment could be to allow for a different origin point, other than the objects origin point.
one also could replace the global weight property with a weight-property per vertex and some parameters to control this point-weight by the point-position.
something like:
pointWeight=1;
if pointPosition.x>0: pointWeight=0.5;

this would make a cube into a halfside sphere and a halfside rounded cube.

 

 Signature 

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

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X