Example #1
0
    def __init__(self, 
                 position=Vector3(0,0,0), 
                 width=None, 
                 height=None, 
                 depth=None, 
                 max=Vector3(0.5, 0.5, 0.5), 
                 min=Vector3(-0.5,-0.5,-0.5),
                 colour=Preset.white ):
        
        Node.__init__(self, name="WireCube")
        
        self.transform.position = position
        
        self._width = width     # X
        self._height = height   # Y
        self._depth = depth     # Z
        
        self._min = min
        self._max = max
        
        # Gen min/max - Will override explictly defined min/max - so pick one or the other!
        if not width is None and not height is None and not depth is None:
            hw = width / 2.0
            hh = height / 2.0
            hd = depth / 2.0
            
            self._min = Vector3(-hw, -hh, -hd) + position
            self._max = Vector3(hw, hh, hd) + position
        
        self.gen_coords()

        self._colour = colour
Example #2
0
 def __init__(self, pos, normal=Vector3.UP(), size=1.0, colour=Preset.white):
     
     Node.__init__(self, name="WirePlane")
     
     self.transform.position = pos
     self._normal = normal.normalized()
     self._size = size
     self._colour = colour
     self._gen_offset_coords()
Example #3
0
    def __init__(self, pos=Vector3(0,0,0), radius=150.0, density=16): #6.328
        Node.__init__(self)
        
        self._name = "planet_root"

        self.transform.position = pos

        # The mesh density
        self._density = density
        
        # The camera position in sphere-space coordinates
        self._camera_pos = pos
        self._camera_pos_sc = None
        self._radius = radius
        self._horizon = 0.0
        
        self._max_depth = 8
        
        #self._camera_gizmo = WireSphere(radius=0.1)
        #self.transform.add_child(self._camera_gizmo.transform)
        
        self._camera_gizmo = GizmoManager.draw_sphere(Vector3(), radius=0.2)
        
        # The maximum height of the sphere surface (above the radius)
        self._max_height = (radius * 0.05) #0.02
        self._split_factor = 1.1  #16
        self._split_power = 1.1 #1.25
        
        self._horizon = 0
        
        self._ui = PlanetSphereDebugWindow()
        
        # Number splits this frame
        self._num_splits = 0
        # Max number of splits per frame
        self._max_splits = 8
        
#        pos = self.transform.position
#        pos.y += 0.1
#        self.transform.position.y = 1.0
#        self._line = Line(Vector3(0,1,0), Vector3(0, 0, 0), 5.0)
#        self.transform.add_child(self._line.transform)

        self._line = GizmoManager.draw_line(Vector3(-1,0,0), Vector3(0,0,0), 5.0)
        
#        self._cube_pos = Line(self.transform.position, Vector3(0, 0, 0), 5.0)
#        self.transform.add_child(self._cube_pos.transform)
        
        self._camera = None
        self._last_camera_pos = None
        self._last_time = datetime.now()
        
        self._generator = SphereSurface(self._density, self._radius, self._max_height)

        # Create the faces of the planet
        self._gen_faces()
Example #4
0
    def __init__(self, name,
                       sphere_parent,
                       planet_root, 
                       split_distance=1.0, 
                       radius=1.0,
                       root=True, 
                       level=-1,
                       density=10,
                       face=CubeSphereMap.TOP,
                       quad=QuadName.TL):
        
        # Override the default renderer
        Node.__init__(self, renderer=SphereQuadRenderer())
        
        self._name = name

        self._sphere_parent = sphere_parent
        
        # Planet Root - for global controls
        self._planet_root = planet_root
        
        self._face = face
        self._quad = quad
        #self.local_scale = Vector3(size, size, size)
        
        self._root = root
        
        self._is_split = False
        self._level = level
        
        # The Mesh density
        self._density = density
        
        self._radius = radius
#        self._split_dist = split_distance * self.SPLIT_DISTANCE 
        
        self._corners = None
        self._quad_centres = None
        
        self._centre_coords = None
        
        self._sorted_quads = None
        
        # The Quads
        self._tl = None
        self._tr = None
        self._bl = None
        self._br = None
Example #5
0
    def __init__(self, 
                 position=Vector3(0,0,0), 
                 direction=Vector3(0,0,0), 
                 length=1.0, 
                 colour=None, 
                 start_colour=Preset.white, 
                 end_colour=Preset.red):
        Node.__init__(self)
        self.transform.position = position
        self._direction = direction.normalized()
        self._length = length

        if not colour is None:
            self._start_colour = colour
            self._end_colour = colour
        else:
            self._start_colour = start_colour
            self._end_colour = end_colour
Example #6
0
 def __init__(self, position=Vector3(0,0,0), radius=1.0):
     Node.__init__(self)
     self.transform.position = position
     print "Wire Sphere position: %s" % self.transform.position
     self._radius = radius
Example #7
0
 def __init__(self, name="terrain", size=64, low=-2.5, high=2.5):
     Node.__init__(self, name=name)
     self._size = size
     self._low = low
     self._high = high
Example #8
0
 def __init__(self):
     Node.__init__(self, name="default_light", light=GLLight(), renderer=None)
Example #9
0
	def __init__(self):
		Node.__init__(self, name="default_camera", camera=CameraGL(), renderer=None)
    def parse_node(self, node, parent=None):
        
        
        current_node = None
        node_name = None
        
        if "name" in node.attrib:
            node_name = node.attrib["name"]
                
        if node.tag == "scene":
            if node_name is None:
                node_name = "default_scene" 
            
            current_node = Node(name=node_name)
        
        elif node.tag == "camera":
            current_node = Camera()
            # SIGH - There is no scene at this point because the loading has just begun
            # If the current scene doesn't yet have an active camera
