RANDOMLY GENERATED MESHES HELP!!

Software: Away3D 4.x

YOYO, Newbie
Posted: 09 May 2013 10:35 PM   Total Posts: 3

HEY EVERYONE,

I’ve been trying to figure out how to create randomly generated meshes in Away3d. I’ve been programming action-script for a while but this one is over my head. How would i go about generating a random spherical object or any random mesh for that matter?

I’d imagine that you could cycle through an array of vertices assigning random values to their XYZ values and then somehow string all of these vertices through a loop that generates a singular mesh.

ANY HELP WOULD BE GREATLY APPRECIATED

   

YOYO, Newbie
Posted: 11 May 2013 01:50 PM   Total Posts: 3   [ # 1 ]

Hey guys, still waiting for a response… If this is not possible please tell me .so I try and find another means to accomplish my project .

   

Avatar
Fabrice Closier, Administrator
Posted: 11 May 2013 03:40 PM   Total Posts: 1265   [ # 2 ]

Of course it’s possible. You should look at the MeshHelper class or any primitive to see how you declare a geometry and it’s subGeometries.
You should get familiar with the api first using the provided tutorials and read the old posts/replies on this forum.

To get you started to build any mesh:
new Mesh(Geometry, material);

Geometry is builded from subGeometries
you can add it to the geometry by simply doing geometry.addSubgeometry(mySubgeom);

The subgeometries, must hold at least 1 buffer of vertices, one of uvs and one for indices. Normals and tangent can be calculated by the engine if you set the dedicated auto property for both to true.

An index buffer is multiple of 3. Each entry points to the x value in vertice indices once multiply by 3. Multiplied by 2 will point to the u value in the uv buffer.

With this information you should already be able to generate your first triangle.
Again, get familar with the Away synthax and principles first using the provided examples.

   

YOYO, Newbie
Posted: 11 May 2013 09:29 PM   Total Posts: 3   [ # 3 ]

HEY thanks for the reply

So I’m still trying to figure this out. I followed your instructions and look through the forums and came up with this.

package
{
 import away3d
.containers.View3D;
 
import away3d.core.base.Geometry;
 
import away3d.core.base.SubGeometry;
 
import away3d.core.base.data.Vertex;
 
import away3d.entities.Mesh;
 
import away3d.materials.ColorMaterial;
 
import away3d.primitives.CubeGeometry;
 
import away3d.primitives.LineSegment;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.primitives.SphereGeometry;
 
import away3d.controllers.HoverController;
 
import flash.display.Sprite;
 
import flash.events.Event;
 
import flash.geom.Vector3D;
 
 
[swf(width=640height=480frameRate=60)]
 
public class away3d extends Sprite
 {
  
private var view:View3D;
  private var 
cube:Mesh;
  private var 
whatever:LineSegment;
  private var 
hc:HoverController;
  
  public function 
away3d()
  
{
   setupScene
();
  
}
  
  
private function setupScene():void
  {
   view 
= new View3D();
   
addChild(view);
   
   
   var 
colorMaterial ColorMaterial = new ColorMaterial(0xff0000);
   
//colorMaterial.smooth = false;
   
colorMaterial.bothSides true;
   
//colorMaterial.diffuseMethod.alphaThreshold = .3;
   //colorMaterial.ambient = .2;
   
   
   
var vertexes:Vector.<Number> = new Vector.<Number>;
   
vertexes.push(4,0,-40);
   
vertexes.push(100,0,-40);
   
vertexes.push(100,0,-300);
   
vertexes.push(250,500,-350);
   
vertexes.push(300,40,-350);
   
vertexes.push(40,300,-300);
   
   
   var 
normals:Vector.<Number> = new Vector.<Number>;
   
normals.push(0,1,0);
   
normals.push(0,1,0);
   
normals.push(0,1,0);
   
normals.push(0,1,0);
   
normals.push(0,1,0);
   
normals.push(0,1,0);
   
   
   var 
uvs:Vector.<Number> = new Vector.<Number>;
   
uvs.push(0,1);
   
uvs.push(0,1);
   
uvs.push(0,1);
   
uvs.push(0,1);
   
uvs.push(0,1);
   
uvs.push(0,1);
   
   var 
indices:Vector.<uint> = Vector.<uint>([0,1,2,3,4,5]);
   
   var 
subGeometry:SubGeometry = new SubGeometry();
   
subGeometry.updateVertexData(vertexes);
   
subGeometry.updateVertexNormalData(normals);
   
subGeometry.updateUVData(uvs);
   
subGeometry.updateIndexData(indices);
   
/*subGeometry.autoDeriveVertexTangents  = true;
   subGeometry.autoDeriveVertexNormals = true;*/
   
   
var geometry:Geometry = new Geometry();
   
geometry.addSubGeometry(subGeometry);
   
   
   var 
mesh:Mesh = new Mesh(geometrycolorMaterial);
   
   
view.scene.addChild(mesh);
   
   
view.camera.= -2000;
   
view.camera.300;
   
view.camera.lookAt(new Vector3D());
   
   
hc = new HoverController(view.cameranull15010200);
   
   
addEventListener(Event.ENTER_FRAMEloop);
  
}
  
  
protected function loop(event:Event):void
  {
   hc
.panAngle mouseX 320;
   
hc.tiltAngle mouseY 240;
   
   
//mesh.rotationY++;
   
view.render();
  
}
 }

Although I dont know why its giving me a flat 2d shape in 3d space, instead of a 3d geometry in 3d space? Am i going about this totally wrong.

how do i create a 3d geometry?

am I suppose to add more subgeometries to the singular geometry?
PLEASE ASSIST

ALL THE BEST

 

   

Avatar
80prozent, Sr. Member
Posted: 12 May 2013 01:02 PM   Total Posts: 430   [ # 4 ]

Hi

Although I dont know why its giving me a flat 2d shape in 3d space, instead of a 3d geometry in 3d space? Am i going about this totally wrong.

how do i create a 3d geometry?

am I suppose to add more subgeometries to the singular geometry?

I think your on the right way. All you need to understand is this:

A Mesh in 3D is displayed by a number of triangle-shapes (faces).

You are only creating 2 Faces, so maybe you will see more 3D. if you create some more. (for each new triangle you need to add 3 pointIndices to the IndexBuffer. You might need to create new Points (Verticles) in the other Buffers too, but you can reuse allready existing points, too).

It simply might be the position of the camera and the mesh/faces that makes you believe the shape is not 3d.

try changing the camera position like this:

view.camera.= -2000;
   
view.camera.2000;
   
view.camera.300;
   
view.camera.lookAt(new Vector3D()); 

or try to change the rotation / position of the mesh:

mesh.x=100;
    
mesh.rotateX=20

The use of Subgeometrys is this:

Each face of a mesh, can only have one material assigned to it.
If you want to different faces of you mesh have different materials assigned, you would need to split you mesh into subMeshes, so you have one Submesh for every material you want to use.

So for your situation, you do not need to add more SubGeometrys.

If you want to use Textures on the Mesh later, you will need to define the correct uvs for the Meshes, but that is something that is quite messy when building meshes the procedual way. if you want to display the Meshes only by using color, not texture, you will not run into the problem with the uvs.

You should not define the normals, as you do it, because they do not seam to be correct, and the SubGeometry can autoderive them in a better way.
i think you just need to get rid of this line:

subGeometry.updateVertexNormalData(normals); 

The Subgeometry should autoDerive the normals now.


Hope that helps

 

 

 

 

 

 

 Signature 

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

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X