示例#1
0
文件: material.py 项目: b2rex/b2rex
	def _exportTextureUnit(self, f, name, btex):
		"""
		Export a single texture unit based on a blender mapto texture.
		"""
		f.write(indent(3)+"texture_unit " + name + "\n")
		f.write(indent(3)+"{\n")
		if btex.tex and btex.tex.getImage():
			f.write(indent(4)+"texture %s\n" % self.manager.registerTextureImage(btex.tex.getImage()))
		f.write(indent(3)+"}\n") # texture_unit
示例#2
0
    def _exportTextureUnit(self, f, name, btex):
        """
		Export a single texture unit based on a blender mapto texture.
		"""
        f.write(indent(3) + "texture_unit " + name + "\n")
        f.write(indent(3) + "{\n")
        if btex.tex and btex.tex.getImage():
            f.write(
                indent(4) + "texture %s\n" %
                self.manager.registerTextureImage(btex.tex.getImage()))
        f.write(indent(3) + "}\n")  # texture_unit
示例#3
0
 def writeProperty(self, f, name, value):
     """
     Write an avatar property
     """
     f.write(
         indent(1) + '<property name="' + name + '" value="' + value +
         '" />')
示例#4
0
文件: material.py 项目: b2rex/b2rex
	def _writeMaterialParameters(self, f, mat):
		"""
		Write the material parameters.
		"""
		# alpha
		if self.alpha < 1.0:
			f.write(indent(3)+"scene_blend alpha_blend\n")
			f.write(indent(3)+"depth_write off\n")

		# ambient
		# (not used in Blender's game engine)
		if mat:
			if (not(mat.mode & Blender.Material.Modes["TEXFACE"])
				and not(mat.mode & Blender.Material.Modes["VCOL_PAINT"])
				and (self.colouredAmbient)):
				ambientRGBList = mat.rgbCol
			else:
				ambientRGBList = [1.0, 1.0, 1.0]
			# ambient <- amb * ambient RGB
			ambR = clamp(mat.amb * ambientRGBList[0])
			ambG = clamp(mat.amb * ambientRGBList[1])
			ambB = clamp(mat.amb * ambientRGBList[2])
			f.write(indent(3)+"ambient %f %f %f\n" % (ambR, ambG, ambB))
		# diffuse
		# (Blender's game engine uses vertex colours
		#  instead of diffuse colour.
		#
		#  diffuse is defined as
		#  (mat->r, mat->g, mat->b)*(mat->emit + mat->ref)
		#  but it's not used.)
		if self.mesh.vertexColors and False:
			# we ignore this possibility for now...
			# Blender does not handle "texface" mesh with vertex colours
			f.write(indent(3)+"diffuse vertexcolour\n")
		elif mat:
			if (not(mat.mode & Blender.Material.Modes["TEXFACE"])
				and not(mat.mode & Blender.Material.Modes["VCOL_PAINT"])):
				# diffuse <- rgbCol
				diffR = clamp(mat.rgbCol[0])
				diffG = clamp(mat.rgbCol[1])
				diffB = clamp(mat.rgbCol[2])
				f.write(indent(3)+"diffuse %f %f %f\n" % (diffR, diffG, diffB))
			elif (mat.mode & Blender.Material.Modes["VCOL_PAINT"]):
				f.write(indent(3)+"diffuse vertexcolour\n")

			# specular <- spec * specCol, hard/4.0
			specR = clamp(mat.spec * mat.specCol[0])
			specG = clamp(mat.spec * mat.specCol[1])
			specB = clamp(mat.spec * mat.specCol[2])
			specShine = mat.hard/4.0
			f.write(indent(3)+"specular %f %f %f %f\n" % (specR, specG, specB, specShine))
			# emissive
			# (not used in Blender's game engine)
			if(not(mat.mode & Blender.Material.Modes["TEXFACE"])
				and not(mat.mode & Blender.Material.Modes["VCOL_PAINT"])):
				# emissive <-emit * rgbCol
				emR = clamp(mat.emit * mat.rgbCol[0])
				emG = clamp(mat.emit * mat.rgbCol[1])
				emB = clamp(mat.emit * mat.rgbCol[2])
