30 WShape *shape =
new WShape;
35 shape->setId(ifs.getId().getFirst());
39void WingedEdgeBuilder::visitNodeShape(
NodeShape &ns)
42 _current_frs_material = &ns.frs_material();
47 if (!_current_matrix) {
48 _current_matrix =
new Matrix44r(tn.matrix());
52 _matrices_stack.push_back(_current_matrix);
54 _current_matrix = new_matrix;
59 delete _current_matrix;
61 if (_matrices_stack.empty()) {
62 _current_matrix =
nullptr;
66 _current_matrix = _matrices_stack.back();
67 _matrices_stack.pop_back();
76 const float *vertices = ifs.
vertices();
83 new_vertices =
new float[vsize];
84 new_normals =
new float[nsize];
87 if (_current_matrix) {
88 transformVertices(vertices, vsize, *_current_matrix, new_vertices);
89 transformNormals(
normals, nsize, *_current_matrix, new_normals);
92 memcpy(new_vertices, vertices, vsize *
sizeof(*new_vertices));
93 memcpy(new_normals,
normals, nsize *
sizeof(*new_normals));
98 vector<FrsMaterial> frs_materials;
102 frs_materials.push_back(*(mats[i]));
112 else if (_current_frs_material) {
119 _current_wshape = &shape;
126 const uint *tindices =
nullptr;
131 const uint *mindices =
nullptr;
138 for (
uint index = 0; index < numfaces; index++) {
139 switch (faceStyle[index]) {
141 buildTriangleStrip(new_vertices,
150 numVertexPerFace[index]);
153 buildTriangleFan(new_vertices,
162 numVertexPerFace[index]);
165 buildTriangles(new_vertices,
174 numVertexPerFace[index]);
177 vindices += numVertexPerFace[index];
178 nindices += numVertexPerFace[index];
180 mindices += numVertexPerFace[index];
183 tindices += numVertexPerFace[index];
188 delete[] new_vertices;
189 delete[] new_normals;
203 set<Vec3f> normalsSet;
205 for (vector<WVertex *>::iterator wv = wvertices.begin(), wvend = wvertices.end(); wv != wvend;
208 if ((*wv)->isBoundary()) {
211 if ((*wv)->GetEdges().empty()) {
218 for (; fit != fitend; ++fit) {
221 if (normalsSet.size() != 1) {
225 if (normalsSet.size() != 1) {
226 (*wv)->setSmooth(
false);
231 _winged_edge->addWShape(&shape);
239 for (
uint i = 0; i < vsize; i += 3) {
240 vertex =
new WVertex(
Vec3f(vertices[i], vertices[i + 1], vertices[i + 2]));
241 vertex->
setId(i / 3);
246void WingedEdgeBuilder::buildTriangleStrip(
const float * ,
248 vector<FrsMaterial> & ,
249 const float *texCoords,
251 const uint *vindices,
252 const uint *nindices,
253 const uint *mindices,
254 const uint *tindices,
255 const uint nvertices)
257 uint nDoneVertices = 2;
261 WShape *currentShape = _current_wshape;
262 vector<WVertex *> triangleVertices;
263 vector<Vec3f> triangleNormals;
264 vector<Vec2f> triangleTexCoords;
265 vector<bool> triangleFaceEdgeMarks;
267 while (nDoneVertices < nvertices) {
269 triangleVertices.clear();
271 if (0 == nTriangle % 2) {
272 triangleVertices.push_back(currentShape->
getVertexList()[vindices[nTriangle] / 3]);
273 triangleVertices.push_back(currentShape->
getVertexList()[vindices[nTriangle + 1] / 3]);
274 triangleVertices.push_back(currentShape->
getVertexList()[vindices[nTriangle + 2] / 3]);
276 triangleNormals.emplace_back(
normals[nindices[nTriangle]],
277 normals[nindices[nTriangle] + 1],
278 normals[nindices[nTriangle] + 2]);
279 triangleNormals.emplace_back(
normals[nindices[nTriangle + 1]],
280 normals[nindices[nTriangle + 1] + 1],
281 normals[nindices[nTriangle + 1] + 2]);
282 triangleNormals.emplace_back(
normals[nindices[nTriangle + 2]],
283 normals[nindices[nTriangle + 2] + 1],
284 normals[nindices[nTriangle + 2] + 2]);
287 triangleTexCoords.emplace_back(texCoords[tindices[nTriangle]],
288 texCoords[tindices[nTriangle] + 1]);
289 triangleTexCoords.emplace_back(texCoords[tindices[nTriangle + 1]],
290 texCoords[tindices[nTriangle + 1] + 1]);
291 triangleTexCoords.emplace_back(texCoords[tindices[nTriangle + 2]],
292 texCoords[tindices[nTriangle + 2] + 1]);
296 triangleVertices.push_back(currentShape->
getVertexList()[vindices[nTriangle] / 3]);
297 triangleVertices.push_back(currentShape->
getVertexList()[vindices[nTriangle + 2] / 3]);
298 triangleVertices.push_back(currentShape->
getVertexList()[vindices[nTriangle + 1] / 3]);
300 triangleNormals.emplace_back(
normals[nindices[nTriangle]],
301 normals[nindices[nTriangle] + 1],
302 normals[nindices[nTriangle] + 2]);
303 triangleNormals.emplace_back(
normals[nindices[nTriangle + 2]],
304 normals[nindices[nTriangle + 2] + 1],
305 normals[nindices[nTriangle + 2] + 2]);
306 triangleNormals.emplace_back(
normals[nindices[nTriangle + 1]],
307 normals[nindices[nTriangle + 1] + 1],
308 normals[nindices[nTriangle + 1] + 2]);
311 triangleTexCoords.emplace_back(texCoords[tindices[nTriangle]],
312 texCoords[tindices[nTriangle] + 1]);
313 triangleTexCoords.emplace_back(texCoords[tindices[nTriangle + 2]],
314 texCoords[tindices[nTriangle + 2] + 1]);
315 triangleTexCoords.emplace_back(texCoords[tindices[nTriangle + 1]],
316 texCoords[tindices[nTriangle + 1] + 1]);
321 triangleFaceEdgeMarks.push_back(
323 triangleFaceEdgeMarks.push_back(
325 triangleFaceEdgeMarks.push_back(
328 currentShape->
MakeFace(triangleVertices,
331 triangleFaceEdgeMarks,
332 mindices[nTriangle / 3]);
336 triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0);
343void WingedEdgeBuilder::buildTriangleFan(
const float * ,
345 vector<FrsMaterial> & ,
357void WingedEdgeBuilder::buildTriangles(
const float * ,
359 vector<FrsMaterial> & ,
360 const float *texCoords,
362 const uint *vindices,
363 const uint *nindices,
364 const uint *mindices,
365 const uint *tindices,
366 const uint nvertices)
368 WShape *currentShape = _current_wshape;
372 vector<bool> triangleFaceEdgeMarks;
375 for (
uint i = 0; i < nvertices / 3; i++) {
376 triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i] / 3]);
377 triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 1] / 3]);
378 triangleVertices.push_back(currentShape->getVertexList()[vindices[3 * i + 2] / 3]);
380 triangleNormals.emplace_back(
382 triangleNormals.emplace_back(
normals[nindices[3 * i + 1]],
383 normals[nindices[3 * i + 1] + 1],
384 normals[nindices[3 * i + 1] + 2]);
385 triangleNormals.emplace_back(
normals[nindices[3 * i + 2]],
386 normals[nindices[3 * i + 2] + 1],
387 normals[nindices[3 * i + 2] + 2]);
390 triangleTexCoords.emplace_back(texCoords[tindices[3 * i]], texCoords[tindices[3 * i] + 1]);
391 triangleTexCoords.emplace_back(texCoords[tindices[3 * i + 1]],
392 texCoords[tindices[3 * i + 1] + 1]);
393 triangleTexCoords.emplace_back(texCoords[tindices[3 * i + 2]],
394 texCoords[tindices[3 * i + 2] + 1]);
403 currentShape->MakeFace(
404 triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, mindices[0]);
407 currentShape->MakeFace(
408 triangleVertices, triangleNormals, triangleTexCoords, triangleFaceEdgeMarks, 0);
412void WingedEdgeBuilder::transformVertices(
const float *vertices,
417 const float *
v = vertices;
420 for (
uint i = 0; i < vsize / 3; i++) {
423 for (
uint j = 0; j < 3; j++) {
424 pv[j] = hv[j] / hv[3];
431void WingedEdgeBuilder::transformNormals(
const float *
normals,
439 for (
uint i = 0; i < nsize / 3; i++) {
440 Vec3r hn(n[0], n[1], n[2]);
442 for (
uint j = 0; j < 3; j++) {
Various tools for geometry.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
Class to build a shape node. It contains a Rep, which is the shape geometry.
Class to render a WingedEdge data structure from a polyhedral data structure organized in nodes of a ...
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
static const FaceEdgeMark EDGE_MARK_V2V3
virtual const uint vsize() const
virtual const FrsMaterial *const * frs_materials() const
virtual const float * vertices() const
static const FaceEdgeMark EDGE_MARK_V1V2
virtual const uint * tindices() const
virtual const uchar * faceEdgeMarks() const
virtual const TRIANGLES_STYLE * trianglesStyle() const
virtual const uint * mindices() const
virtual const uint numFaces() const
virtual const float * texCoords() const
virtual const float * normals() const
virtual const uint msize() const
virtual const uint nsize() const
virtual const uint * numVertexPerFaces() const
virtual const uint * nindices() const
virtual const uint * vindices() const
virtual const uint tsize() const
static const FaceEdgeMark FACE_MARK
static const FaceEdgeMark EDGE_MARK_V3V1
const FrsMaterial * frs_material() const
Vec3f & GetVertexNormal(int index)
void setFrsMaterials(const vector< FrsMaterial > &iMaterials)
vector< WVertex * > & getVertexList()
real ComputeMeanEdgeSize() const
void setFrsMaterial(const FrsMaterial &frs_material, uint i)
virtual WFace * MakeFace(vector< WVertex * > &iVertexList, vector< bool > &iFaceEdgeMarksList, uint iMaterialIndex)
void AddVertex(WVertex *iVertex)
vector< WFace * > & GetFaceList()
RenderMonitor * _pRenderMonitor
virtual void visitNodeTransformAfter(NodeTransform &)
virtual bool buildWShape(WShape &shape, IndexedFaceSet &ifs)
virtual void buildWVertices(WShape &shape, const float *vertices, uint vsize)
static float normals[][3]
Vec3r rotateVector(const Matrix44r &mat, const Vec3r &v)
VecMat::Vec3< float > Vec3f
VecMat::SquareMatrix< real, 4 > Matrix44r
VecMat::HVec3< real > HVec3r
VecMat::Vec3< real > Vec3r