| 23 | { |
| 24 | |
| 25 | void thicken(const PatchNodePtr& sourcePatch, float thickness, bool createSeams, int axis) |
| 26 | { |
| 27 | if (axis < 0 || axis > 3) throw cmd::ExecutionFailure(fmt::format(_("Invalid axis value: {0}"), string::to_string(axis))); |
| 28 | |
| 29 | // Get a shortcut to the patchcreator |
| 30 | auto& patchCreator = GlobalPatchModule(); |
| 31 | |
| 32 | // Create a new patch node |
| 33 | scene::INodePtr node(patchCreator.createPatch(patch::PatchDefType::Def2)); |
| 34 | |
| 35 | scene::INodePtr parent = sourcePatch->getParent(); |
| 36 | assert(parent != NULL); |
| 37 | |
| 38 | // Insert the node into the same parent as the existing patch |
| 39 | parent->addChildNode(node); |
| 40 | |
| 41 | // Retrieve the contained patch from the node |
| 42 | Patch* targetPatch = Node_getPatch(node); |
| 43 | |
| 44 | // Create the opposite patch with the given thickness = distance |
| 45 | targetPatch->createThickenedOpposite(sourcePatch->getPatchInternal(), thickness, axis); |
| 46 | |
| 47 | // Select the newly created patch |
| 48 | Node_setSelected(node, true); |
| 49 | |
| 50 | if (createSeams && thickness > 0.0f) |
| 51 | { |
| 52 | // Allocate four new patches |
| 53 | scene::INodePtr nodes[4] = { |
| 54 | patchCreator.createPatch(patch::PatchDefType::Def2), |
| 55 | patchCreator.createPatch(patch::PatchDefType::Def2), |
| 56 | patchCreator.createPatch(patch::PatchDefType::Def2), |
| 57 | patchCreator.createPatch(patch::PatchDefType::Def2) |
| 58 | }; |
| 59 | |
| 60 | // Now create the four walls |
| 61 | for (int i = 0; i < 4; i++) |
| 62 | { |
| 63 | // Retrieve the contained patch from the node |
| 64 | Patch* wallPatch = Node_getPatch(nodes[i]); |
| 65 | |
| 66 | // Create the wall patch by passing i as wallIndex |
| 67 | wallPatch->createThickenedWall(sourcePatch->getPatchInternal(), *targetPatch, i); |
| 68 | |
| 69 | if (!wallPatch->isDegenerate()) |
| 70 | { |
| 71 | // Insert each node into the same parent as the existing patch |
| 72 | // It's vital to do this first, otherwise these patches won't have valid shaders |
| 73 | parent->addChildNode(nodes[i]); |
| 74 | |
| 75 | // Now the shader is realised, apply natural scale |
| 76 | wallPatch->scaleTextureNaturally(); |
| 77 | |
| 78 | // Now select the newly created patch |
| 79 | Node_setSelected(nodes[i], true); |
| 80 | } |
| 81 | else |
| 82 | { |
no test coverage detected