示例#1
0
def geometryExport(scene,typeOfGeometry='geometry',skipOthersGeometries=False):
	buffer=_geometryHeader
	actors=[]
	actors=Acoustic.getActors()
#	print "---------- acoustic actors: %s" % list(actors)
#	for object in scene.objects:
#	print "---------- acoustic objects: %s" % list(Acoustic.getAcousticObjects(scene))
	for object in Acoustic.getAcousticObjects(scene):
		if skipOthersGeometries and Acoustic.getObjectSoundTypeGameProperty(object) != typeOfGeometry:
			continue

		impedance=None
		diffusion=None
		materialName=""
		print "Reading object: %s" % object.name
#		data=bpy.data.meshes[object.getData().name]
		if type(object.getData())!=Blender.Types.NMeshType:
			print "no mesh, skipping..."
			continue
		if actors.count(object)!=0:
			print "%s is an actor, skipping" % object.name
			continue
		materials=Acoustic.getObjectMaterials(object)
		if (materials==None or materials==[]): 
			print "\tdoesn't contains acoustic materials,",
			if Acoustic.getObjectSoundTypeGameProperty(object) != typeOfGeometry:
				print 'no game object property "sound_type"=="%s", skipping...' % typeOfGeometry
				continue #if doesnt have any acoustic (by name) material, doesnt export
			print 'WARNING: setting material as "%s", with default acoustic properties (impedance: %s, diff.: %s)' % (_defaultMaterialName,str(_defaultImpedance),str(_defaultDiffusion))
			impedance=_defaultImpedance
			diffusion=_defaultDiffusion
			materialName=_defaultMaterialName
		BPyNMesh.ApplySizeAndRotation(object)
		data=object.getData(False,True) # get mesh instead name or NMesh (name_only=False / mesh=True)
		print "Exporting %s..."%object.name
		bufferObject= "<%s>\n" % object.name
		bufferObject+= "<VERTS>\n"
		location=object.mat.translationPart()
		for vert in data.verts:
			bufferObject+="%f %f %f\n" % (vert.co[0]+location[0],vert.co[1]+location[1],vert.co[2]+location[2])
		bufferObject+="<FACES>\n"

		if impedance==None and diffusion==None: # it doesn't have assigned the default material
			# use first linked material with acoustic properties 
			for material in materials:
				print material.name
				impedance=Acoustic.getImpedance(material)
				if (impedance==None):
					continue
				diffusion=Acoustic.getDiffusion(material)
				if (diffusion==None):
					continue
				materialName=material.name
				break
		if (impedance==None) or (diffusion==None):
			print "any material have acoustic parameters, skipping..."
			continue 
		impedanceReal=impedance.real
		impedanceImag=impedance.imag
		if _convertToTriangles==True:
			print "Converting mesh to triangles..."
			Blender.Mesh.Mode(3) # select faces
			Blender.Window.EditMode(0) # non-edit mode!
			data.quadToTriangle(0)
		for face in data.faces:
			verts=""
			vertCount=0
			for vert in face.verts:
				vertCount+=1
				verts+="%s " % str(vert.index+1)
			if vertCount>3:
				print "WARNING!! Object %s have more than 3 verts (%i) per face!!!" % (object.name,vertCount)
			bufferObject+=FaceLineTemplate % vars()
		buffer+=bufferObject
		print "Added Object: %s" % object.name
	return buffer	
示例#2
0
def geometryExport(scene,
                   typeOfGeometry='geometry',
                   skipOthersGeometries=False):
    buffer = _geometryHeader
    actors = []
    actors = Acoustic.getActors()
    #	print "---------- acoustic actors: %s" % list(actors)
    #	for object in scene.objects:
    #	print "---------- acoustic objects: %s" % list(Acoustic.getAcousticObjects(scene))
    for object in Acoustic.getAcousticObjects(scene):
        if skipOthersGeometries and Acoustic.getObjectSoundTypeGameProperty(
                object) != typeOfGeometry:
            continue

        impedance = None
        diffusion = None
        materialName = ""
        print "Reading object: %s" % object.name
        #		data=bpy.data.meshes[object.getData().name]
        if type(object.getData()) != Blender.Types.NMeshType:
            print "no mesh, skipping..."
            continue
        if actors.count(object) != 0:
            print "%s is an actor, skipping" % object.name
            continue
        materials = Acoustic.getObjectMaterials(object)
        if (materials == None or materials == []):
            print "\tdoesn't contains acoustic materials,",
            if Acoustic.getObjectSoundTypeGameProperty(
                    object) != typeOfGeometry:
                print 'no game object property "sound_type"=="%s", skipping...' % typeOfGeometry
                continue  #if doesnt have any acoustic (by name) material, doesnt export
            print 'WARNING: setting material as "%s", with default acoustic properties (impedance: %s, diff.: %s)' % (
                _defaultMaterialName, str(_defaultImpedance),
                str(_defaultDiffusion))
            impedance = _defaultImpedance
            diffusion = _defaultDiffusion
            materialName = _defaultMaterialName
        BPyNMesh.ApplySizeAndRotation(object)
        data = object.getData(
            False, True
        )  # get mesh instead name or NMesh (name_only=False / mesh=True)
        print "Exporting %s..." % object.name
        bufferObject = "<%s>\n" % object.name
        bufferObject += "<VERTS>\n"
        location = object.mat.translationPart()
        for vert in data.verts:
            bufferObject += "%f %f %f\n" % (vert.co[0] + location[0],
                                            vert.co[1] + location[1],
                                            vert.co[2] + location[2])
        bufferObject += "<FACES>\n"

        if impedance == None and diffusion == None:  # it doesn't have assigned the default material
            # use first linked material with acoustic properties
            for material in materials:
                print material.name
                impedance = Acoustic.getImpedance(material)
                if (impedance == None):
                    continue
                diffusion = Acoustic.getDiffusion(material)
                if (diffusion == None):
                    continue
                materialName = material.name
                break
        if (impedance == None) or (diffusion == None):
            print "any material have acoustic parameters, skipping..."
            continue
        impedanceReal = impedance.real
        impedanceImag = impedance.imag
        if _convertToTriangles == True:
            print "Converting mesh to triangles..."
            Blender.Mesh.Mode(3)  # select faces
            Blender.Window.EditMode(0)  # non-edit mode!
            data.quadToTriangle(0)
        for face in data.faces:
            verts = ""
            vertCount = 0
            for vert in face.verts:
                vertCount += 1
                verts += "%s " % str(vert.index + 1)
            if vertCount > 3:
                print "WARNING!! Object %s have more than 3 verts (%i) per face!!!" % (
                    object.name, vertCount)
            bufferObject += FaceLineTemplate % vars()
        buffer += bufferObject
        print "Added Object: %s" % object.name
    return buffer