示例#5
0
 def writeAnimation(self, f, id, name, internal_name):
     """
     Write an animation to the avatar file
     """
     f.write(indent(1) + '<animation name="' + name + '" ')
     f.write('id="' + id + '" internal_name="' + internal_name + '" ')
     f.write('looped="1" speedfactor="1.0" ')
     if 'walk' in name.lower() or 'run' in name.lower():
         f.write('usevelocity="1" ')
     f.write('fadein="0.25" ')
     f.write('fadeout="0.25" />\n')
示例#6
0
 def writeAnimation(self, f, id, name, internal_name):
     """
     Write an animation to the avatar file
     """
     f.write(indent(1)+'<animation name="'+name+'" ')
     f.write('id="'+id+'" internal_name="'+internal_name+'" ')
     f.write('looped="1" speedfactor="1.0" ')
     if 'walk' in name.lower() or 'run' in name.lower():
         f.write('usevelocity="1" ')
     f.write('fadein="0.25" ')
     f.write('fadeout="0.25" />\n')
示例#7
0
 def writeAvatarFile(self, f):
     """
     Write an avatar file for the selected mesh.
     """
     f.write('<?xml version="1.0" encoding="utf-8" ?>\n')
     f.write('<avatar>\n')
     f.write(indent(1)+'<version>0.2</version>\n')
     f.write(indent(1)+'<base name="default_female" mesh="'+self.settings['mesh_file']+'" />\n')
     f.write(indent(1)+'<skeleton name="'+self.settings['skeleton_file']+'" />\n')
     #f.write(indent(1)+'<material name="male/Body" />\n')
     #f.write(indent(1)+'<material name="male/Face" />\n')
     first_face_image = self.getMesh().getData(0, True).faces[0].image
     if first_face_image:
         texture_name = os.path.basename(first_face_image.getFilename())
     else:
         texture_name = ''
     f.write(indent(1)+'<texture_body name="'+texture_name+'" />\n')
     #f.write(indent(1)+'<texture_face name="" />\n')
     f.write(indent(1)+'<appearance height="1.800000" weight="1" />\n')
     f.write(indent(1)+'<transformation position="%s" rotation="%s" \
             scale="%s" />\n' % (self.settings['translation'],
                                 self.settings['rotation'],
                                 self.settings['scale']))
     self.writeProperties(f)
     self.writeAnimations(f)
     f.write('</avatar>')
示例#8
0
 def writeAvatarFile(self, f):
     """
     Write an avatar file for the selected mesh.
     """
     f.write('<?xml version="1.0" encoding="utf-8" ?>\n')
     f.write('<avatar>\n')
     f.write(indent(1) + '<version>0.2</version>\n')
     f.write(
         indent(1) + '<base name="default_female" mesh="' +
         self.settings['mesh_file'] + '" />\n')
     f.write(
         indent(1) + '<skeleton name="' + self.settings['skeleton_file'] +
         '" />\n')
     #f.write(indent(1)+'<material name="male/Body" />\n')
     #f.write(indent(1)+'<material name="male/Face" />\n')
     first_face_image = self.getMesh().getData(0, True).faces[0].image
     if first_face_image:
         texture_name = os.path.basename(first_face_image.getFilename())
     else:
         texture_name = ''
     f.write(indent(1) + '<texture_body name="' + texture_name + '" />\n')
     #f.write(indent(1)+'<texture_face name="" />\n')
     f.write(indent(1) + '<appearance height="1.800000" weight="1" />\n')
     f.write(
         indent(1) + '<transformation position="%s" rotation="%s" \
             scale="%s" />\n' %
         (self.settings['translation'], self.settings['rotation'],
          self.settings['scale']))
     self.writeProperties(f)
     self.writeAnimations(f)
     f.write('</avatar>')
示例#9
0
文件: material.py 项目: b2rex/b2rex
	def _writePassContents(self, f, mat):
		"""
		Write a full pass information.
		"""
		f.write(indent(3)+"iteration once\n")

		# shader programs
		self._writeShaderPrograms(f)

		# material colors
		self._writeMaterialParameters(f, mat)

		# texture units
		self._writeTextureUnits(f, mat)
示例#10
0
    def _writePassContents(self, f, mat):
        """
		Write a full pass information.
		"""
        f.write(indent(3) + "iteration once\n")

        # shader programs
        self._writeShaderPrograms(f)

        # material colors
        self._writeMaterialParameters(f, mat)

        # texture units
        self._writeTextureUnits(f, mat)
