PeriDyno 1.0.0
Loading...
Searching...
No Matches
TextureMeshLoader.cpp
Go to the documentation of this file.
1#include "TextureMeshLoader.h"
2
4
6
7namespace dyno
8{
10
12 {
13 this->stateTextureMesh()->setDataPtr(std::make_shared<TextureMesh>());
14
15 auto callbackLoadFile = std::make_shared<FCallBackFunc>(std::bind(&TextureMeshLoader::callbackLoadFile, this));
16
17 this->varFileName()->attach(callbackLoadFile);
18
19 auto callbackTransform = std::make_shared<FCallBackFunc>(std::bind(&TextureMeshLoader::callbackTransform, this));
20 this->varLocation()->attach(callbackTransform);
21 this->varRotation()->attach(callbackTransform);
22 this->varScale()->attach(callbackTransform);
23
24 auto render = this->graphicsPipeline()->createModule<GLPhotorealisticRender>();
25 this->stateTextureMesh()->connect(render->inTextureMesh());
26 this->graphicsPipeline()->pushModule(render);
27
28 this->stateTextureMesh()->promoteOuput();
29 }
30
37
39 {
40
41 }
42
44 {
45 auto fullname = this->varFileName()->getValue();
46 auto root = fullname.path().parent_path();
47
48 auto texMesh = this->stateTextureMesh()->getDataPtr();
49
50 bool success = loadTextureMeshFromObj(texMesh, fullname);
51 if (!success)
52 return;
53
54 mInitialVertex.assign(texMesh->vertices());
55 mInitialNormal.assign(texMesh->normals());
56 mInitialTexCoord.assign(texMesh->texCoords());
57
58 //reset the transform
59 this->varLocation()->setValue(Vec3f(0));
60 this->varRotation()->setValue(Vec3f(0));
61 this->varScale()->setValue(Vec3f(1));
62 }
63
65 {
66#ifdef CUDA_BACKEND
68#endif
69
70#ifdef VK_BACKEND
71 TriangleSet ps;
72#endif
75
76 // apply transform to vertices
77 {
78 auto t = this->varLocation()->getValue();
79 auto q = this->computeQuaternion();
80 auto s = this->varScale()->getValue();
81
82#ifdef CUDA_BACKEND
83 ts.scale(s);
84 ts.rotate(q);
85 ts.translate(t);
86#endif
87 }
88
89 auto texMesh = this->stateTextureMesh()->getDataPtr();
90
91 texMesh->vertices().assign(ts.getPoints());
92 texMesh->normals().assign(ts.getVertexNormals());
93 texMesh->texCoords().assign(mInitialTexCoord);
94
95 ts.clear();
96 }
97
98}
#define IMPLEMENT_CLASS(name)
Definition Object.h:79
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
DArray< Coord > & getPoints()
Return the array of points.
Definition PointSet.h:70
void scale(const Real s)
void setPoints(const std::vector< Coord > &pos)
void translate(const Coord t)
DArray< Vec3f > mInitialNormal
DArray< Vec3f > mInitialVertex
DArray< Vec2f > mInitialTexCoord
void setNormals(DArray< Coord > &normals)
void clear() override
DArray< Coord > & getVertexNormals()
void rotate(const Coord angle) override
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
bool loadTextureMeshFromObj(std::shared_ptr< TextureMesh > texMesh, const FilePath &fullname)
Vector< float, 3 > Vec3f
Definition Vector3D.h:93