00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if defined(_MSC_VER)
00025 #pragma once
00026 #endif
00027
00028 #ifndef PBRT_SHAPES_TRIANGLEMESH_H
00029 #define PBRT_SHAPES_TRIANGLEMESH_H
00030
00031
00032 #include "shape.h"
00033 #include <map>
00034 using std::map;
00035
00036
00037 class TriangleMesh : public Shape {
00038 public:
00039
00040 TriangleMesh(const Transform *o2w, const Transform *w2o, bool ro,
00041 int ntris, int nverts, const int *vptr,
00042 const Point *P, const Normal *N, const Vector *S,
00043 const float *uv, const Reference<Texture<float> > &atex);
00044 ~TriangleMesh();
00045 BBox ObjectBound() const;
00046 BBox WorldBound() const;
00047 bool CanIntersect() const { return false; }
00048 void Refine(vector<Reference<Shape> > &refined) const;
00049 friend class Triangle;
00050 template <typename T> friend class VertexTexture;
00051 protected:
00052
00053 int ntris, nverts;
00054 int *vertexIndex;
00055 Point *p;
00056 Normal *n;
00057 Vector *s;
00058 float *uvs;
00059 Reference<Texture<float> > alphaTexture;
00060 };
00061
00062
00063 class Triangle : public Shape {
00064 public:
00065
00066 Triangle(const Transform *o2w, const Transform *w2o, bool ro,
00067 TriangleMesh *m, int n)
00068 : Shape(o2w, w2o, ro) {
00069 mesh = m;
00070 v = &mesh->vertexIndex[3*n];
00071 PBRT_CREATED_TRIANGLE(this);
00072 }
00073 BBox ObjectBound() const;
00074 BBox WorldBound() const;
00075 bool Intersect(const Ray &ray, float *tHit, float *rayEpsilon,
00076 DifferentialGeometry *dg) const;
00077 bool IntersectP(const Ray &ray) const;
00078 void GetUVs(float uv[3][2]) const {
00079 if (mesh->uvs) {
00080 uv[0][0] = mesh->uvs[2*v[0]];
00081 uv[0][1] = mesh->uvs[2*v[0]+1];
00082 uv[1][0] = mesh->uvs[2*v[1]];
00083 uv[1][1] = mesh->uvs[2*v[1]+1];
00084 uv[2][0] = mesh->uvs[2*v[2]];
00085 uv[2][1] = mesh->uvs[2*v[2]+1];
00086 }
00087 else {
00088 uv[0][0] = 0.; uv[0][1] = 0.;
00089 uv[1][0] = 1.; uv[1][1] = 0.;
00090 uv[2][0] = 1.; uv[2][1] = 1.;
00091 }
00092 }
00093 float Area() const;
00094 virtual void GetShadingGeometry(const Transform &obj2world,
00095 const DifferentialGeometry &dg,
00096 DifferentialGeometry *dgShading) const;
00097 Point Sample(float u1, float u2, Normal *Ns) const;
00098 private:
00099
00100 Reference<TriangleMesh> mesh;
00101 int *v;
00102 };
00103
00104
00105 TriangleMesh *CreateTriangleMeshShape(const Transform *o2w, const Transform *w2o,
00106 bool reverseOrientation, const ParamSet ¶ms,
00107 map<string, Reference<Texture<float> > > *floatTextures = NULL);
00108
00109 #endif // PBRT_SHAPES_TRIANGLEMESH_H