示例#11
0
文件: material.py 项目: b2rex/b2rex
	def _writeShaderPrograms(self, f):
		"""
		Write the rex specific shader references into the material.
		"""
		shader = self.shader
		fp_parms = self.fp_parms
		vp_parms = self.vp_parms
		f.write(indent(3)+"vertex_program_ref " + shader + "VP\n")
		f.write(indent(3)+"{\n")
		for par, value in vp_parms.iteritems():
			par_type = "float"
			f.write(indent(4)+"param_named %s %s %s\n"%(par, par_type, value))
		f.write(indent(3)+"}\n")
		f.write(indent(3)+"fragment_program_ref " + shader + "FP\n")
		f.write(indent(3)+"{\n")
		for par, value in fp_parms.iteritems():
			par_type = "float"
			f.write(indent(4)+"param_named %s %s %s\n"%(par, par_type, value))
		f.write(indent(3)+"}\n")
示例#12
0
    def _writeShaderPrograms(self, f):
        """
		Write the rex specific shader references into the material.
		"""
        shader = self.shader
        fp_parms = self.fp_parms
        vp_parms = self.vp_parms
        f.write(indent(3) + "vertex_program_ref " + shader + "VP\n")
        f.write(indent(3) + "{\n")
        for par, value in vp_parms.iteritems():
            par_type = "float"
            f.write(
                indent(4) + "param_named %s %s %s\n" % (par, par_type, value))
        f.write(indent(3) + "}\n")
        f.write(indent(3) + "fragment_program_ref " + shader + "FP\n")
        f.write(indent(3) + "{\n")
        for par, value in fp_parms.iteritems():
            par_type = "float"
            f.write(
                indent(4) + "param_named %s %s %s\n" % (par, par_type, value))
        f.write(indent(3) + "}\n")
示例#13
0
    def writeRexTechniques(self, f, mat):
        """
		Write a rex material technique.
		"""
        # default material
        # SOLID, white, no specular
        f.write(indent(1) + "technique\n")
        f.write(indent(1) + "{\n")
        f.write(indent(2) + "pass\n")
        f.write(indent(2) + "{\n")
        self._writePassContents(f, mat)
        f.write(indent(2) + "}\n")  # pass
        f.write(indent(1) + "}\n")  # technique
        return
示例#14
0
文件: material.py 项目: b2rex/b2rex
	def writeRexTechniques(self, f, mat):
		"""
		Write a rex material technique.
		"""
		# default material
		# SOLID, white, no specular
		f.write(indent(1)+"technique\n")
		f.write(indent(1)+"{\n")
		f.write(indent(2)+"pass\n")
		f.write(indent(2)+"{\n")
		self._writePassContents(f, mat)
		f.write(indent(2)+"}\n") # pass
		f.write(indent(1)+"}\n") # technique
		return
