MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/PositionBasedDynamics / readTriangleModels

Method readTriangleModels

Utils/SceneLoader.cpp:254–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252}
253
254void SceneLoader::readTriangleModels(const nlohmann::json &j, const std::string &key, const std::string &basePath, SceneData &sceneData)
255{
256 const nlohmann::json &child = j[key];
257
258 for (auto& triModel : child)
259 {
260 std::string geomFileName;
261 if (readValue<std::string>(triModel, "geometryFile", geomFileName))
262 {
263 if (FileSystem::isRelativePath(geomFileName))
264 {
265 geomFileName = basePath + "/" + geomFileName;
266 }
267
268 sceneData.m_triangleModelData.emplace_back(TriangleModelData());
269 TriangleModelData &data = sceneData.m_triangleModelData.back();
270 data.m_modelFile = geomFileName;
271
272 // id
273 data.m_id = 0;
274 readValue(triModel, "id", data.m_id);
275
276 // translation
277 data.m_x.setZero();
278 readVector(triModel, "translation", data.m_x);
279
280 // rotation axis
281 Vector3r axis;
282 axis.setZero();
283 Real angle = 0.0;
284 if (readVector(triModel, "rotationAxis", axis) &&
285 readValue<Real>(triModel, "rotationAngle", angle))
286 {
287 axis.normalize();
288 data.m_q = Quaternionr(AngleAxisr(angle, axis));
289 }
290 else
291 data.m_q = Quaternionr(1.0, 0.0, 0.0, 0.0);
292
293 // scale
294 data.m_scale = Vector3r(1.0, 1.0, 1.0);
295 readVector(triModel, "scale", data.m_scale);
296
297 // static particles
298 unsigned int index = 0;
299 if (triModel.find("staticParticles") != triModel.end())
300 {
301 data.m_staticParticles.reserve((unsigned int)triModel["staticParticles"].size());
302 for (auto& item : triModel["staticParticles"])
303 data.m_staticParticles.push_back(item.get<unsigned int>());
304 }
305
306 // restitution
307 data.m_restitutionCoeff = 0.1;
308 readValue(triModel, "restitution", data.m_restitutionCoeff);
309
310 // friction
311 data.m_frictionCoeff = 0.2;

Callers

nothing calls this directly

Calls 9

TriangleModelDataClass · 0.85
backMethod · 0.80
setZeroMethod · 0.45
normalizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected