YafaRay Core  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
object3d.cc
Go to the documentation of this file.
1 #include <yafraycore/meshtypes.h>
2 #include <cstdlib>
3 
5 
6 float object3d_t::highestObjectIndex = 1.f; //Initially this class shared variable will be 1.f
7 unsigned int object3d_t::objectIndexAuto = 0; //Initially this class shared variable will be 0
8 
9 
10 triangleObject_t::triangleObject_t(int ntris, bool hasUV, bool hasOrco):
11  has_orco(hasOrco), has_uv(hasUV), is_smooth(false), normals_exported(false)
12 {
13  triangles.reserve(ntris);
14  if(hasUV)
15  {
16  uv_offsets.reserve(ntris);
17  }
18 
19  if(hasOrco)
20  {
21  points.reserve(2 * 3 * ntris);
22  }
23  else
24  {
25  points.reserve(3 * ntris);
26  }
27 }
28 
30 {
31  for(unsigned int i=0; i < triangles.size(); ++i)
32  {
33  prims[i] = &(triangles[i]);
34  }
35  return triangles.size();
36 }
37 
39 {
40  triangles.push_back(t);
41  triangles.back().selfIndex = triangles.size() - 1;
42  return &(triangles.back());
43 }
44 
46 {
47  for(auto i=triangles.begin(); i!= triangles.end(); ++i)
48  {
49  i->recNormal();
50  }
51 }
52 
53 // triangleObjectInstance_t Methods
54 
56 {
57  objToWorld = obj2World;
58  mBase = base;
59  has_orco = mBase->has_orco;
60  has_uv = mBase->has_uv;
61  is_smooth = mBase->is_smooth;
63  visible = true;
64  is_base_mesh = false;
65 
66  triangles.reserve(mBase->triangles.size());
67 
68  for(size_t i = 0; i < mBase->triangles.size(); i++)
69  {
70  triangles.push_back(triangleInstance_t(&mBase->triangles[i], this));
71  }
72 }
73 
75 {
76  for(size_t i = 0; i < triangles.size(); i++)
77  {
78  prims[i] = &triangles[i];
79  }
80  return triangles.size();
81 }
82 
84 {
85  // Empty
86 }
87 
88 /*===================
89  meshObject_t methods
90 =====================================*/
91 
92 meshObject_t::meshObject_t(int ntris, bool hasUV, bool hasOrco):
93  has_orco(hasOrco), has_uv(hasUV), has_vcol(false), is_smooth(false), light(nullptr)
94 {
95  //triangles.reserve(ntris);
96  if(hasUV)
97  {
98  uv_offsets.reserve(ntris);
99  }
100 }
101 
103 {
104  int n=0;
105  for(unsigned int i=0; i < triangles.size(); ++i, ++n)
106  {
107  prims[n] = &(triangles[i]);
108  }
109  for(unsigned int i=0; i < s_triangles.size(); ++i, ++n)
110  {
111  prims[n] = &(s_triangles[i]);
112  }
113  return n;
114 }
115 
117 {
118  triangles.push_back(t);
119  return &(triangles.back());
120 }
121 
123 {
124  s_triangles.push_back(t);
125  return &(triangles.back());
126 }
127 
129 {
130  for(auto i=triangles.begin(); i!= triangles.end(); ++i)
131  {
132  i->recNormal();
133  }
134 }
135 
meshObject_t(int ntris, bool hasUV=false, bool hasOrco=false)
Definition: object3d.cc:92
#define __BEGIN_YAFRAY
bool visible
toggle whether geometry is visible or only guidance for other stuff
Definition: object3d.h:90
triangle_t * addTriangle(const triangle_t &t)
Definition: object3d.cc:38
static unsigned int objectIndexAuto
Object Index automatically generated for the object-index-auto render pass.
Definition: object3d.h:93
std::vector< int > uv_offsets
Definition: meshtypes.h:49
int getPrimitives(const primitive_t **prims) const
Definition: object3d.cc:102
primitive_t * addBsTriangle(const bsTriangle_t &t)
Definition: object3d.cc:122
primitive_t * addTriangle(const vTriangle_t &t)
Definition: object3d.cc:116
void finish()
Definition: object3d.cc:128
virtual int getPrimitives(const triangle_t **prims)
Definition: object3d.cc:29
std::vector< bsTriangle_t > s_triangles
Definition: meshtypes.h:46
static float highestObjectIndex
Class shared variable containing the highest object index used for the Normalized Object Index pass...
Definition: object3d.h:96
friend class triangleInstance_t
Definition: meshtypes.h:107
bool normals_exported
Definition: meshtypes.h:102
__BEGIN_YAFRAY const int prims[50]
Definition: scr_halton.h:11
virtual int getPrimitives(const triangle_t **prims)
Definition: object3d.cc:74
std::vector< vTriangle_t > triangles
Definition: meshtypes.h:45
virtual void finish()
Definition: object3d.cc:45
triangleObjectInstance_t(triangleObject_t *base, matrix4x4_t obj2World)
Definition: object3d.cc:55
bool is_base_mesh
Definition: object3d.h:91
virtual void finish()
Definition: object3d.cc:83
#define __END_YAFRAY