示例#15
0
    def _writeMaterialParameters(self, f, mat):
        """
		Write the material parameters.
		"""
        # alpha
        if self.alpha < 1.0:
            f.write(indent(3) + "scene_blend alpha_blend\n")
            f.write(indent(3) + "depth_write off\n")

        # ambient
        # (not used in Blender's game engine)
        if mat:
            if (not (mat.mode & Blender.Material.Modes["TEXFACE"])
                    and not (mat.mode & Blender.Material.Modes["VCOL_PAINT"])
                    and (self.colouredAmbient)):
                ambientRGBList = mat.rgbCol
            else:
                ambientRGBList = [1.0, 1.0, 1.0]
            # ambient <- amb * ambient RGB
            ambR = clamp(mat.amb * ambientRGBList[0])
            ambG = clamp(mat.amb * ambientRGBList[1])
            ambB = clamp(mat.amb * ambientRGBList[2])
            f.write(indent(3) + "ambient %f %f %f\n" % (ambR, ambG, ambB))
        # diffuse
        # (Blender's game engine uses vertex colours
        #  instead of diffuse colour.
        #
        #  diffuse is defined as
        #  (mat->r, mat->g, mat->b)*(mat->emit + mat->ref)
        #  but it's not used.)
        if self.mesh.vertexColors and False:
            # we ignore this possibility for now...
            # Blender does not handle "texface" mesh with vertex colours
            f.write(indent(3) + "diffuse vertexcolour\n")
        elif mat:
            if (not (mat.mode & Blender.Material.Modes["TEXFACE"])
                    and not (mat.mode & Blender.Material.Modes["VCOL_PAINT"])):
                # diffuse <- rgbCol
                diffR = clamp(mat.rgbCol[0])
                diffG = clamp(mat.rgbCol[1])
                diffB = clamp(mat.rgbCol[2])
                f.write(
                    indent(3) + "diffuse %f %f %f\n" % (diffR, diffG, diffB))
            elif (mat.mode & Blender.Material.Modes["VCOL_PAINT"]):
                f.write(indent(3) + "diffuse vertexcolour\n")

            # specular <- spec * specCol, hard/4.0
            specR = clamp(mat.spec * mat.specCol[0])
            specG = clamp(mat.spec * mat.specCol[1])
            specB = clamp(mat.spec * mat.specCol[2])
            specShine = mat.hard / 4.0
            f.write(
                indent(3) + "specular %f %f %f %f\n" %
                (specR, specG, specB, specShine))
            # emissive
            # (not used in Blender's game engine)
            if (not (mat.mode & Blender.Material.Modes["TEXFACE"])
                    and not (mat.mode & Blender.Material.Modes["VCOL_PAINT"])):
                # emissive <-emit * rgbCol
                emR = clamp(mat.emit * mat.rgbCol[0])
                emG = clamp(mat.emit * mat.rgbCol[1])
                emB = clamp(mat.emit * mat.rgbCol[2])
示例#16
0
文件: material.py 项目: b2rex/b2rex
	def _writeTextureUnits(self, f, mat):
		"""
		Write the texture units for the material.
		"""
		textures = self.getTextureLayers(mat)
		spectex = textures['spec']
		nortex = textures['nor']
		reftex = textures['ref']
		ambtex = textures['amb']
		disptex = textures['disp']
		shader = self.shader
		# texture units
		if self.mesh.faceUV:
			# mesh has texture values, resp. tface data
			# scene_blend <- transp
			if (self.face.transp == Blender.Mesh.FaceTranspModes["ALPHA"]):
				f.write(indent(3)+"scene_blend alpha_blend \n")
			elif (self.face.transp == Blender.NMesh.FaceTranspModes["ADD"]):
				f.write(indent(3)+"scene_blend add\n")
			# cull_hardware/cull_software
			if (self.face.mode & Blender.Mesh.FaceModes['TWOSIDE']):
				f.write(indent(3) + "cull_hardware none\n")
				f.write(indent(3) + "cull_software none\n")
			# shading
			# (Blender's game engine is initialized with glShadeModel(GL_FLAT))
			##f.write(indent(3) + "shading flat\n")
			# texture
			if (self.face.mode & Blender.Mesh.FaceModes['TEX']) and (self.face.image):
				# 0.0-heightMap
				if disptex:
					self._exportTextureUnit(f, "heightMap", disptex)

				# 0-diffuse
				f.write(indent(3)+"texture_unit baseMap\n")
				f.write(indent(3)+"{\n")
				f.write(indent(4)+"texture %s\n" % self.manager.registerTextureImage(self.face.image))
				f.write(indent(3)+"}\n") # texture_unit
				# 1-specular
				if spectex:
					self._exportTextureUnit(f, "specularMap", spectex)
				# 2-normal
				if len(self.mesh.materials):
					tex = self.findMapToTexture(mat, 'NOR')
					if tex and tex.tex and tex.tex.getImage():
						self._exportTextureUnit(f, "normalMap", tex)
				# 3-lightMap
				if ambtex:
					self._exportTextureUnit(f, "lightMap", ambtex)

				# 4-shadow
				if self.shadows and "Shadow" in self.shader:
					f.write(indent(3)+"texture_unit shadowMap0\n")
					f.write(indent(3)+"{\n")
					f.write(indent(4)+"content_type shadow\n")
					f.write(indent(4)+"tex_address_mode clamp\n")
					f.write(indent(3)+"}\n") # texture_unit
					f.write(indent(3)+"texture_unit shadowMap1\n")
					f.write(indent(3)+"{\n")
					f.write(indent(4)+"content_type shadow\n")
					f.write(indent(4)+"tex_address_mode clamp\n")
					f.write(indent(3)+"}\n") # texture_unit
					f.write(indent(3)+"texture_unit shadowMap2\n")
					f.write(indent(3)+"{\n")
					f.write(indent(4)+"content_type shadow\n")
					f.write(indent(4)+"tex_address_mode clamp\n")
					f.write(indent(3)+"}\n") # texture_unit

				# 5-luminanceMap
				# 6-opacityMap
				if textures['alpha']:
					self._exportTextureUnit(f, "opacityMap", textures['alpha'])
				# 7-reflectionMap
				if reftex:
					self._exportTextureUnit(f, "reflectionMap", reftex)
