Exemplo n.º 1
0
def setMesh(bmesh, ob, matrix=None):
    """ Update a mesh from a bmesh object
	"""
    #Before setting mesh data assign matrix:
    if matrix is not None:
        ob.matrix_world = matrix
    bmesh.normal_update()
    bmesh.to_mesh(ob.data)
    return ob
Exemplo n.º 2
0
def setMesh(bmesh, ob, matrix = None) :
	""" Update a mesh from a bmesh object
	"""
	#Before setting mesh data assign matrix:
	if matrix is not None :
		ob.matrix_world = matrix
	bmesh.normal_update()
	bmesh.to_mesh(ob.data)
	return ob
Exemplo n.º 3
0
Arquivo: tools.py Projeto: katosh/sym
def bmesh_write(bmesh, obj):
    """ writes the bmesh to the object
    independent of current mode """
    toggle = False
    if obj.mode == 'EDIT':
        bpy.ops.object.editmode_toggle()
        toggle = True
    bmesh.to_mesh(obj.data)
    if toggle: bpy.ops.object.editmode_toggle()
Exemplo n.º 4
0
def setNamedMesh(bmesh, object_name, scene = None, matrix = None) :
	""" Update a mesh from a bmesh object name
	"""
	try :
		ob = getObject(object_name)
		#Before setting mesh data assign matrix:
		if matrix is not None :
			ob.matrix_world = matrix
		bmesh.normal_update()
		bmesh.to_mesh(ob.data)
		return ob
	except :
		return createMesh(bmesh, scene, object_name)
Exemplo n.º 5
0
def setNamedMesh(bmesh, object_name, scene=None, matrix=None):
    """ Update a mesh from a bmesh object name
	"""
    try:
        ob = getObject(object_name)
        #Before setting mesh data assign matrix:
        if matrix is not None:
            ob.matrix_world = matrix
        bmesh.normal_update()
        bmesh.to_mesh(ob.data)
        return ob
    except:
        return createMesh(bmesh, scene, object_name)
Exemplo n.º 6
0
def createMesh(bmesh, scene = None, matrix = None, name = "Object") :
	"""
	Create a blender mesh object from a specified bmesh and context
	bmesh:		Mesh to create a object for
	scene:		Scene the new object will be added to
	name:		Name of the object added 
	"""
	mesh = bpy.data.meshes.new(name + "_Mesh") 		# create a new mesh with the name
	newOb = bpy.data.objects.new(name, mesh)	# create an object with that mesh
	if matrix is not None :
		newOb.matrix_world = matrix
	#Link to scene
	if scene is not None :
		scene.objects.link(newOb)         	
	bmesh.to_mesh(newOb.data)					
	return newOb
Exemplo n.º 7
0
def createMesh(bmesh, scene=None, matrix=None, name="Object"):
    """
	Create a blender mesh object from a specified bmesh and context
	bmesh:		Mesh to create a object for
	scene:		Scene the new object will be added to
	name:		Name of the object added 
	"""
    mesh = bpy.data.meshes.new(name +
                               "_Mesh")  # create a new mesh with the name
    newOb = bpy.data.objects.new(name, mesh)  # create an object with that mesh
    if matrix is not None:
        newOb.matrix_world = matrix
    #Link to scene
    if scene is not None:
        scene.objects.link(newOb)
    bmesh.to_mesh(newOb.data)
    return newOb
Exemplo n.º 8
0
def AddBrick(blPath, filePath, BrickName, PosX, PosY, PosZ, Angle, Color,
             Print, Rendering, normalmap, joinbricks, BLSCol):
    import re
    import os
    import bpy, bmesh

    BrickName = BrickName.replace('�', '°')
    pattern = re.compile("BLS_*")

    if Rendering == 0:
        return

    filepath = os.path.join(blPath + "BLS_Bricks", BrickName + '.blb')

    file = open(filepath)

    line = file.readline()
    line = file.readline()

    if line == 'BRICK':
        return {'Brick importer does not handle cubic type'}

    # mesh, obj
    mesh = bpy.data.meshes.new("BLS_" + BrickName + '_m')
    obj = bpy.data.objects.new("BLS_" + BrickName, mesh)
    obj.show_transparent = True
    BLSCol.objects.link(obj)

    # bmesh
    global bmesh
    bmesh = bmesh.new()
    bmesh.from_mesh(mesh)
    Layer = bmesh.loops.layers.uv.new()

    while line:
        if 'TEX:' in line:
            Tex = line.replace('TEX:', '').replace('\n', '')

            AddTex(blPath, Tex)

            POSH = file.readline().replace('\n', '')  #Position Header
            POS1 = (' '.join(file.readline().split())).split()
            POS2 = (' '.join(file.readline().split())).split()
            POS3 = (' '.join(file.readline().split())).split()
            POS4 = (' '.join(file.readline().split())).split()

            NewFace = AddFace(bmesh, POS1, POS2, POS3, POS4)

            UVH = file.readline().replace('\n', '')  # UV Header
            UV1 = (' '.join(file.readline().split())).split()
            UV2 = (' '.join(file.readline().split())).split()
            UV3 = (' '.join(file.readline().split())).split()
            UV4 = (' '.join(file.readline().split())).split()

            NewFace = AddUV(NewFace, UV1, UV2, UV3, UV4, Layer, Tex, Angle)

            CNH = file.readline().replace('\n', '')  # Color or Normal Header

            if CNH == 'COLORS:':
                C1 = (' '.join(file.readline().split())).split()
                C2 = (' '.join(file.readline().split())).split()
                C3 = (' '.join(file.readline().split())).split()
                C4 = (' '.join(file.readline().split())).split()
                H = file.readline().replace('\n', '')  # Normal Header

                AddMat(normalmap, obj, Tex, C1)
                SetMat(obj, NewFace, Tex, C1)
            else:
                AddMat(normalmap, obj, Tex, Color)
                SetMat(obj, NewFace, Tex, Color)

        try:
            line = file.readline()
        except StopIteration:
            break

    file.close()
    print("Created mesh for brick %s!" % BrickName)
    bmesh.to_mesh(mesh)

    bpy.ops.object.select_all(action='DESELECT')
    obj.select_set(True)
    bpy.context.view_layer.objects.active = obj

    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_all(action='TOGGLE')
    bpy.ops.mesh.normals_make_consistent(inside=True)
    bpy.ops.mesh.select_all(action='TOGGLE')
    bpy.ops.object.mode_set(mode='OBJECT')

    bpy.ops.transform.rotate(value=((-1.5708) * float(Angle) * -1))
    bpy.ops.transform.translate(value=(float(PosX) * 2, float(PosY) * 2,
                                       float(PosZ) * 2))

    bpy.ops.object.transform_apply(rotation=True)
    bpy.ops.object.select_all(action='TOGGLE')

    if joinbricks:
        for ob in bpy.context.visible_objects:
            if ob.type != 'MESH':
                continue

            match = pattern.match(ob.name)
            if match == None:
                print("No match for %s" % ob.name)
            else:
                print("Found matched object %s!" % match.group())
                ob.select_set(True)

        bpy.ops.object.join()
        # deselect everything before the next iteration
        bpy.ops.object.select_all(action='DESELECT')

    return