Lights on the roof: applying material to simple polygon and trying to get shadows…

Software: Away3D 4.x

danielmcq, Newbie
Posted: 26 March 2013 09:35 PM   Total Posts: 5

Hi All,

I’m trying to get a handle on how to apply materials to some basic shapes I created: I’ve created a small building with a hip roof. The roof is composed of just two basic triangles and two polygons (just two triangles a piece).

However, when I try to apply a texture material to the roof, it just shows up as grey. Furthermore, when adding lights (per the Basic_Shading example on the Away3D git repo), the roof just acts as one surface. See below screenshots.

My 3D skills are somewhat basic so sorry if this is stupid simple and I’m just missing something.

I’ve included below the methods I’m using to build the roof.

Here’s a createRoof method in my BuildingFactory class…

private function createRoof(bldg:Buildingfacade:String):Mesh
    {

        
if (bldg.ridgeOrientation == Building.NO_RIDGE)
        
{
            
var isTriangle:Boolean true
        }
        
else if (bldg.ridgeOrientation == Building.RIDGE_ORIENTATION_EAST_WEST)
        
{
            isTriangle 
= (facade == Building.FACADE_EAST || facade == Building.FACADE_WEST);
        
}
        
else if (bldg.ridgeOrientation == Building.RIDGE_ORIENTATION_NORTH_SOUTH)
        
{
            isTriangle 
=  (facade == Building.FACADE_NORTH || facade == Building.FACADE_SOUTH);
        
}

        
if (isTriangle)
        
{
            
var vertices:Vector.<Number> = drawRoofTriangle(bldgfacade);
        
}
        
else
        
{
            vertices 
drawRoofPolygon(bldgfacade);
        
}

        
var normals:Vector.<Number> = new Vector.<Number>;
        
normals.push(010);
        
normals.push(010);
        
normals.push(010);

        var 
uvs:Vector.<Number> = new Vector.<Number>;
        
uvs.push(01);
        
uvs.push(01);
        
uvs.push(01);

        var 
indices:Vector.<uint> = Vector.<uint>([012]);

        if (
vertices.length>9)
        
{
            normals
.push(0,1,0);
            
uvs.push(0,1);

            
indices Vector.<uint>([012,  023]);
        
}

        
var subGeom:SubGeometry = new SubGeometry();
        
subGeom.updateVertexData(vertices);
        
subGeom.updateVertexNormalData(normals);
        
subGeom.updateUVData(uvs);
        
subGeom.updateIndexData(indices);

        var 
geom:Geometry = new Geometry();
        
geom.addSubGeometry(subGeom);

        return new 
Mesh(geom_roofMat);

    
}


    
private function drawRoofTriangle(b:Buildingfacade:String):Vector.<Number>
    
{

        
var vertices:Vector.<Number> = new Vector.<Number>;

        if (
facade == Building.FACADE_SOUTH)
        
{
            vertices
.push(0b.h0);
            
vertices.push(b.w/2b.bldgHeightb.ridgeOffset);
            
vertices.push(b.wb.h0);
        
}
        
else if (facade == Building.FACADE_WEST)
        
{
            vertices
.push(0b.h0);
            
vertices.push(b.ridgeOffsetb.bldgHeightb.d/2);
            
vertices.push(0b.hb.d);
        
}
        
else if (facade == Building.FACADE_NORTH)
        
{
            vertices
.push(0b.hb.d);
            
vertices.push(b.widthMidPointb.bldgHeightb.b.ridgeOffset);
            
vertices.push(b.wb.hb.d);
        
}
        
else if (facade == Building.FACADE_EAST)
        
{
            vertices
.push(b.wb.h0);
            
vertices.push(b.b.ridgeOffsetb.bldgHeightb.depthMidPoint);
            
vertices.push(b.wb.hb.d);
        
}

        
return vertices;

    
}


    
private function drawRoofPolygon(b:Buildingfacade:String):Vector.<Number>
    
{

        
var vertices:Vector.<Number> = new Vector.<Number>;


        if (
facade == Building.FACADE_SOUTH)
        
{
            vertices
.push(0b.h0);
            
vertices.push(b.ridgeOffsetb.bldgHeightb.depthMidPoint);
            
vertices.push(b.w-b.ridgeOffsetb.bldgHeightb.depthMidPoint);
            
vertices.push(b.wb.h0);
        
}
        
else if (facade == Building.FACADE_WEST)
        
{
            vertices
.push(0b.h0);
            
vertices.push(0b.hb.d);
            
vertices.push(b.widthMidPointb.bldgHeightb.d-b.ridgeOffset);
            
vertices.push(b.widthMidPointb.bldgHeightb.ridgeOffset);
        
}
        
else if (facade == Building.FACADE_NORTH)
        
{
            vertices
.push(0b.hb.d);
            
vertices.push(b.wb.hb.d);
            
vertices.push(b.w-b.ridgeOffsetb.bldgHeightb.depthMidPoint);
            
vertices.push(b.ridgeOffsetb.bldgHeightb.depthMidPoint);
        
}
        
else if (facade == Building.FACADE_EAST)
        
{
            vertices
.push(b.wb.h0);
            
vertices.push(b.widthMidPointb.bldgHeightb.ridgeOffset);
            
vertices.push(b.widthMidPointb.bldgHeightb.d-b.ridgeOffset);
            
vertices.push(b.wb.hb.d);
        
}


        
return vertices;

    

 


And my lights are created like this in my main class:

_light1 = new DirectionalLight();
        
_light1.direction = new Vector3D(0, -10);
        
_light1.ambient 0.1;
        
_light1.diffuse 0.7;

        
_view.scene.addChild(_light1);

        
_light2 = new DirectionalLight();
        
_light2.direction = new Vector3D(0, -10);
        
_light2.color 0x00FFFF;
        
_light2.ambient 0.1;
        
_light2.diffuse 0.7;

        
_view.scene.addChild(_light2);

        
_staticLightPicker = new StaticLightPicker([_light1_light2]); 

And here’s how I’m creating the material in a different class. The image is 512 x 512. The staticLightPicker is passed into this method as a parameter.

var roofBD:BitmapData Cast.bitmapData(Resources.RoofTiles)
            var 
roofTexture:BitmapTexture = new BitmapTexture(roofBD);
            
_roofMat = new TextureMaterial(roofTexture);
            
_roofMat.lightPicker staticLightPicker;
            
_roofMat.repeat true;
            
_roofMat.mipmap false;
            
_roofMat.bothSides true


Thanks in advance for any tips!

Daniel

 

 

   

danielmcq, Newbie
Posted: 26 March 2013 10:20 PM   Total Posts: 5   [ # 1 ]

I’m realizing this question is probably as basic as they come. At any rate, perhaps it will help somebody else new to 3D and Away3D.

I see now that I was setting my UV vector wrong. Need to learn more about how UV maps bitmaps to triangles (and particularly in my roof example with a bunch of triangles that make a roof shape), but changing the uvs in the code above seemed to help..

uvs.push(00);
uvs.push(200);
 
uvs.push(2020); 

Not sure how to exactly map a 512 x 512 bitmap onto the roof so that it looks good…I’ll post as I figure more out!

The lighting was simply a matter of better understanding basic lighting. Things are looking better (but still a bit off) with:

_light1 = new DirectionalLight();
        
_light1.direction = new Vector3D(-.75, -11);
        
_light1.ambient 0.4;
        
_light1.diffuse 0.7;

        
_view.scene.addChild(_light1);

        
_staticLightPicker = new StaticLightPicker([_light1]); 

 

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X