MCPcopy Create free account
hub / github.com/RenderKit/embree / loadFurBall

Method loadFurBall

tutorials/common/scenegraph/xml_loader.cpp:1312–1547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1310 }
1311
1312 Ref<SceneGraph::Node> XMLLoader::loadFurBall(const Ref<XML>& xml)
1313 {
1314 Ref<SceneGraph::GroupNode> group = new SceneGraph::GroupNode;
1315
1316 float r = (xml->parm("radius") != "") ? xml->parm_float("radius") : 10.0f;
1317 int slices = (xml->parm("slices") != "") ? int(xml->parm_float("slices")) : 60;
1318 int slabs = (xml->parm("slabs") != "") ? int(xml->parm_float("slabs")) : 60;
1319 int nhairs = (xml->parm("nhairs") != "") ? int(xml->parm_float("nhairs")) : 30000;
1320 float hairwidth = (xml->parm("hairwidth") != "") ? int(xml->parm_float("hairwidth")) : (r / 100.0f);
1321 float hairlength = (xml->parm("hairlength") != "") ? int(xml->parm_float("hairlength")) : (r / 10.0f);
1322 RTCGeometryType hairtype = RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE;
1323 bool is_linear = false;
1324 bool is_bezier = false;
1325 bool is_bspline = false;
1326 bool is_hermite = false;
1327 bool is_catmulrom = false;
1328 bool is_normaloriented = false;
1329 std::string phairtype = xml->parm("hairtype");
1330 if (phairtype == "linear_flat") { hairtype = RTC_GEOMETRY_TYPE_FLAT_LINEAR_CURVE; is_linear = true; }
1331 else if (phairtype == "linear_round") { hairtype = RTC_GEOMETRY_TYPE_ROUND_LINEAR_CURVE; is_linear = true; }
1332 else if (phairtype == "bezier_flat") { hairtype = RTC_GEOMETRY_TYPE_FLAT_BEZIER_CURVE; is_bezier = true; }
1333 else if (phairtype == "bezier_round") { hairtype = RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE; is_bezier = true; }
1334 else if (phairtype == "bezier_normaloriented") { hairtype = RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BEZIER_CURVE; is_bezier = true; is_normaloriented = true; }
1335 else if (phairtype == "bspline_flat") { hairtype = RTC_GEOMETRY_TYPE_FLAT_BSPLINE_CURVE; is_bspline = true; }
1336 else if (phairtype == "bspline_round") { hairtype = RTC_GEOMETRY_TYPE_ROUND_BSPLINE_CURVE; is_bspline = true; }
1337 else if (phairtype == "bspline_normaloriented") { hairtype = RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_BSPLINE_CURVE; is_bspline = true; is_normaloriented = true; }
1338 else if (phairtype == "hermite_flat") { hairtype = RTC_GEOMETRY_TYPE_FLAT_HERMITE_CURVE; is_hermite = true; }
1339 else if (phairtype == "hermite_round") { hairtype = RTC_GEOMETRY_TYPE_ROUND_HERMITE_CURVE; is_hermite = true; }
1340 else if (phairtype == "hermite_normaloriented") { hairtype = RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_HERMITE_CURVE; is_hermite = true; is_normaloriented = true; }
1341 else if (phairtype == "catmulrom_flat") { hairtype = RTC_GEOMETRY_TYPE_FLAT_CATMULL_ROM_CURVE; is_catmulrom = true; }
1342 else if (phairtype == "catmulrom_round") { hairtype = RTC_GEOMETRY_TYPE_ROUND_CATMULL_ROM_CURVE; is_catmulrom = true; }
1343 else if (phairtype == "catmulrom_normaloriented") { hairtype = RTC_GEOMETRY_TYPE_NORMAL_ORIENTED_CATMULL_ROM_CURVE; is_catmulrom = true; is_normaloriented = true; }
1344 else { hairtype = RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE; is_bezier = true; }
1345
1346 Ref<SceneGraph::MaterialNode> material = loadMaterial(xml->child("material"));
1347 Ref<SceneGraph::TriangleMeshNode> mesh = new SceneGraph::TriangleMeshNode(material,BBox1f(0,1),0);
1348
1349 {
1350 avector<Vec3fa> data;
1351 data.resize(slices * (slabs - 1) + 2);
1352 data[0] = Vec3fa(0, -r, 0);
1353
1354 float dphi = float(pi) / float(slabs);
1355 float dtheta = float(pi) / float(slices) * 2.0f;
1356 int i = 0;
1357
1358 for (int slab=0; slab<slabs-1; slab++)
1359 {
1360 float phi = dphi * (slab + 1);
1361 for (int slice=0; slice<slices; slice++)
1362 {
1363 float theta = dtheta * slice;
1364 float x = r * sin(phi) * cos(theta);
1365 float z = r * sin(phi) * sin(theta);
1366 float y = r * cos(phi);
1367 data[i] = Vec3fa(x, y, z);
1368 i++;
1369 }

Callers

nothing calls this directly

Calls 15

HairClass · 0.85
fix_bspline_end_pointsFunction · 0.85
parmMethod · 0.80
parm_floatMethod · 0.80
TriangleClass · 0.70
Vec3faClass · 0.50
sinFunction · 0.50
cosFunction · 0.50
acosFunction · 0.50
normalizeFunction · 0.50
crossFunction · 0.50
childMethod · 0.45

Tested by

no test coverage detected