def load(self, data_object): """ @type data_object: tuple @param data_object: (scene, parent, kml_node) """ scene, parent, node = data_object # Load Object based values Object.load(self, (parent, node)) physical_node = node.get('Physical', None) if physical_node is None: msg = 'Object "%s" needs a "Phsyical" section' % node['name'] raise PhysicsError(msg) # Find shape type and its properties shape_node = physical_node.get('Shape', None) if shape_node is None: msg = 'Object "%s" needs a "Physical.Shape" section' % node['name'] raise PhysicsError(msg) shape_type = shape_node['type'].lower() shape_props = {} for param, value in shape_node.iteritems(): if param != 'type': shape_props[param] = value scale = shape_node.get('mesh_scale', None) if scale is not None: shape_props['mesh_scale'] = scale else: gfx_node = node.get('Graphical', {}) shape_props['mesh_scale'] = gfx_node.get('scale', [1,1,1]) # Grab and validate Mass mass = physical_node.get('mass', 0) if (type(mass) is not int) and (type(mass) is not float): raise SimulationError('Mass must be an interger of float') position, orientation = parse_position_orientation(node) # Inertia and COM center_of_mass = physical_node.get('center_of_mass',Ogre.Vector3.ZERO) inertia = physical_node.get('inertia', None) Body._create(self, scene, shape_type, shape_props, mass, center_of_mass, inertia, position, orientation) # Small hack, this should be integrated integrated better # I should probably reduce the number of constructor parameters as well material = physical_node.get('material', None) if material is not None: self._material = material material_id = scene.world.get_material_id(material) self._body.setMaterialGroupID(material_id)
def load(self, data_object): """ @type data_object: tuple @param data_object: (scene, parent, kml_node) """ scene, parent, node = data_object # Load Object based values Object.load(self, (parent, node)) gfx_node = node["Graphical"] mesh = gfx_node["mesh"] material = gfx_node.get("material", None) scale = sim.OgreVector3(gfx_node.get("scale", Ogre.Vector3(1, 1, 1))) # Handle special mesh generation if mesh.startswith("PLANE"): if ":" in mesh: mesh = mesh.split(":")[1] else: mesh = "Plane" + str(Visual._plane_count) norm = gfx_node["normal"] width = gfx_node["width"] height = gfx_node["height"] upvec = gfx_node.get("upvec", Ogre.Vector3.UNIT_Y) utile = gfx_node.get("utile", 1) vtile = gfx_node.get("vtile", 1) plane = Ogre.Plane(norm, 0) group_name = gfx_node.get("group", Ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME) xsegments = int(width) ysegments = int(height) Ogre.MeshManager.getSingletonPtr().createPlane( mesh, group_name, plane, width, height, upVector=upvec, uTile=utile, vTile=vtile, xsegments=xsegments, ysegments=ysegments, ) Visual._plane_count += 1 # Orientation defaults: IDENTITY, Position: (0,0,0) position, orientation = parse_position_orientation(node) Visual._create(self, scene, mesh, material, position, orientation, scale) # Check visibility if not gfx_node.get("visible", True): self._node.setVisible(False)
def load(self, data_object): """ @type data_object: tuple @param data_object: (scene, parent, kml_node) """ scene, parent, node = data_object # Load Object based values Object.load(self, (parent, node)) gfx_node = node['Graphical'] mesh = gfx_node['mesh'] material = gfx_node.get('material', None) scale = sim.OgreVector3(gfx_node.get('scale', Ogre.Vector3(1, 1, 1))) # Handle special mesh generation if mesh.startswith('PLANE'): if ':' in mesh: mesh = mesh.split(':')[1] else: mesh = 'Plane' + str(Visual._plane_count) norm = gfx_node['normal'] width = gfx_node['width'] height = gfx_node['height'] upvec = gfx_node.get('upvec', Ogre.Vector3.UNIT_Y) utile = gfx_node.get('utile', 1) vtile = gfx_node.get('vtile', 1) plane = Ogre.Plane(norm, 0) group_name = gfx_node.get( 'group', Ogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME) xsegments = int(width) ysegments = int(height) Ogre.MeshManager.getSingletonPtr().createPlane(mesh, \ group_name, plane, width, height, upVector = upvec, uTile = utile, vTile = vtile, xsegments = xsegments, ysegments = ysegments) Visual._plane_count += 1 # Orientation defaults: IDENTITY, Position: (0,0,0) position, orientation = parse_position_orientation(node) Visual._create(self, scene, mesh, material, position, orientation, scale) # Check visibility if not gfx_node.get('visible', True): self._node.setVisible(False)
def load(self, data_object): #Visual.load(self, data_object) # Remove me when scene node parenting issue is fixed scene, parent, kml_node = data_object Object.load(self, (parent, kml_node)) gfx_node = kml_node['Graphical'] mesh = gfx_node['mesh'] material = gfx_node['material'] scale = sim.OgreVector3(gfx_node['scale']) position, orientation = parse_position_orientation(kml_node) self._force_pos = sim.OgreVector3(position) direction = sim.OgreVector3(kml_node['direction']) min_force = kml_node['min_force'] max_force = kml_node['max_force'] Thruster._create(self, scene, direction, min_force, max_force, mesh, material, position, orientation, scale)