1 | #pragma once
|
---|
2 | #include "Intersectable.hpp"
|
---|
3 | #include "KDTree.hpp"
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | class Radion;
|
---|
7 |
|
---|
8 | #include "FlexVertex.h"
|
---|
9 |
|
---|
10 | /*#ifndef D3DVERTEX__DEFINED
|
---|
11 | struct D3DVERTEXPRM{
|
---|
12 | D3DXVECTOR3 pos;
|
---|
13 | D3DXVECTOR3 normal;
|
---|
14 | D3DXVECTOR2 tex0;
|
---|
15 | D3DXVECTOR2 tex1;
|
---|
16 | D3DXVECTOR3 tangent;
|
---|
17 | D3DXVECTOR3 binormal;
|
---|
18 | };
|
---|
19 | #define D3DVERTEX__DEFINED
|
---|
20 | #endif*/
|
---|
21 |
|
---|
22 | /*!
|
---|
23 | \brief ray-tracable representaion of a mesh
|
---|
24 | TriangleMesh encapsulates a kd-tree containing triangles. It can be constructed using the vertex and index
|
---|
25 | buffers of a mesh. Ray-intersection and random surface sampling are supported.
|
---|
26 | */
|
---|
27 | class TriangleMesh :
|
---|
28 | public Intersectable
|
---|
29 | {
|
---|
30 | // const Material* material;
|
---|
31 | KDTree* meshTree;
|
---|
32 |
|
---|
33 | Vector* meshVertices;
|
---|
34 | Vector* normals;
|
---|
35 | Vector* texCoords;
|
---|
36 | unsigned int nMeshVertices;
|
---|
37 |
|
---|
38 | /*!
|
---|
39 | \brief A triangle with ray-intersection.
|
---|
40 | */
|
---|
41 | class Patch : public Intersectable{
|
---|
42 | public:
|
---|
43 | static Vector* meshVertices; //!< a temporary reference to the owner TriangleMesh's vertex array
|
---|
44 | static Vector* meshNormals; //!< a temporary reference to the owner TriangleMesh's normal array
|
---|
45 | static Vector* meshTexCoords; //!< a temporary reference to the owner TriangleMesh's texcoord array
|
---|
46 | Vector flatNormal; //!< triangle normal |
---|
47 | float hyperPlaneShiftOffset; //!< triangle plane offset |
---|
48 | Vector inverseVertexMatrix[3]; //!< Descartes to barycentric matrix
|
---|
49 | unsigned short vertexIndices[3]; //!< triangle vertex indices
|
---|
50 | bool intersect(const Ray& ray, float& depth, float rayMin, float rayMax);
|
---|
51 | bool intersectBackSide(const Ray& ray, float& depth, float rayMin, float rayMax);
|
---|
52 | void sampleSurface(Radion& radion); //power = brdf
|
---|
53 | } *meshPatches; //!< mesh triangles array
|
---|
54 |
|
---|
55 | unsigned int nMeshPatches; //!< number of mesh triangles
|
---|
56 | unsigned int nAreaTreeNodes; //!< number of nodes in area tree (for selection ~ area)
|
---|
57 | double getPatchArea(unsigned int index);
|
---|
58 |
|
---|
59 | double surfaceArea; //!< total surface
|
---|
60 | double* areaTree; //!< area tree nodes array
|
---|
61 | void buildAreaTree(); //!< build area tree from root
|
---|
62 | double buildAreaTree(unsigned int u); //!< build area tree from given node (recursively)
|
---|
63 | public:
|
---|
64 | float getSurfaceArea(); //!< return total surface area
|
---|
65 | void sampleSurface(Radion& radion); //!< return random surface radion
|
---|
66 | private:
|
---|
67 | void sampleSurface(unsigned int u, double rnd, Radion& radion); //!< return random surface radion from area subtree under node u (recursive)
|
---|
68 | public:
|
---|
69 | TriangleMesh(std::istream& isc, Material** materialTable, int nMaterials);
|
---|
70 | void getTransformedBoundingBox(const Transformation& tf, BoundingBox& bb);
|
---|
71 | bool intersectBackSide(const Ray& ray, float& depth, float rayMin, float rayMax);
|
---|
72 | bool intersect(const Ray& ray, float& depth, float rayMin, float rayMax);
|
---|
73 | ~TriangleMesh(void);
|
---|
74 |
|
---|
75 | //! constructor to build a TriangleMesh from mesh buffers. Vertex format has to be per struct D3DVERTEX.
|
---|
76 | TriangleMesh(Material* material, unsigned short* indexBuffer, unsigned int nFaces,
|
---|
77 | FlexVertexArray& vertexBuffer, unsigned int nVertices);
|
---|
78 |
|
---|
79 | };
|
---|