Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1769 - in trunk: Core/Geometry Model/Primitives Model/Readers scenes
- Date: Tue, 9 Oct 2007 17:27:11 -0600 (MDT)
Author: bigler
Date: Tue Oct 9 17:27:10 2007
New Revision: 1769
Modified:
trunk/Core/Geometry/AffineTransform.cc
trunk/Core/Geometry/AffineTransform.h
trunk/Model/Primitives/KenslerShirleyTriangle.cc
trunk/Model/Primitives/WaldTriangle.cc
trunk/Model/Readers/PlyReader.cc
trunk/Model/Readers/PlyReader.h
trunk/scenes/teapotRoom.cc
trunk/scenes/triangleSceneViewer.cc
Log:
Core/Geometry/AffineTransform.cc
Core/Geometry/AffineTransform.h
Added static createIdentity function.
Model/Primitives/KenslerShirleyTriangle.cc
Model/Primitives/WaldTriangle.cc
Fix texture lookups if there are no texture coordinates.
Model/Readers/PlyReader.cc
Model/Readers/PlyReader.h
Take a constant AffineTransform and make a copy of the values not
the pointer.
scenes/teapotRoom.cc
Made everything 10x smaller. Helps with epsilon issues.
Add teapot and bunny (bunny is off in la la land).
Please figure out which kind of Triangle to use (currently uses
Wald).
scenes/triangleSceneViewer.cc
Use the new AffineTransform::createIdentity function.
Modified: trunk/Core/Geometry/AffineTransform.cc
==============================================================================
--- trunk/Core/Geometry/AffineTransform.cc (original)
+++ trunk/Core/Geometry/AffineTransform.cc Tue Oct 9 17:27:10 2007
@@ -184,6 +184,13 @@
mat[i][3] += translation[i];
}
+ AffineTransform AffineTransform::createIdentity()
+ {
+ AffineTransform result;
+ result.initWithIdentity();
+ return result;
+ }
+
AffineTransform AffineTransform::createScale(const Vector& scale)
{
AffineTransform result;
Modified: trunk/Core/Geometry/AffineTransform.h
==============================================================================
--- trunk/Core/Geometry/AffineTransform.h (original)
+++ trunk/Core/Geometry/AffineTransform.h Tue Oct 9 17:27:10 2007
@@ -85,6 +85,7 @@
void translate(const Vector& translation);
// These static methods return a new transform with the indicated
transform
+ static AffineTransform createIdentity();
static AffineTransform createScale(const Vector& scale);
static AffineTransform createRotation(const Vector& from,
const Vector& to);
Modified: trunk/Model/Primitives/KenslerShirleyTriangle.cc
==============================================================================
--- trunk/Model/Primitives/KenslerShirleyTriangle.cc (original)
+++ trunk/Model/Primitives/KenslerShirleyTriangle.cc Tue Oct 9 17:27:10
2007
@@ -52,7 +52,8 @@
{
const int which = myID*3;
- const unsigned int index0 = mesh->texture_indices[which];
+ const unsigned int index0 = mesh->texture_indices.size() ?
+ mesh->texture_indices[which] :
Mesh::kNoTextureIndex;
if (index0 == Mesh::kNoTextureIndex) {
// NOTE(boulos): Assume that if the first index is invalid, they
Modified: trunk/Model/Primitives/WaldTriangle.cc
==============================================================================
--- trunk/Model/Primitives/WaldTriangle.cc (original)
+++ trunk/Model/Primitives/WaldTriangle.cc Tue Oct 9 17:27:10 2007
@@ -142,7 +142,8 @@
{
const int which = myID*3;
- const unsigned int index0 = mesh->texture_indices[which];
+ const unsigned int index0 = mesh->texture_indices.size() ?
+ mesh->texture_indices[which] :
Mesh::kNoTextureIndex;
if (index0 == Mesh::kNoTextureIndex) {
// NOTE(boulos): Assume that if the first index is invalid, they
Modified: trunk/Model/Readers/PlyReader.cc
==============================================================================
--- trunk/Model/Readers/PlyReader.cc (original)
+++ trunk/Model/Readers/PlyReader.cc Tue Oct 9 17:27:10 2007
@@ -31,10 +31,10 @@
unsigned int vertices_start = 0;
VertexData vertexData;
-AffineTransform *t;
+static AffineTransform t;
static void addVertex(Mesh *mesh) {
- vertexData.point = t->multiply_point(vertexData.point);
+ vertexData.point = t.multiply_point(vertexData.point);
mesh->vertices.push_back(vertexData.point);
}
@@ -138,7 +138,7 @@
}
bool
-Manta::readPlyFile(const string fileName, AffineTransform &_t,
+Manta::readPlyFile(const string fileName, const AffineTransform &_t,
Mesh *mesh, Material *m,
MeshTriangle::TriangleType triangleType) {
long nVertices;
@@ -146,7 +146,7 @@
unsigned int vertex_indices_start = mesh->vertex_indices.size();
vertices_start = mesh->vertices.size();
- t = &_t;
+ t = _t;
p_ply ply = ply_open(fileName.c_str(), NULL);
if (!ply)
Modified: trunk/Model/Readers/PlyReader.h
==============================================================================
--- trunk/Model/Readers/PlyReader.h (original)
+++ trunk/Model/Readers/PlyReader.h Tue Oct 9 17:27:10 2007
@@ -17,7 +17,7 @@
class Material;
class Group;
- extern "C" bool readPlyFile(const string fileName, AffineTransform &t,
+ extern "C" bool readPlyFile(const string fileName, const AffineTransform
&t,
Mesh *mesh, Material *m=0,
MeshTriangle::TriangleType triangleType =
MeshTriangle::KENSLER_SHIRLEY_TRI);
}
Modified: trunk/scenes/teapotRoom.cc
==============================================================================
--- trunk/scenes/teapotRoom.cc (original)
+++ trunk/scenes/teapotRoom.cc Tue Oct 9 17:27:10 2007
@@ -3,6 +3,9 @@
#include <Model/Groups/ObjGroup.h>
#include <Model/Groups/DynBVH.h>
+#include <Model/Readers/PlyReader.h>
+
+#include <Model/Instances/Instance.h>
#include <Model/Materials/Checker.h>
#include <Model/Materials/CopyTextureMaterial.h>
@@ -11,11 +14,12 @@
#include <Model/Materials/MetalMaterial.h>
#include <Model/Materials/Phong.h>
-#include <Model/Textures/Constant.h>
-#include <Model/Textures/MarbleTexture.h>
-
#include <Model/Primitives/Cube.h>
#include <Model/Primitives/Parallelogram.h>
+#include <Model/Primitives/Sphere.h>
+
+#include <Model/Textures/Constant.h>
+#include <Model/Textures/MarbleTexture.h>
#include <Model/Backgrounds/ConstantBackground.h>
#include <Model/Lights/PointLight.h>
@@ -31,41 +35,14 @@
#define Rect(material, center, dir1, dir2) \
Parallelogram(material, (center) - (dir1) - (dir2), (dir1)*2, (dir2)*2)
-class TeapotObjGroup: public ObjGroup {
-public:
- TeapotObjGroup( const char* filename ):
- ObjGroup(filename)
- {
- }
-
-protected:
- virtual void create_materials( Glm::GLMmodel *model )
- {
- // Here we are going to override the materials with our stuff
-
-
//////////////////////////////////////////////////////////////////////////
- // Path to the model for loading textures.
- string model_path = model->pathname;
-
- size_t pos = model_path.rfind( '/' );
- if (pos != string::npos) {
- model_path = model_path.substr( 0, pos+1 );
- }
-
- material_array = new Material *[ model->nummaterials ];
- material_array_size = model->nummaterials;
-
- // Just override the materials
- for (unsigned int i=0;i<model->nummaterials;++i) {
- material_array[i] = new Lambertian(new
Constant<Color>(Color(RGB(1,0,1))));
- }
- }
-};
+static string bunny_file("/Users/bigler/manta/data/ply/bun_zipper_res4.ply");
+static string teapot_file("/Users/bigler/manta/data/obj/goodteapot.obj");
void usage()
{
cerr << "Valid options for scene:\n";
- cerr << " -model - Required. The file to load.\n";
+ cerr << " -teapot - Path to teapot obj file. Defaults to:
"<<teapot_file<<"\n";
+ cerr << " -bunny - Path to bunny ply file. Defaults to:
"<<bunny_file<<"\n";
}
void argumentError(int i, const vector<string>& args)
@@ -74,27 +51,95 @@
throw IllegalArgument("scene teapotRoom", i, args);
}
+static Material* glass= new Dielectric(1.5, 1.0, Color(RGB(.80, .93 ,
.87)).Pow(0.2));//, 0.001);
void addTable(Group* group)
{
// Top
- Material* glass= new Dielectric(1.5, 1.0, Color(RGB(.80, .93 ,
.87)).Pow(.02));//, 0.001);
- Object* box=new Cube(glass, Vector(-500,-100,-10), Vector(300,300,0) );
+ Object* box=new Cube(glass, Vector(-50.0,-10.0,-1.0), Vector(30.0,30.0,0)
);
group->add(box);
// Legs
Material* legs = new MetalMaterial( Color::white() * 0.01 );
- group->add(new Cube(legs, Vector(-480,-80,-200), Vector(-450,-50,-10) ) );
- group->add(new Cube(legs, Vector(-480,250,-200), Vector(-450,280,-10) ) );
- group->add(new Cube(legs, Vector(250,-80,-200), Vector(280,-50,-10) ) );
- group->add(new Cube(legs, Vector(250,250,-200), Vector(280,280,-10) ) );
+ group->add(new Cube(legs, Vector(-48.0,-8.0,-20.0),
Vector(-45.0,-5.0,-1.0) ) );
+ group->add(new Cube(legs, Vector(-48.0,25.0,-20.0),
Vector(-45.0,28.0,-1.0) ) );
+ group->add(new Cube(legs, Vector(25.0,-8.0,-20.0), Vector(28.0,-5.0,-1.0)
) );
+ group->add(new Cube(legs, Vector(25.0,25.0,-20.0), Vector(28.0,28.0,-1.0)
) );
// Crossbars
- group->add(new Cube(legs, Vector(-450,-70,-40), Vector(250,-60,-10) ) );
- group->add(new Cube(legs, Vector(-450,260,-40), Vector(250,280,-10) ) );
- group->add(new Cube(legs, Vector(-470,-70,-40), Vector(-460,250,-10) ) );
- group->add(new Cube(legs, Vector(260,-70,-40), Vector(270,250,-10) ) );
+ group->add(new Cube(legs, Vector(-45.0,-7.0,-4.0), Vector(25.0,-6.0,-1.0)
) );
+ group->add(new Cube(legs, Vector(-45.0,26.0,-4.0), Vector(25.0,28.0,-1.0)
) );
+ group->add(new Cube(legs, Vector(-47.0,-7.0,-4.0), Vector(-46.0,25.0,-1.0)
) );
+ group->add(new Cube(legs, Vector(26.0,-7.0,-4.0), Vector(27.0,25.0,-1.0) )
);
+}
+
+Object* packMesh(const string& mesh_name, const AffineTransform& transform,
+ Material* material)
+{
+ Mesh* mesh = 0;
+ if(mesh_name != "") {
+ // load mesh
+ if(!strncmp(mesh_name.c_str()+mesh_name.length()-4, ".ply", 4)) {
+ mesh = new Mesh();
+ if (readPlyFile(mesh_name, transform, mesh, material,
MeshTriangle::WALD_TRI)) {
+ DynBVH* mesh_bvh = new DynBVH();
+ mesh_bvh->setGroup(mesh);
+ return mesh_bvh;
+ } else {
+ cerr << "Warning: could not load mesh: " << mesh_name << endl;;
+ return 0;
+ }
+ } else if(!strncmp(mesh_name.c_str()+mesh_name.length()-4, ".obj", 4)) {
+ mesh = new ObjGroup(mesh_name.c_str(), material,
MeshTriangle::WALD_TRI);
+ DynBVH* mesh_bvh = new DynBVH();
+ mesh_bvh->setGroup(mesh);
+ Instance* instance = new Instance(mesh_bvh, transform);
+ return instance;
+ } else {
+ cerr << "Warning: could not load mesh: " << mesh_name << endl;
+ return 0;
+ }
+ }
+ return 0;
}
+void addTableTopStuff(Group* group)
+{
+ // Glass sphere
+ Object* sphere = new Sphere(glass, Vector(20.0, 20.0, 4.0), 4.0);
+ group->add(sphere);
+
+ // Bunny
+ if (1)
+ {
+ Material* bunny_material = new Phong(Color(RGB(0.63, 0.51, 0.5)),
+ Color::white()*0.3,
+ 400);
+ AffineTransform bunnyT;
+ bunnyT.translate(Vector(-30.0, 15.0, 0));
+ // bunnyT.translate(Vector(0,0,0.01));
+ bunnyT.scale(Vector(95.0, 95.0, 95.0));
+ Object* bunny = packMesh(bunny_file, bunnyT, bunny_material);
+ if (bunny)
+ group->add(bunny);
+ }
+
+ // Teapot
+ if (1)
+ {
+ AffineTransform teapotT;
+ teapotT.initWithIdentity();
+ teapotT.translate(Vector(2.0,1.575,0.0));
+ teapotT.rotate(Vector(0,1,0), M_PI_4);
+ teapotT.rotate(Vector(1,0,0), M_PI_2);
+ teapotT.scale(Vector(1,1,1)*3);
+ Material* teapot_material = new MetalMaterial(Color::white()*0.8);
+ Object* teapot = packMesh(teapot_file, teapotT, teapot_material);
+ if (teapot)
+ group->add(teapot);
+ }
+
+ // SIGGRAPH proceedings
+}
void addFloor(Group* group)
{
/* RTRT CrowMarble(double scale,
@@ -170,9 +215,9 @@
// checkered_floor = new CopyTextureMaterial(new
Constant<Color>(Color::white()));
Object* floor=new Rect(checkered_floor,
- Vector(0,0,-200),
- Vector(1600,0,0),
- Vector(0,1600,0));
+ Vector(0,0,-20.0),
+ Vector(160.0,0,0),
+ Vector(0,160.0,0));
group->add(floor);
}
@@ -180,23 +225,23 @@
{
Material* white = new Lambertian(Color::white() * 0.8);
group->add( // room10
- new Rect(white, Vector(1600,0,600), Vector(0,0,800),
Vector(0,1600,0))
+ new Rect(white, Vector(160.0,0,60.0), Vector(0,0,80.0),
Vector(0,160.0,0))
);
group->add( // room00
- new Rect(white, Vector(-1600,0,600), Vector(0,0,800),
Vector(0,1600,0))
+ new Rect(white, Vector(-160.0,0,60.0), Vector(0,0,80.0),
Vector(0,160.0,0))
);
group->add( // room11
- new Rect(white, Vector(0,1600,600), Vector(0,0,800),
Vector(1600, 0,0))
+ new Rect(white, Vector(0,160.0,60.0), Vector(0,0,80.0),
Vector(160.0, 0,0))
);
group->add( // room01
- new Rect(white, Vector(0,-1600,600), Vector(0,0,800),
Vector(1600, 0,0))
+ new Rect(white, Vector(0,-160.0,60.0), Vector(0,0,80.0),
Vector(160.0, 0,0))
);
// group->add( // ceiling (roomtb)
-// new Rect(white, Vector(0,0,1400), Vector(0,1600,0),
Vector(1600, 0,0))
+// new Rect(white, Vector(0,0,140.0), Vector(0,160.0,0),
Vector(160.0, 0,0))
// );
}
@@ -216,6 +261,7 @@
Group* group = new Group();
addTable(group);
+ addTableTopStuff(group);
addFloor(group);
addWalls(group);
@@ -236,8 +282,8 @@
scene->setLights(lights);
// Add a default camera
- Vector eye(700,1390,300);
- Vector lookat(0,0,150);
+ Vector eye(70.0,139.0,30.0);
+ Vector lookat(0,0,15.0);
Real fov=45;
scene->addBookmark("default view", eye, lookat, up, fov, fov);
Modified: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- trunk/scenes/triangleSceneViewer.cc (original)
+++ trunk/scenes/triangleSceneViewer.cc Tue Oct 9 17:27:10 2007
@@ -135,9 +135,7 @@
if (!strncmp(modelName.c_str()+modelName.length()-4, ".ply", 4)) {
frame = new Mesh;
- AffineTransform t;
- t.initWithScale(Vector(1, 1, 1));
- if (!readPlyFile(modelName, t, frame, NULL, triangleType))
+ if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame,
0, triangleType))
printf("error loading or reading ply file: %s\n", modelName.c_str());
}
else if (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
- [Manta] r1769 - in trunk: Core/Geometry Model/Primitives Model/Readers scenes, bigler, 10/09/2007
Archive powered by MHonArc 2.6.16.