2#include <NDEVR/Model.h>
3#include <NDEVR/ShapeConstructors.h>
4#include <NDEVR/Effect.h>
5#include <NDEVR/Geometry.h>
6#include <NDEVR/Material.h>
7#include <NDEVR/Scene.h>
8#include <NDEVR/Translator.h>
21 class RotationBounds :
public Model
34 RotationBounds(
const Model& model)
37 if (!is<NDPN::type>(TypeName()))
39 setChildApplicationConstructed();
40 m_vertical_rotation_grip = createChild();
41 m_horizontal_rotation_grip = createChild();
42 set<NDPN::type>(TypeName());
43 set<NDPO::tree_visible>(
false);
44 set<NDPO::is_application_owned>(
true);
45 set<NDPO::application_locked>(
true);
46 set<NDPN::can_select_children>(
true);
47 Effect effect = createChildEffect();
48 effect.setupAsBoundingBox(*
this);
49 setupRotationGrips(m_vertical_rotation_grip, 0);
50 setupRotationGrips(m_horizontal_rotation_grip, 1);
54 m_vertical_rotation_grip = getChild(0);
55 m_horizontal_rotation_grip = getChild(1);
68 void attachTo(
const Model& model)
70 Effect effect = getEffect();
71 if (effect.targetCount() < 2 || effect.getTarget(1) != model)
72 effect.setupAsBoundingBox(*
this, model);
91 void setupRotationGrips(Model& grip, uint01 index)
93 grip.set<NDPOC::name>(_t(
"Rotate"));
94 grip.set<NDPN::type>(
"rotation_grip");
95 grip.set<NDPN::can_select_children>(
true);
96 Scene scene(grip.getScene());
97 Geometry circle = ShapeConstructors::StaticCircleOutline(scene);
98 Matrix<fltp08> matrix = Matrix<fltp08>::RotationMatrix(Angle<fltp08>(DEGREES, 90.0), IndexTangent(index));
99 grip.set<NDPO::transform>(matrix);
100 grip.setGeometryChild(circle);
101 grip.set<NDPO::bounds_ignored>(
true);
104 flag(ParentMatrixFlags::e_ignore_scale_distortion,
true);
105 grip.setParentMatrixFlags(flag);
106 grip.update<NDPO::spacial_visible>(
false);
107 grip.updateModifiedTime();
109 Material material = grip.createChildMaterial();
110 material.setUVMode(UVType::e_KD, Material::UVMode::e_solid_color);
113 case X: material.setUVColor(UVType::e_KD, RGBColor(255, 0, 0));
break;
114 case Y: material.setUVColor(UVType::e_KD, RGBColor(0, 255, 0));
break;
115 case Z: material.setUVColor(UVType::e_KD, RGBColor(0, 0, 255));
break;
118 material.set<NDPM::shading_model>(Material::ShadingModel::e_flat);
119 material.set<NDPM::override_camera_material>(
true);
120 material.set<NDPM::wireframe>(
true);
121 material.set<NDPM::pixel_thickness>(10.0);
122 material.set<NDPO::tree_visible>(
false);
123 material.updateModifiedTime();
124 grip.updateModifiedTime();
131 static constexpr StringView TypeName()
133 return "rotation_bounds_model";
142 static Ray<3, fltp08> IndexNormal(uint04 index)
146 case 0:
return Ray<3, fltp08>(1.0, 0.0, 0.0);
147 case 1:
return Ray<3, fltp08>(0.0, 1.0, 0.0);
149 lib_assert(
false,
"Bad index normal");
150 return Ray<3, fltp08>(0, 0, 1);
164 static Ray<3, fltp08> IndexTangent(uint04 index)
168 case 0:
return Ray<3, fltp08>(0.0, 1.0, 0.0);
169 case 1:
return Ray<3, fltp08>(1.0, 0.0, 0.0);
171 lib_assert(
false,
"Bad index normal");
172 return Ray<3, fltp08>(0, 0, 1);
176 Model m_vertical_rotation_grip;
177 Model m_horizontal_rotation_grip;
A core class that represents a node on model hierarchy.
The primary namespace for the NDEVR SDK.
@ BitFlag
Per-vertex bit flags (selected, hidden, etc.).