Help with building a shed/house model

Software: Away3D 4.x

Tayyab, Member
Posted: 06 August 2012 09:20 AM   Total Posts: 72

Hi there,

I have created a shed, with the help of cubes and a custom made class Triangle (with the help of away3d Forum).

I wanted to know if i am on the right path. at the moment the texture is all over the place.

the red lines are photoshoped on top of the screenshot to explain how iam making the shed. roof is made of all triangles.

the triangle class iam using:

package
{
 import away3d
.core.base.SubGeometry;
 
import away3d.materials.MaterialBase;
 
import away3d.primitives.PrimitiveBase;
 
 
import flash.geom.Vector3D;
 
 public class 
Triangle extends PrimitiveBase
 {
  
private var _v0:Vector3D;
  private var 
_v1:Vector3D;
  private var 
_v2:Vector3D;
  private var 
_uv0:Vector3D;
  private var 
_uv1:Vector3D;
  private var 
_uv2:Vector3D;
  
  
// Define vertices in a clockwise manner.
  
public function Triangle(v0:Vector3Dv1:Vector3Dv2:Vector3D,
         
uv0:Vector3D nulluv1:Vector3D nulluv2:Vector3D null)
  
{
   super
(/*material*/);
   
   
_v0 v0;
   
_v1 v1;
   
_v2 v2;
   
_uv0 uv0;
   
_uv1 uv1;
   
_uv2 uv2;
  
}
  
  override 
protected function buildGeometry(target:SubGeometry):void
  {
   
var rawVertices:Vector.<Number> = Vector.<Number>([_v0.x_v0.y_v0.z_v1.x_v1.y_v1.z_v2.x_v2.y_v2.z]);
   var 
rawIndices:Vector.<uint> = Vector.<uint>([012]);
   
   var 
d0:Vector3D _v1.subtract(_v0);
   var 
d1:Vector3D _v2.subtract(_v0);
   var 
rawTangents:Vector.<Number> = Vector.<Number>([000]);
   
   var 
normal:Vector3D d0.crossProduct(d1);
   
normal.normalize();
   var 
rawNormals:Vector.<Number> = Vector.<Number>([normal.xnormal.ynormal.znormal.xnormal.ynormal.znormal.xnormal.ynormal.z]);
   
   
target.updateVertexData(rawVertices);
   
target.updateIndexData(rawIndices);
   
target.updateVertexNormalData(rawNormals);
   
target.updateVertexTangentData(rawTangents);
  
}
  
  override 
protected function buildUVs(target:SubGeometry):void
  {
   
var rawUvData:Vector.<Number>
   if(
_uv0 && _uv1 && _uv2)
    
rawUvData Vector.<Number>([_uv0.x_uv0.y_uv1.x_uv1.y_uv2.x_uv2.y]);
   else
    
rawUvData Vector.<Number>([000111]);

   
target.updateUVData(rawUvData);   
  
}
 }  

Also I cannot have material.bothsides to be true on the triangles, it just displays black.

Can anybody help please!

 

   

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

I would strongly recommend that you create your model in a modeling tool instead (or ask a 3D artist to do it.) The ratio of detail and visual quality for effort can’t be compared to what you get if you try to make it procedurally, although the same results can obviously be reached with enough effort.

If you create your model in a modeling package (e.g. the free and open-source program Blender) you can more easily tweak the UV layout of your mesh.

If you really do want to create everything in code, and are not happy with the texture layout, what you need to do is to generate better UVs. For the triangle, what you probably want is for the bottom two vertices to have UV coordinates (0,0) and (1,0) respectively, and the top vertex to have, for example (0.5, 1). But it all depends on whether you want to use tiled textures, for example.

 

   

Tayyab, Member
Posted: 07 August 2012 12:02 AM   Total Posts: 72   [ # 2 ]

the thing is that i have tried using blender, but I just can’t make it to work. :(

plus I am passing in all the parameters to the shed class to make this shed like:

shedWidth, shedLength, wallWidth, wallHeight, shedX, shedY, shedZ, roofHeight, roofTopHeight

would i be able to do that with blender?

the thing u mentioned about the triangle, where would i change the coordinates of the UV?

Also how do i rotate the texture on front triangle? as you can see the front triangle is angled.

Thanx

 

   

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

Yes, you would be able to do that with a pre-created model (e.g. from Blender) by just scaling it, since you have such a simple model.

But if you do want to continue creating it procedurally, you will want to fix the UV mapping by tweaking your UV data. For example, try changing one of the UV pairs to have a 0.5 U coordinate, e.g. this:

rawUvData Vector.<Number>([000.5111]); 

But let me ask, are you creating your entire shed from these triangles, or is it just the triangular area under the roof that uses this?

 

   

Tayyab, Member
Posted: 07 August 2012 08:59 AM   Total Posts: 72   [ # 4 ]

the walls of the shed are cubes
the whole roof is made of these triangles

is there any other way to create the roof ?

 

   

Richard Olsson, Administrator
Posted: 07 August 2012 09:01 AM   Total Posts: 1192   [ # 5 ]

There are plenty of ways, like using a pre-created model, using the extrusions tools in Away3D, manually filling the vertex buffer with suitable numbers, et c. But if what you already have works for you, I think you should probably stick with it for now.

 

   

Tayyab, Member
Posted: 08 August 2012 02:57 AM   Total Posts: 72   [ # 6 ]

Thak you richard,

this code worked for me:

rawUvData Vector.<Number>([00.50.5111]); 

Now i wanted to ask is that if the shedwidth and shedlength are changed, do i need to change the scaleUV of the meshes, that is what iam doing when iam creating this mesh, but when i change the width and length the texture also changes.

is there a way where i could just change the width and length and it does not effect the texture and the texture repeats itself?

in the screen grabs you can see the difference, the first shed has less width and length, and the second one has more. see how the texture gets stretched.

Thank you once again.

 

   

Tayyab, Member
Posted: 08 August 2012 06:12 AM   Total Posts: 72   [ # 7 ]

this happens when i put another image as its texture.

why is it still on angle on the triangle??
it is the same code as previous

and also the top triangles do not even repeat propertly

here is the code for the roof top. I have made a custom Rectangle class which uses the triangle class and displays a rectangle

package  
{
 import away3d
.entities.Mesh;
 
import away3d.materials.MaterialBase;
 
import away3d.tools.commands.Merge;
 
import flash.display.Sprite;
 
import flash.geom.Vector3D;
 
 
/**
  * ...
  * @author Tayyab Azam @ Grey
  */
 
public class Rectangle3D extends Sprite 
 {
  
private var _v0:Vector3D;
  private var 
_v1:Vector3D;
  private var 
_v2:Vector3D;
  private var 
_v3:Vector3D;
  private var 
_uv0:Vector3D;
  private var 
_uv1:Vector3D;
  private var 
_uv2:Vector3D;
  private var 
rectMesh:Mesh;
  private var 
_material:MaterialBase;
  
  public function 
Rectangle3D(material:MaterialBasev0:Vector3Dv1:Vector3Dv2:Vector3Dv3:Vector3Duv0:Vector3D=nulluv1:Vector3D=nulluv2:Vector3D=null)
  
{
   
//super();
   //super(v0, v1, v2, uv0, uv1, uv2);
   
_v0 v0;
   
_v1 v1;
   
_v2 v2;
   
_v3 v3;
   
_uv0 uv0;
   
_uv1 uv1;
   
_uv2 uv2;
   
_material material;
   
  
}
  
public function returnRectMesh():Mesh
  {
   
var tr1:Triangle = new Triangle_v0_v1_v3, new Vector3D(11), new Vector3D(01), new Vector3D(11) );
   var 
tr2:Triangle = new Triangle_v1_v2_v3, new Vector3D(01), new Vector3D(01), new Vector3D(11) );
   
   var 
trMesh1:Mesh = new Mesh(tr1);
   var 
trMesh2:Mesh = new Mesh(tr2);
   
//rectMesh = new Mesh(tr1);
   
var m:Merge = new Merge();
   
m.apply(trMesh1trMesh2);
   
trMesh1.material _material;
   
   return 
trMesh1;
  
}
  
 }

 

   

Richard Olsson, Administrator
Posted: 08 August 2012 08:06 AM   Total Posts: 1192   [ # 8 ]

Let me answer your question with a question: Why would they repeat? Do you scale their UV coordinates anywhere? I can’t find it in your code at least.

Do you understand how UV coordinates work? Do you understand how the vertex, index and UV buffers of a geometry in Away3D work? All of these questions that you are asking are fairly simple trial and error questions that as long as you know how stuff work, you should be able to fix by just tweaking your properties until you get it right (even if you can’t intuitively guess what would be the right values.)

This makes me think that if you are not quite sure what’s going on, instead of us doing trial and error together via the forums, you should take a break from the project and read up on the basics, like how UV mapping works. Does that make sense?

 

   

Tayyab, Member
Posted: 08 August 2012 08:48 AM   Total Posts: 72   [ # 9 ]

The reason Iam repeating the texture is that, my shed can be of any width height and length, if I don’t repeat the texture goes blurry.

When Iam making my shed Iam calling the triangle and rectangle class and then scaling the UVs there…

To be frank I have got little idea how the vertex, index and UV buffers of a geometry in Away3D work.

I have tried and tested a lot with tweaking the rawUVData.

You are correct I will go through the basics..

Do you recommend any where I could get good basic manual , especially for away3D.

 

   

Richard Olsson, Administrator
Posted: 08 August 2012 08:52 AM   Total Posts: 1192   [ # 10 ]

My question wasn’t so much why you are scaling it, but why you are expecting it to scale. I’m looking at your code and can’t find any place where the UVs are scaled. Have you not shown us that code, or could you simply have forgotten to implement it everywhere needed?

For the basics of Stage3D (which powers Away3D, and sets the rules for how Away3D defines geometry data) see this tutorial, which although I haven’t read it looks to cover most of what you need to know (and more):
http://www.adobe.com/devnet/flashplayer/articles/how-stage3d-works.html

For the basics of how UV mapping works, google “UV mapping” and read as much as you feel like, starting with this one:
http://en.wikipedia.org/wiki/UV_mapping

 

   

Tayyab, Member
Posted: 08 August 2012 01:45 PM   Total Posts: 72   [ # 11 ]

here is the function which builds the roof:

protected function buildRoof():ObjectContainer3D
  {
   initFrontBackTriangles
();

   var 
roof:ObjectContainer3D = new ObjectContainer3D();
   var 
triangleMeshes:Vector.<Mesh> = new Vector.<Mesh>;
   var 
merge:Merge = new Merge();
   
   
//var frontTriangle:Triangle = new Triangle( _frontTriangleLeft, _frontTriangleTop, _frontTriangleRight, new Vector3D(-1, -1), new Vector3D(0, 1), new Vector3D(1, 1) );
   
var frontTriangle:Triangle = new Triangle_frontTriangleLeft_frontTriangleTop_frontTriangleRight );
   
frontTriangleMesh = new Mesh(frontTriangle); //trMesh1.showBounds = true;
   
frontTriangleMesh.geometry.scaleUV(44);
   
//frontTriangleMesh.geometry.
   
   //var backTriangle:Triangle = new Triangle( _backTriangleLeft, _backTriangleTop, _backTriangleRight, new Vector3D( -1, -1), new Vector3D(0, 1), new Vector3D(1, 1) );
   
var backTriangle:Triangle = new Triangle_backTriangleLeft_backTriangleTop_backTriangleRight );
   
backTriangleMesh = new Mesh(backTriangle); //trMesh2.showBounds = true; ttrace(trMesh2.position.toString()); 
   
backTriangleMesh.geometry.scaleUV(44);
   
   var 
rect1:Rectangle3D = new Rectangle3D(null_frontTriangleRight_frontTriangleTop_backTriangleTop_flipped_backTriangleRight);
   var 
rectMesh1:Mesh rect1.returnRectMesh();
   
rectMesh1.geometry.scaleUV(8,8);
   var 
rect2:Rectangle3D = new Rectangle3D(null_backTriangleLeft_backTriangleTop_flipped_frontTriangleTop_frontTriangleLeft);
   var 
rectMesh2:Mesh rect2.returnRectMesh();
   
rectMesh2.geometry.scaleUV(88);
   
   
backTriangleMesh.rotationY=180// flip the back triangle
   
backTriangleMesh.position = new Vector3D_shedX _shedWidth0_shedZ newshedZ ); // move the back triangle along the z-axis to back
   
   
roof.addChild(frontTriangleMesh); frontTriangleMesh.name "frontTriangle";
   
roof.addChild(backTriangleMesh); backTriangleMesh.name "backTriangle";
   
   var 
rectMeshes:Vector.<Mesh> = new Vector.<Mesh>;
   
rectMeshes.push(rectMesh1);
   
rectMeshes.push(rectMesh2);
   
roofTopLayer merge.applyToMeshes(Mesh(rectMeshes.shift()), rectMeshes);
   
merge.apply(roofTopLayerrectMesh2);
   
roof.addChild(roofTopLayer); roofTopLayer.name "roofTopLayer";
   
   
roofTopThicknesMesh roofThickness();
   
roof.addChild(roofTopThicknesMesh); roofTopThicknesMesh.name "roofTopThicknesMesh";
   
   return 
roof;
  

and here is the code that creates the walls:

protected function buildShedWalls(width:Numberheight:Number_wallWidth:Number_wallHeight:NumberobjectName:Stringstart:Vector3D=null  ):Mesh
  {
   
   
var container:ObjectContainer3D = new ObjectContainer3D();
   if (
start != null)
   
{
    ttrace
("Doing Nothing.. each wall will have its own positions");
   
}
   
else
   
{
    
//ttrace("Resetting the start values to 0,0,0 so that object container can change the position of shed");
    
start = new Vector3D(0,0,0);
   
}
   wallMeshes 
= new Vector.<Mesh>();
   
//x-axis = near z
   
_wallFront createWallstart, new Vector3Dstart.widthstart._wallHeightstart._wallWidth ) );
   
_wallFront.geometry.scaleUV(44);
   
wallMeshes.push(_wallFront);
   
//z-axis = near x
   
_wallLeft createWall(new Vector3D(start.xstart.ystart._wallWidth ), new Vector3Dstart._wallWidthstart._wallHeightstart.height ) );
   
_wallLeft.geometry.scaleUV(44);
   
wallMeshes.push(_wallLeft);
   
   
//x-axis = far z
   
_wallRight createWall(new Vector3D(start.width _wallWidth,  start.y,     start._wallWidth), 
         new 
Vector3D(start.width,    start._wallHeight,  start.height) );
   
_wallRight.geometry.scaleUV(1616);
   
wallMeshes.push(_wallRight);
   
//z-axis = far x
   
_wallBack createWall( new Vector3D(start.x,    start.y,     start.height), 
         new 
Vector3D(start.width,  start._wallHeight,  start.height _wallWidth) );
   
_wallBack.geometry.scaleUV(1616);
   
wallMeshes.push(_wallBack);
   
   var 
merge:Merge = new Merge(true);
   
// recieving empty mesh
   //var recieverMesh:Mesh = new Mesh();
   
var walls:Mesh merge.applyToMeshes(new Mesh(new Geometry), wallMeshes);
   
   
   return 
walls;
  
}
  
protected function createWall(start:Vector3Dend:Vector3D):Mesh
  {
   
var x:Number end.x-start.x;
   var 
y:Number end.y-start.y;
   var 
z:Number end.z-start.z;
   
   var 
actualX:Number start.x/2;
   var 
actualY:Number start.y/2;
   var 
actualZ:Number start.z/2;
   
   var 
wall:CubeGeometry = new CubeGeometry(xyz);
   
//plane.geometry.scaleUV(10);
   
   
wall.tile6 false;
   
   var 
wallMesh:Mesh = new Mesh(wall);
   
wallMesh.position = new Vector3DactualXactualYactualZ );
   return 
wallMesh;
  

 

   

Tayyab, Member
Posted: 14 August 2012 06:55 AM   Total Posts: 72   [ # 12 ]

Richard, I have done what you told me to do. I do have a better understanding of how UV work. But I am still stuck there. See my previous post to see how i am tweaking the UVs of Triangles.

In one of your earlier post you mentioned, there are other ways to create the roof

There are plenty of ways, like using a pre-created model, using the extrusions tools in Away3D, manually filling the vertex buffer with suitable numbers, et c.

Can you please help me guide to any of the above method which is easy to implement. or an example may be.

I really really appreciate all the help you are giving me and to this forum.

 

 

   

Richard Olsson, Administrator
Posted: 15 August 2012 09:39 AM   Total Posts: 1192   [ # 13 ]

Well, modeling tools (like Blender, 3ds Max, Maya et c) is a whole other topic. You should learn at least the basics of one to gain a better understanding of how 3D CG works, as well as to aid you in creating these types of assets.

You should also try not to use Merge at all, to rule out that there is anything going wrong when you merge your meshes. I’m not saying you should have many separate single-triangle meshes, because you really should try to keep your mesh count down, but you should not be generating them by creating several meshes and then joining them. If you conclude that Merge is the problem, you should just generate the mesh consisting of several triangles yourself instead of relying on Merge.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X