示例#17
0
 def writeProperty(self, f, name, value):
     """
     Write an avatar property
     """
     f.write(indent(1) + '<property name="'+name+'" value="'+value+'" />')
示例#18
0
    def _writeTextureUnits(self, f, mat):
        """
		Write the texture units for the material.
		"""
        textures = self.getTextureLayers(mat)
        spectex = textures['spec']
        nortex = textures['nor']
        reftex = textures['ref']
        ambtex = textures['amb']
        disptex = textures['disp']
        shader = self.shader
        # texture units
        if self.mesh.faceUV:
            # mesh has texture values, resp. tface data
            # scene_blend <- transp
            if (self.face.transp == Blender.Mesh.FaceTranspModes["ALPHA"]):
                f.write(indent(3) + "scene_blend alpha_blend \n")
            elif (self.face.transp == Blender.NMesh.FaceTranspModes["ADD"]):
                f.write(indent(3) + "scene_blend add\n")
            # cull_hardware/cull_software
            if (self.face.mode & Blender.Mesh.FaceModes['TWOSIDE']):
                f.write(indent(3) + "cull_hardware none\n")
                f.write(indent(3) + "cull_software none\n")
            # shading
            # (Blender's game engine is initialized with glShadeModel(GL_FLAT))
            ##f.write(indent(3) + "shading flat\n")
            # texture
            if (self.face.mode
                    & Blender.Mesh.FaceModes['TEX']) and (self.face.image):
                # 0.0-heightMap
                if disptex:
                    self._exportTextureUnit(f, "heightMap", disptex)

                # 0-diffuse
                f.write(indent(3) + "texture_unit baseMap\n")
                f.write(indent(3) + "{\n")
                f.write(
                    indent(4) + "texture %s\n" %
                    self.manager.registerTextureImage(self.face.image))
                f.write(indent(3) + "}\n")  # texture_unit
                # 1-specular
                if spectex:
                    self._exportTextureUnit(f, "specularMap", spectex)
                # 2-normal
                if len(self.mesh.materials):
                    tex = self.findMapToTexture(mat, 'NOR')
                    if tex and tex.tex and tex.tex.getImage():
                        self._exportTextureUnit(f, "normalMap", tex)
                # 3-lightMap
                if ambtex:
                    self._exportTextureUnit(f, "lightMap", ambtex)

                # 4-shadow
                if self.shadows and "Shadow" in self.shader:
                    f.write(indent(3) + "texture_unit shadowMap0\n")
                    f.write(indent(3) + "{\n")
                    f.write(indent(4) + "content_type shadow\n")
                    f.write(indent(4) + "tex_address_mode clamp\n")
                    f.write(indent(3) + "}\n")  # texture_unit
                    f.write(indent(3) + "texture_unit shadowMap1\n")
                    f.write(indent(3) + "{\n")
                    f.write(indent(4) + "content_type shadow\n")
                    f.write(indent(4) + "tex_address_mode clamp\n")
                    f.write(indent(3) + "}\n")  # texture_unit
                    f.write(indent(3) + "texture_unit shadowMap2\n")
                    f.write(indent(3) + "{\n")
                    f.write(indent(4) + "content_type shadow\n")
                    f.write(indent(4) + "tex_address_mode clamp\n")
                    f.write(indent(3) + "}\n")  # texture_unit

                # 5-luminanceMap
                # 6-opacityMap
                if textures['alpha']:
                    self._exportTextureUnit(f, "opacityMap", textures['alpha'])
                # 7-reflectionMap
                if reftex:
                    self._exportTextureUnit(f, "reflectionMap", reftex)