Esempio n. 1
0
    def __init__(self, name, pos, mesh, material, lightColor = (1.0, 1.0, 1.0, 1.0)):
        BaseObject.__init__(self, name, pos, mesh, material)

        self.lightColor = np.array(lightColor, dtype=np.float32)

        # log
        logger.info("Create Light : %s", self.name)
Esempio n. 2
0
    def initialize(self):
        logger.info("initialize " + self.__class__.__name__)

        # collect shader files
        for filename in glob.glob(os.path.join(PathShaders, '*.*')):
            try:
                shaderFile = os.path.split(filename)[1]
                shaderName, ext = os.path.splitext(shaderFile)
                # open shader file
                f = open(filename, 'r')
                shaderSource = f.read()
                f.close()
                # create shader
                if ext == '.vs':
                    shader = VertexShader(shaderName, shaderSource)
                    self.vertexShaders[shaderName] = shader
                elif ext == '.fs':
                    shader = FragmentShader(shaderName, shaderSource)
                    self.fragmentShader[shaderName] = shader
                else:
                    logger.warn("Shader error : %s is invalid shader. Shader file extension must be one of '.vs', '.ps', '.cs'..." % filename)
                    continue
                # regist shader
                self.shaders.append(shader)
            except:
                logger.error(traceback.format_exc())
Esempio n. 3
0
 def create_collection(self, collection_name):
     if not self.IS_CONNECTED:
         self.connect_to_mongodb()
     new_collection = self.data_base[collection_name]
     collections = self.data_base.list_collection_names()
     if collection_name in collections:
         logger.info(f"Successfully creted {new_collection} in {self.data_base}")
         return True
     else:
         logger.fatal(f"Created empty collection named {collection_name}")
Esempio n. 4
0
    def __init__(self, shaderName, shaderSource):
        logger.info("Create " + self.__class__.__name__ + " : " + shaderName)
        self.name = shaderName
        self.source = shaderSource
        self.shader = glCreateShader(self.shaderType)

        # Set shaders source
        glShaderSource(self.shader, shaderSource)

        # Compile shaders
        glCompileShader(self.shader)
Esempio n. 5
0
    def initialize(self):
        logger.info("initialize " + self.__class__.__name__)

        # Regist meshs
        self.meshes['Triangle'] = Triangle()
        self.meshes['Quad'] = Quad()
        # regist mesh files
        for filename in glob.glob(os.path.join(PathMeshes, '*.mesh')):
            name = os.path.splitext(os.path.split(filename)[1])[0]
            name = name[0].upper() + name[1:]
            self.meshes[name] = Mesh(name, filename)
Esempio n. 6
0
    def __init__(self, name):
        BaseObject.__init__(self, name, (0, 0, 0), None, None)

        # get properties
        self.fov = config.Camera.fov
        self.near = config.Camera.near
        self.far = config.Camera.far
        self.pan_speed = config.Camera.pan_speed
        self.rotation_speed = config.Camera.rotation_speed

        # log
        logger.info("Create Camera : %s", self.name)
Esempio n. 7
0
 def edit_document(self, collection_name, key, value,
  new_key = None, new_value = None):
     document = self.find_document(collection_name, key, value)
     if new_key:
         document.pop(key)
         document[new_key] = value
         old_key = key
         key = new_key
     if new_value:
         document[key] = new_value
     self.delete_document(collection_name, old_key, value)
     self.insert_to_mongodb(collection_name, doc = document)
     logger.info("Successfully updated the document")
Esempio n. 8
0
 def insert_to_mongodb(self, collection_name, doc = None, **data):
     if not self.IS_CONNECTED:
         self.connect_to_mongodb()
     collection = self.data_base[collection_name]
     if doc:
         collection.insert_one(doc)
         logger.info("Inserted successfully the document")
     else:
         document = {}
         for key in data.keys():
             document[str(key)] = data.get(key)
         collection.insert_one(document)
         logger.info("Inserted successfully the dictionary")
Esempio n. 9
0
    def initialize(self):
        logger.info("initialize " + self.__class__.__name__)
        shaderLoader = ShaderLoader.instance()

        # create materials
        for filename in glob.glob(os.path.join(PathMaterials, "*.*")):
            if os.path.splitext(filename)[1].lower() == ".material":
                materialFile = configparser.ConfigParser()
                materialFile.read(filename)
                vs = shaderLoader.getVertexShader(materialFile.get("VertexShader", "shaderName"))
                fs = shaderLoader.getFragmentShader(materialFile.get("FragmentShader", "shaderName"))
                materialName = os.path.splitext(os.path.split(filename)[1])[0]
                material = self.createMaterial(name=materialName, vs=vs, fs=fs)
                self.materials[materialName] = material
        self.default_material = self.getMaterial('default')
Esempio n. 10
0
    def __init__(self, name, vs, fs):
        logger.info("Create Material : " + name)
        self.name = name
        self.twoSide = False

        # build and link the program
        self.program = glCreateProgram()
        self.vertexShader = vs
        self.fragmentShader = fs
        glAttachShader(self.program, vs.shader)
        glAttachShader(self.program, fs.shader)
        glLinkProgram(self.program)

        # We can not get rid of shaders, they won't be used again
        glDetachShader(self.program, vs.shader)
        glDetachShader(self.program, fs.shader)