示例#1
0
 def run(self,
         py_ubi_forge,
         file_id: Union[str, int],
         forge_file_name: str,
         datafile_id: int,
         options: Union[List[dict], None] = None):
     # TODO add select directory option
     save_folder = py_ubi_forge.CONFIG.get('dumpFolder', 'output')
     texture.export_dds(py_ubi_forge, file_id, save_folder, forge_file_name,
                        datafile_id)
示例#2
0
	def save_and_close(self):
		"""
		when called will create the mtl file and write its contents
		when finished will close both mtl and self._obj
		:return:
		"""
		mtl = open(f'{self.save_folder}{os.sep}{self.model_name}.mtl', 'w')
		mtl.write('# Material Library\n#Exported by ACExplorer, written by gentlegiantJGC, based on code from ARchive_neXt\n\n')
		for material in self.mtl_handler.materials.values():
			mtl.write(f'newmtl {material.name}\n')
			mtl.write('Ka 1.000 1.000 1.000\nKd 1.000 1.000 1.000\nKs 0.000 0.000 0.000\nNs 0.000\n')

			if material.missing_no:
				mtl.write(f'map_Kd {os.path.basename(self.pyUbiForge.CONFIG["missingNo"])}\n')
				self.export_missing_no()
			else:
				for map_type, file_id in [
											['map_Kd', material.diffuse],
											['map_d', material.diffuse],
											['map_Ks', material.specular],
											['map_bump', material.normal],
											['disp', material.height]
										]:
					if file_id is None:
						continue
					image_path = texture.export_dds(self.pyUbiForge, file_id, self.save_folder)
					if image_path is None:
						mtl.write(f'{map_type} {os.path.basename(self.pyUbiForge.CONFIG["missingNo"])}\n')
						self.export_missing_no()
					else:
						mtl.write(f'{map_type} {os.path.basename(image_path)}\n')
			mtl.write('\n')
		mtl.close()
		self._obj.close()
示例#3
0
def plugin(py_ubi_forge, file_id, forge_file_name, datafile_id, options):
    # TODO add select directory option
    save_folder = py_ubi_forge.CONFIG['dumpFolder']
    texture.export_dds(py_ubi_forge, file_id, save_folder, forge_file_name,
                       datafile_id)
示例#4
0
    def save_and_close(self) -> None:
        """
		when called will write the textures, materials and scene data
		when finished will close self._dae
		:return:
		"""

        library_materials = []
        library_effects = []
        library_images = []

        self._dae.write('''	</library_geometries>
''')

        self._dae.write(f'''	<library_visual_scenes>
		<visual_scene id="Scene" name="Scene">
{''.join(self._library_visual_scenes)}		</visual_scene>
	</library_visual_scenes>
''')

        for material in self._mtl_handler.materials.values():
            image_path = None
            material_name = material.name
            if material.missing_no:
                image_path = os.path.basename(
                    pyUbiForge.CONFIG.get('missingNo',
                                          'resources/missingNo.png'))
                self.export_missing_no()
            else:
                for map_type, file_id in [
                    ['diffuse', material.diffuse]  #,
                        # ['map_d', material.diffuse],
                        # ['map_Ks', material.specular],
                        # ['map_bump', material.normal],
                        # ['disp', material.height]
                ]:
                    if file_id is None:
                        continue
                    image_path = os.path.basename(
                        texture.export_dds(file_id, self.save_folder))
                    if image_path is None:
                        image_path = os.path.basename(
                            pyUbiForge.CONFIG.get('missingNo',
                                                  'resources/missingNo.png'))
                        self.export_missing_no()
                    library_images.append(
                        f'''		<image id="{material_name}-{map_type}" name="{material_name}">
			<init_from>{urllib.parse.quote(image_path)}</init_from>
		</image>
''')

            library_effects.append(f'''		<effect id="{material_name}-effect">
			<profile_COMMON>
				<newparam sid="{material_name}-surface">
					<surface type="2D">
						<init_from>{material_name}-diffuse</init_from>
					</surface>
				</newparam>
				<newparam sid="{material_name}-sampler">
					<sampler2D>
						<source>{material_name}-surface</source>
					</sampler2D>
				</newparam>
				<technique sid="common">
					<phong>
						<emission>
							<color sid="emission">0 0 0 1</color>
						</emission>
						<ambient>
							<color sid="ambient">0 0 0 1</color>
						</ambient>
						<diffuse>
							<texture texture="{material_name}-sampler"/>
						</diffuse>
						<specular>
							<color sid="specular">0.5 0.5 0.5 1</color>
						</specular>
						<shininess>
							<float sid="shininess">50</float>
						</shininess>
						<index_of_refraction>
							<float sid="index_of_refraction">1</float>
						</index_of_refraction>
					</phong>
				</technique>
			</profile_COMMON>
		</effect>
''')

            library_materials.append(
                f'''		<material id="{material_name}-material" name="{material_name}">
			<instance_effect url="#{material_name}-effect"/>
		</material>
''')

        self._dae.write(f'''	<library_images>
{''.join(library_images)}	</library_images>
''')

        self._dae.write(f'''	<library_effects>
{''.join(library_effects)}	</library_effects>
''')

        self._dae.write(f'''	<library_materials>
{''.join(library_materials)}	</library_materials>
''')

        self._dae.write('''	<scene>
		<instance_visual_scene url="#Scene"/>
	</scene>
''')
        self._dae.write('</COLLADA>')

        self._dae.close()