#            if not parent is None and \
#               isinstance(parent, Node) and \
#               parent.scene.active_camera is None:
#                # Set this camera as the active camera
#                parent.scene.active_camera = current_node
                    
                        
        elif node.tag == "light":
            current_node = Light()
        
        elif node.tag == "node":
            current_node = Node()
            
            if not node_name is None and not current_node is None:
                if hasattr(current_node, 'name'):
                    current_node.name = node_name
        
        # Child Nodes
        
        # Transform
        elif node.tag == "transform":
            if not parent is None:
                
                transform = None
                if isinstance(parent, Transform):
                    transform = parent
                elif isinstance(parent, Node):
                    transform = parent.transform
                
                if "position" in node.attrib:
                    coord = node.attrib["position"].split(" ")
                    if len(coord) == 3:
                        coord = Vector3(float(coord[0]), float(coord[1]), float(coord[2]) )
                    else:
                        self._log.Log("Invalid position: [%s]" % (" ".join(coord)))
                    
                    transform.position = coord
                
                if "rotation" in node.attrib:
                    rot = node.attrib["rotation"].split(" ")
                    if len(rot) == 4:
                        rot = Quaternion().new_rotate_axis(float(rot[0]), Vector3(float(rot[1]),float(rot[2]),float(rot[3])))
                    else:
                        self._log.Log( "Invalid rotation: [%s]" % (" ".join(rot)) )
                    
                    transform.rotation = rot
                    
                if "scale" in node.attrib:
                    scale = node.attrib["scale"].split(" ")
                    if len(scale) == 3:
                        scale = Vector3(float(scale[0]), float(scale[1]), float(scale[2]) )
                    else:
                        self._log.Log( "Invalid scale: [%s]" % (" ".join(scale)) )
                    
                    transform.local_scale = scale
        # Colour
        elif node.tag == "colour":
            if not parent is None:
                colour_object = None
                
                if isinstance(parent, Light) and not parent.light is None:
                    colour_object = parent.light
                elif isinstance(parent, BaseMaterial):
                    colour_object = parent
                    
#                if not colour_object is None:
                if "ambient" in node.attrib:
                    colour_object.ambient = Colour.from_string(node.attrib["ambient"])
                
                if "diffuse" in node.attrib:
                    colour_object.diffuse = Colour.from_string(node.attrib["diffuse"])
                
                if "specular" in node.attrib:
                    colour_object.specular = Colour.from_string(node.attrib["specular"])
                        
        elif node.tag == "attenuation":
            if not current_node is None and isinstance(current_node, Node):
                if not current_node.light is None:
                    if "value" in node.attrib:
                        atten = node.attrib["value"].split(" ")
                        if len(atten) == 1:
                            atten = float(atten)
                        else:
                            self._log.Log( "Invalid attenuation: [%s]" % (str(atten)) )
                        
                        current_node.light.attenuation = float(atten)
#                        if isinstance(parent, GLLight):
#                            parent.attenuation = float(atten)
        
        # Mesh
        elif node.tag == "mesh":
            if not isinstance(parent, Light) or not isinstance(parent, Camera):
                if "preset" in node.attrib:
                    preset = node.attrib["preset"]
                    if preset in MeshTypesString.MESHES:
                        parent.renderer.mesh = MeshFactory.get_mesh(MeshTypesString.MESHES[preset])
                    else:
                        self._log.Log( "Invalid Mesh Preset: [%s]" % ( preset ) )
                        
                if "filename" in node.attrib:
                    
                    # Get the name
                    name = None
                    if 'name' in node.attrib:
                        name = node.attrib['name']

                    # Load the mesh
                    filename = node.attrib["filename"]
                    mesh = ResourceManager.get_instance().process_resource(filename, name)

                    # Set it to the node
                    parent.renderer.mesh = mesh
        
        # Children        
        elif node.tag == "children":
            if not parent is None:
                # Get the child nodes of the children Element
                
                children = node.getchildren()
                
                # Process each of the child elements found.
                for child in children:
                    self.parse_node(child, parent)
            
        # Scripts
        elif node.tag == "scripts":
            if not parent is None:
                # Get the scripts applied to this node
                scripts = node.getchildren()
                
                # Process and attach each of the scripts
                for script in scripts:
                    self.parse_node(script, parent)
                    
        elif node.tag == "script":
            # If this tag is used as a child tag of another node.
            if not parent is None:
                script_name = node.attrib["name"]
                parameters = {}
                for key in node.attrib:
                    if not key == "name":
                        parameters[key] = node.attrib[key]
                        
                # The current limitation of this is that the only scripts that can be used
                # are the ones listed in TestScripts.  TBD: Change to dynamic import, allow
                # files to be included in the scene description.
                
                # The python files listed in the scene definition need to be parsed and loaded
                # into the engine before this parsing occurs if this is to be made more
                # flexible
                
                # Create the Script
                script = None
                try:
                    script = getattr(testscripts, script_name)
                    new_script = script()
                except Exception, e:
                    self._log.Log("Could not create Script with name: " + script_name)
                    self._log.Log("Message: " + e.message)
                    script = None
                
                if not script is None:
                    try:
                        # Initialise it using the parameters in the XML
                        
                        new_script.init_parameters(parameters)
                        parent.add_script(new_script)
                    except Exception, e:
                        self._log.Log("Invalid parameters for script: " + script_name)
                        self._log.Log("parameters: " + str(parameters))