Пример #1
0
    def __init__(self, filename, name=None):
        ResourceBase.__init__(self, filename=filename)
        self._type = ResourceType.IMAGE
        if name is None:
            name = "Texture_" + str(self._id)
        
        self._name = name
        self._opengl_id = None
        self._size_x = None
        self._size_y = None
        
        self._pyglet_image = None

        self._smoothed = True
        self._wrapped = True
Пример #2
0
 def __init__(self, filename="", name="", root=None):
     ResourceBase.__init__(self)
     self._resource_type = ResourceType.SCENE
     
     # Scene Properties
     if root is None:
         self._root = Node(name="scene_root",scene=self)
     else:
         if isinstance(root, Node):
             self._root = root
             self._loaded = True
         #else:
             # root not is not assigned because it isn't a Node object
     self._cameras = []
     self._lights = []
     self._active_camera = None
     
     self._active = False
     
     self._scene_listener = SceneBaseListener(self)
Пример #3
0
    def __init__(self, vertices, faces, face_colours=None, tex_coords=None, filename=""):
        ResourceBase.__init__(self, filename=filename)
        self._type = ResourceType.MESH
        
        # Create Vertices
        # If they are not already in Vector3 format create the necessary 
        # Vector3 objects
        if len(vertices) > 0 and not isinstance(vertices[0], Vector3):
            vertices = [Vector3(*v) for v in vertices]
        self._vertices = vertices
        
        # Currently only Triangles are supported
        for face in faces:
            # Check if the faces reference more than 3 vertices
            assert len(face) >= 3
            
            # Check that each vertex referenced in the face
            # is valid
            for index in face:
                assert 0 <= index < len(vertices)
        
        self._faces = faces
        
        if face_colours is None:
            face_colours = Preset.white 
        # If a single Colour has been specified for all of the faces,
        # replicate it for all of the faces in the Mesh
        if isinstance(face_colours, Colour):
            face_colours = list(repeat(face_colours, len(self.faces)) )
                        
        self._face_colours = face_colours
        
        # If tex coords haven't been specified give the mesh a bunch of
        # zero'd texture coordinates
        if tex_coords is None:
            tex_coords = []
#            tex_coords = list(repeat(Vector3(), len(self._vertices)))
        
        self._tex_coords = tex_coords
        
        # calculate the min and max vertices for bounds
        min = Vector3()
        max = Vector3()
        
        for vec in self._vertices:
            if min.x > vec.x:
                min.x = vec.x
            if min.y > vec.y:
                min.y = vec.y
            if min.z > vec.z:
                min.z = vec.z
                
            if max.x < vec.x:
                max.x = vec.x
            if max.y < vec.y:
                max.y = vec.y
            if max.z < vec.z:
                max.z = vec.z
        
        self._bounds = Bounds(min, max)
            
        # Create a Open GL Mesh Object
        self._glmesh = GLMesh(self)