16 this->varDensity()->setRange(1.0f, 10000.0f);
19 this->varLocation()->attach(callback);
20 this->varScale()->attach(callback);
21 this->varRotation()->attach(callback);
23 auto EnvelopeRender = std::make_shared<GLSurfaceVisualModule>();
24 EnvelopeRender->setColor(
Color(0.8f, 0.8f, 0.8f));
25 this->stateEnvelope()->promoteOuput()->connect(EnvelopeRender->inTriangleSet());
27 EnvelopeRender->setVisible(
false);
30 auto texMeshRender = std::make_shared<GLPhotorealisticInstanceRender>();
31 this->stateTextureMesh()->connect(texMeshRender->inTextureMesh());
32 this->stateInstanceTransform()->connect(texMeshRender->inTransform());
36 auto evenlopeLoader = std::make_shared<FCallBackFunc>(
38 std::string name = this->varEnvelopeName()->getValue().string();
43 if (this->stateEnvelope()->isEmpty())
44 this->stateEnvelope()->allocate();
46 auto envelope = this->stateEnvelope()->getDataPtr();
50 envelope->scale(this->varScale()->getValue());
51 envelope->rotate(this->varRotation()->getValue() *
M_PI / 180);
52 envelope->translate(this->varLocation()->getValue());
58 evenlopeLoader->update();
60 this->varEnvelopeName()->attach(evenlopeLoader);
62 auto textureMeshLoader = std::make_shared<FCallBackFunc>(
64 std::string filepath = this->varTextureMeshName()->getValue().string();
65 if (this->stateTextureMesh()->isEmpty())
66 this->stateTextureMesh()->allocate();
68 std::shared_ptr<TextureMesh> texMesh = this->stateTextureMesh()->getDataPtr();
73 this->varTextureMeshName()->attach(textureMeshLoader);
75 this->varDensity()->setValue(150.0f);
76 this->varBarycenterOffset()->setValue(
Vec3f(0.0f, 0.0f, -0.5f));
98 if (this->stateEnvelope()->isEmpty()) this->stateEnvelope()->allocate();
99 if (this->stateTextureMesh()->isEmpty()) this->stateTextureMesh()->allocate();
103 auto texMesh = this->stateTextureMesh()->constDataPtr();
115 Coord scale = this->varScale()->getValue();
120 Real lx = hi.x - lo.x;
121 Real ly = hi.y - lo.y;
122 Real lz = hi.z - lo.z;
124 Real rho = this->varDensity()->getData();
125 Real mass = rho * lx * ly * lz;
128 Matrix inertia = 1.0f / 12.0f * mass
129 *
Mat3f(ly * ly + lz * lz, 0, 0,
130 0, lx * lx + lz * lz, 0,
131 0, 0, lx * lx + ly * ly);
134 Coord location = this->varLocation()->getValue();
135 Coord rot = this->varRotation()->getValue();
138 auto offset = this->varBarycenterOffset()->getValue();
140 this->stateMass()->setValue(mass);
142 this->stateBarycenter()->setValue(location +
mShapeCenter +
quat.rotate(offset));
143 this->stateVelocity()->setValue(
Vec3f(0));
144 this->stateAngularVelocity()->setValue(
Vec3f(0));
145 this->stateInertia()->setValue(inertia);
146 this->stateQuaternion()->setValue(
quat);
147 this->stateInitialInertia()->setValue(inertia);
158 auto center = this->stateCenter()->getValue();
159 auto quat = this->stateQuaternion()->getValue();
160 auto scale = this->varScale()->getValue();
162 auto offset = this->varBarycenterOffset()->getValue();
164 this->stateBarycenter()->setValue(center +
quat.rotate(offset));
166 auto buoy = this->stateEnvelope()->getDataPtr();
172 auto texMesh = this->stateTextureMesh()->getDataPtr();
175 uint N = texMesh->shapes().size();
178 tms.assign(this->stateInstanceTransform()->constData());
180 for (
uint i = 0; i < tms.size(); i++)
183 for (
uint j = 0; j < list.size(); j++)
185 list[j].translation() = center +
quat.rotate(texMesh->shapes()[i]->boundingTransform.translation() * scale) -
mShapeCenter;
186 list[j].rotation() =
quat.toMatrix3x3();
187 list[j].scale() = scale;
192 auto instantanceTransform = this->stateInstanceTransform()->getDataPtr();
193 instantanceTransform->assign(tms);
204 Coord location = this->varLocation()->getValue();
205 Coord rot = this->varRotation()->getValue();
206 Coord scale = this->varScale()->getValue();
210 auto envelope = this->stateEnvelope()->getDataPtr();
212 envelope->scale(scale);
213 envelope->rotate(
quat);
214 envelope->translate(location);
216 if (this->stateTextureMesh()->isEmpty())
219 auto texMesh = this->stateTextureMesh()->constDataPtr();
221 uint N = texMesh->shapes().size();
226 for (
uint i = 0; i <
N; i++)
228 Transform3f t = texMesh->shapes()[i]->boundingTransform;
230 tms[i].insert(
Transform3f(t.translation() * scale + location,
quat.toMatrix3x3(), t.scale() * scale));
233 if (this->stateInstanceTransform()->isEmpty())
235 this->stateInstanceTransform()->allocate();
238 auto instantanceTransform = this->stateInstanceTransform()->getDataPtr();
239 instantanceTransform->assign(tms);
void updateStates() override