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:Building, facade: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(bldg, facade);
}
else
{
vertices = drawRoofPolygon(bldg, facade);
}
var normals:Vector.<Number> = new Vector.<Number>;
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);
var indices:Vector.<uint> = Vector.<uint>([0, 1, 2]);
if (vertices.length>9)
{
normals.push(0,1,0);
uvs.push(0,1);
indices = Vector.<uint>([0, 1, 2, 0, 2, 3]);
}
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:Building, facade:String):Vector.<Number>
{
var vertices:Vector.<Number> = new Vector.<Number>;
if (facade == Building.FACADE_SOUTH)
{
vertices.push(0, b.h, 0);
vertices.push(b.w/2, b.bldgHeight, b.ridgeOffset);
vertices.push(b.w, b.h, 0);
}
else if (facade == Building.FACADE_WEST)
{
vertices.push(0, b.h, 0);
vertices.push(b.ridgeOffset, b.bldgHeight, b.d/2);
vertices.push(0, b.h, b.d);
}
else if (facade == Building.FACADE_NORTH)
{
vertices.push(0, b.h, b.d);
vertices.push(b.widthMidPoint, b.bldgHeight, b.d - b.ridgeOffset);
vertices.push(b.w, b.h, b.d);
}
else if (facade == Building.FACADE_EAST)
{
vertices.push(b.w, b.h, 0);
vertices.push(b.w - b.ridgeOffset, b.bldgHeight, b.depthMidPoint);
vertices.push(b.w, b.h, b.d);
}
return vertices;
}
private function drawRoofPolygon(b:Building, facade:String):Vector.<Number>
{
var vertices:Vector.<Number> = new Vector.<Number>;
if (facade == Building.FACADE_SOUTH)
{
vertices.push(0, b.h, 0);
vertices.push(b.ridgeOffset, b.bldgHeight, b.depthMidPoint);
vertices.push(b.w-b.ridgeOffset, b.bldgHeight, b.depthMidPoint);
vertices.push(b.w, b.h, 0);
}
else if (facade == Building.FACADE_WEST)
{
vertices.push(0, b.h, 0);
vertices.push(0, b.h, b.d);
vertices.push(b.widthMidPoint, b.bldgHeight, b.d-b.ridgeOffset);
vertices.push(b.widthMidPoint, b.bldgHeight, b.ridgeOffset);
}
else if (facade == Building.FACADE_NORTH)
{
vertices.push(0, b.h, b.d);
vertices.push(b.w, b.h, b.d);
vertices.push(b.w-b.ridgeOffset, b.bldgHeight, b.depthMidPoint);
vertices.push(b.ridgeOffset, b.bldgHeight, b.depthMidPoint);
}
else if (facade == Building.FACADE_EAST)
{
vertices.push(b.w, b.h, 0);
vertices.push(b.widthMidPoint, b.bldgHeight, b.ridgeOffset);
vertices.push(b.widthMidPoint, b.bldgHeight, b.d-b.ridgeOffset);
vertices.push(b.w, b.h, b.d);
}
return vertices;
}
And my lights are created like this in my main class:
_light1 = new DirectionalLight();
_light1.direction = new Vector3D(0, -1, 0);
_light1.ambient = 0.1;
_light1.diffuse = 0.7;
_view.scene.addChild(_light1);
_light2 = new DirectionalLight();
_light2.direction = new Vector3D(0, -1, 0);
_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