PeriDyno 1.2.1
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 this->varUseInstanceTransform()->attach(callbackLoadFile);
19
20 auto callbackTransform = std::make_shared<FCallBackFunc>(std::bind(&TextureMeshLoader::callbackTransform, this));
21 this->varLocation()->attach(callbackTransform);
22 this->varRotation()->attach(callbackTransform);
23 this->varScale()->attach(callbackTransform);
24
25 auto render = this->graphicsPipeline()->createModule<GLPhotorealisticRender>();
26 this->stateTextureMesh()->connect(render->inTextureMesh());
27 this->graphicsPipeline()->pushModule(render);
28
29 this->stateTextureMesh()->promoteOuput();
30 }
31
39
41 {
42
43 }
44
46 {
47 auto fullname = this->varFileName()->getValue();
48 auto root = fullname.path().parent_path();
49
50 auto texMesh = this->stateTextureMesh()->getDataPtr();
51
52 bool success = loadTextureMeshFromObj(texMesh, fullname,this->varUseInstanceTransform()->getValue());
53 if (!success)
54 return;
55
56 mInitialVertex.assign(texMesh->vertices());
57 mInitialNormal.assign(texMesh->normals());
58 mInitialTexCoord.assign(texMesh->texCoords());
59
60 auto& shape = this->stateTextureMesh()->getDataPtr()->shapes();
61 initialShapeCenter.clear();
62 for (size_t i = 0; i < shape.size(); i++)
63 {
64 initialShapeCenter.pushBack(shape[i]->boundingTransform.translation());
65 }
66
68 }
69
71 {
72 auto& shape = this->stateTextureMesh()->getDataPtr()->shapes();
73 auto vertices = this->stateTextureMesh()->getDataPtr()->vertices();
75 cv.assign(vertices);
76
77 if (varUseInstanceTransform()->getValue())
78 {
79 for (size_t i = 0; i < shape.size(); i++)
80 {
81 auto quat = this->computeQuaternion();
82 shape[i]->boundingTransform.translation() = quat.rotate(initialShapeCenter[i]) * this->varScale()->getValue() + this->varLocation()->getValue();
83 shape[i]->boundingTransform.rotation() = quat.toMatrix3x3();
84 shape[i]->boundingTransform.scale() = this->varScale()->getValue();
85 }
86 }
87 else
88 {
89 for (size_t i = 0; i < shape.size(); i++)
90 {
91 shape[i]->boundingTransform.translation() = Vec3f(0);
92 }
93 }
94 }
95
96}
#define IMPLEMENT_CLASS(name)
Definition Object.h:79
bool connect(ModulePort *nPort)
Definition Module.cpp:139
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:311
DArray< Vec3f > mInitialNormal
DArray< Vec3f > mInitialVertex
CArray< Vec3f > initialShapeCenter
DArray< Vec2f > mInitialTexCoord
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
bool loadTextureMeshFromObj(std::shared_ptr< TextureMesh > texMesh, const FilePath &fullname, bool useToCenter)
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
Array< T, DeviceType::CPU > CArray
Definition Array.h:151
vgm::Quat quat
Definition vgMath.h:633