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/Translator.h>
14 class RotationBounds :
public Model
17 RotationBounds(
const Model& model)
20 if (!isOfType(TypeName()))
22 setModelProperty(Model::e_application_constructed,
true);
23 m_vertical_rotation_grip = createChild();
24 m_horizontal_rotation_grip = createChild();
25 setModelProperty(Model::e_type, TypeName());
26 setProperty(DesignObject::e_tree_visible,
false);
27 setProperty(DesignObject::e_is_application_owned,
true);
28 setProperty(DesignObject::e_is_application_locked,
true);
29 setModelProperty(Model::e_can_select_children,
true);
30 Effect effect = createChildEffect();
31 effect.setupAsBoundingBox(*
this);
32 setupRotationGrips(m_vertical_rotation_grip, 0);
33 setupRotationGrips(m_horizontal_rotation_grip, 1);
37 m_vertical_rotation_grip = getChild(0);
38 m_horizontal_rotation_grip = getChild(1);
41 void attachTo(
const Model& model)
43 Effect effect = getEffect();
44 if (effect.numberOfTargets() < 2 || effect.getTarget(1) != model)
45 effect.setupAsBoundingBox(*
this, model);
50 void setupRotationGrips(Model& grip, uint01 index)
52 grip.setProperty(DesignObject::e_name,
_t(
"Rotate"));
53 grip.setModelProperty(Model::e_type,
"rotation_grip");
54 grip.setModelProperty(Model::e_can_select_children,
true);
55 Scene scene = grip.getScene();
56 Geometry circle = ShapeConstructors::StaticCircleOutline(scene);
57 Matrix<fltp08> matrix = Matrix<fltp08>::RotationMatrix(Angle<fltp08>(DEGREES, 90.0), IndexTangent(index));
58 grip.setTransform(matrix);
59 grip.setGeometryChild(circle);
60 grip.setProperty(Model::e_bounds_ignored,
true);
63 flag(ParentMatrixFlags::e_ignore_scale_distortion,
true);
64 grip.setParentMatrixFlags(flag);
65 grip.updateVisible(
false);
66 grip.updateModifiedTime();
68 Material material = grip.createChildMaterial();
69 material.setUVMode(UVType::e_KD, Material::UVMode::e_solid_color);
72 case X: material.setUVColor(UVType::e_KD, RGBColor(255, 0,0));
73 case Y: material.setUVColor(UVType::e_KD, RGBColor(0, 255, 0));
74 case Z: material.setUVColor(UVType::e_KD, RGBColor(0, 0, 255));
77 material.setShadingModel(Material::ShadingModel::e_flat);
78 material.setMaterialProperty(Material::e_override_camera_material,
true);
79 material.setMaterialProperty(Material::e_wireframe,
true);
80 material.setMaterialProperty(Material::e_pixel_thickness, 10.0);
81 material.setProperty(Material::e_tree_visible,
false);
82 material.updateModifiedTime();
83 grip.updateModifiedTime();
85 static constexpr const char* TypeName()
87 return "rotation_bounds_model";
89 static Ray<3, fltp08> IndexNormal(uint04 index)
93 case 0:
return Ray<3, fltp08>(1.0, 0.0, 0.0);
94 case 1:
return Ray<3, fltp08>(0.0, 1.0, 0.0);
97 return Ray<3, fltp08>(0, 0, 1);
100 static Ray<3, fltp08> IndexTangent(uint04 index)
104 case 0:
return Ray<3, fltp08>(0.0, 1.0, 0.0);
105 case 1:
return Ray<3, fltp08>(1.0, 0.0, 0.0);
108 return Ray<3, fltp08>(0, 0, 1);
112 Model m_vertical_rotation_grip;
113 Model m_horizontal_rotation_grip;
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:68
#define _t(english_string)
Definition Translator.h:90
@ Y
Definition BaseValues.hpp:165
@ X
Definition BaseValues.hpp:163
@ Z
Definition BaseValues.hpp:167