-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Grid Floor for better orientation
- Loading branch information
Showing
2 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/usr/bin/env python | ||
|
||
import Ogre | ||
|
||
GRID_MATERIAL = "MeshViewer/VertexColour" | ||
|
||
class GridFloor: | ||
def __init__(self, scene, resource_group): | ||
self.scn_mgr = scene | ||
self.resource_group = resource_group | ||
self.plane_names = ["YZPlane", "XZPlane", "XYPlane"] | ||
self.normals = [ | ||
(1, 0, 0), # YZPlane normal | ||
(0, 1, 0), # XZPlane normal | ||
(0, 0, 1) # XYPlane normal | ||
] | ||
self.axis_colors = [ | ||
Ogre.ColourValue(1, 0, 0, 1), | ||
Ogre.ColourValue(0, 1, 0, 1), | ||
Ogre.ColourValue(0, 0, 1, 1) | ||
] | ||
|
||
def show_plane(self, plane): | ||
for p in range(0, 3): | ||
plane_name = "MeshViewer/" + self.plane_names[p] | ||
plane_node = self.scn_mgr.getSceneNode(plane_name) | ||
plane_node.setVisible(p == plane) | ||
|
||
def create_material(self): | ||
material = Ogre.MaterialManager.getSingleton().create(GRID_MATERIAL, self.resource_group); | ||
p = material.getTechnique(0).getPass(0); | ||
p.setLightingEnabled(False); | ||
p.setVertexColourTracking(Ogre.TVC_AMBIENT); | ||
|
||
def create_planes(self, diam): | ||
self.create_material() | ||
for plane in range(0, 3): | ||
plane_name = "MeshViewer/" + self.plane_names[plane] | ||
self.create_plane(plane, -diam, diam) | ||
|
||
def create_plane(self, plane, min_val, max_val): | ||
cl = None | ||
axis_color = None | ||
plane_name = "MeshViewer/" + self.plane_names[plane] | ||
|
||
normal = self.normals[plane] | ||
|
||
color_X = self.axis_colors[0] | ||
color_Y = self.axis_colors[1] | ||
color_Z = self.axis_colors[2] | ||
|
||
if plane == 0: | ||
axis_color = [color_Y, color_Z] | ||
elif plane == 1: | ||
axis_color = [color_X, color_Z] | ||
elif plane == 2: | ||
axis_color = [color_Y, color_X] | ||
|
||
grid_color = Ogre.ColourValue(0.2, 0.2, 0.2, 0.4) | ||
|
||
# Compute the other axes based on the normal vector | ||
axis = [ | ||
Ogre.Vector3(normal[1], normal[2], normal[0]), | ||
Ogre.Vector3(normal[2], normal[0], normal[1]) | ||
] | ||
|
||
o = self.scn_mgr.createManualObject(plane_name); | ||
o.begin(GRID_MATERIAL, Ogre.RenderOperation.OT_LINE_LIST, self.resource_group) | ||
|
||
for i in range(0, 2): | ||
for j in range(min_val, max_val + 1): | ||
if j == 0: | ||
cl = axis_color[i] | ||
else: | ||
cl = grid_color | ||
o.position(axis[i] * min_val + axis[1 - i] * j) | ||
o.colour(cl) | ||
o.position(axis[i] * max_val + axis[1 - i] * j) | ||
o.colour(cl) | ||
|
||
o.end() | ||
|
||
plane_node = self.scn_mgr.getRootSceneNode().createChildSceneNode(plane_name) | ||
plane_node.attachObject(o) | ||
plane_node.setVisible(False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters