Blender script for import minetest nodes

minetesprogramercor
New member
 
Posts: 3
Joined: Tue Oct 08, 2019 18:49
In-game: None

Blender script for import minetest nodes

by minetesprogramercor » Tue Oct 08, 2019 18:55

First i don't speak English(i speak Spanish)
New version of my script to import minetest nodes in blender.
Requirements:
1-You need to have installed “Blender 2.79”(I dont know if functions in “2.80”)
2-Your operative system must be Linux(only probe in Linux)
Instructions
1-Open Blender.
2-Change the render mode to “Cycles Render”(“Blender Render” is the default).
3-Copy the script in the Blender text editor
4-Run the script(mouse over the blender text editor and (Alt+P) or in the Blender text editor:text>Run Script )
5-Open the new Minetest Panel.
6-Press the Import button.
6.5(Optional:Configure the import whit:The align selector(Line,2DCube),and the Layer option)
7-Select the file from you want to import the nodes(and activate this)
[list=]
0.1
.Puede importar nodos
.Puede representar estos tipos de nodos:plantlike ,node.
0.2
.Al importar los nodos,crea un "grupo para cada nodo".
0.2.1(Grandes correciones)
.No me habia dado cuenta que sin importar que archivos seleccionaras,siempre importaba los nodos del mismo archivo.
.Esto ya esta arreglado.
.Se arreglo un error,que sucedia si no se usaba la opcion separar por tipo.
.Se arreglo un error a la hora de crear un "grupo para cada nodo"(el de la posicion).
.Se arreglo un error a la hora de crear las texturas.
0.3
.Ahora tambien puede representar los siguientes tipos de modos:plantlike_rooted,glasslike_framed_optional,glasslike(en realidad ya lo representaba),
0.3.1
.Arreglados algunos bugs.
.Pequennas mejoras.
0.4
.Ahora puede representar materiales transparentes.
[/list]

Code: Select all
#Este script puede importar los nodos del minetest desde un archivo "lua".
#This script can import the minetest nodes from a "lua" file.

import os
import bpy

bpy.context.scene.render.engine = "CYCLES"
bpy.mnlocatx = 0
bpy.mnlocaty = 0
bpy.mnlocatz = 0
bpy.nodecount = 0

def importnoddesexec(path,aligopt="linear",slayers = "False"):
    def importnode(archivo = path):
        lx,ly,lz = (bpy.mnlocatx,bpy.mnlocaty,bpy.mnlocatz)
        o = open(archivo,"r")
        nodecount = bpy.nodecount
        e  = 0
        inicp = False
        tileini = False
        texturelist = []
        ndrawtype = None
        d = 0
        nodo = ""
        texture = None
        plantheig = None
        for lines in o.readlines():
            if lines.find("minetest.register_node(") == 0 and inicp==False: #and d == 0:
                texturelist = []
                inicp= True
                e = e+1
                try:
                    nodo = lines.split('"')[1]
                except:
                    #texturelist[-1] = texturelist[-1].replace("(","") 
                    nodo = lines.split('(')[1]
                    nodo = nodo.replace(",","")
                    nodo = nodo.replace("{","")
            elif inicp== True:
                if lines.find("tiles = {") > 0 or lines.find("tiles={") > 0 or lines.find("tiles= {") > 0 or lines.find("tiles= {") > 0:
                    tileini = True
                if lines.find("drawtype ") > 0:
                    ndrawtype = lines.split("=")[1]
                    ndrawtype = ndrawtype.split(",")[0]
                if lines.find("local height ") > 0:
                    plantheig = [n for n in lines if n.isnumeric()]
                if tileini == True:
                    if lines.find(".png") >0:
                        if lines.split('"').__len__() >= 3:
                            if lines.split('"')[1].find("^")>0:
                                texturelist.append(lines.split('"')[1].split("^")[1])
                                if texturelist[-1].endswith(".png") == False:
                                     texturelist[-1] = lines.split('"')[1].split("^")[0]       
                            else:
                                texturelist.append(lines.split('"')[1])
                            texturelist[-1] = texturelist[-1].replace("(","") 
                    if lines.find("},")>0:
                        tileini = False           
            if lines.find("})") == 0 and inicp== True:# and texturelist != []:
                d = 1
                inicp= False
                if bpy.data.objects.find(nodo) == -1:
                    def cmaterial(mname = nodo):
                        if bpy.data.materials.find(mname) != -1:
                            bpy.data.materials.remove(bpy.data.materials[mname])
                           
                        if bpy.data.materials.find("Material") == -1:
                            print("No existe el material")
                        else:
                            bpy.data.materials.remove(bpy.data.materials['Material'])
                           
                        def cleanlist(list):
                            for i in list:
                                if i.endswith(".png") == False:
                                    list.remove(i)
                            for i in list:
                                print(list)
                                list[list.index(i)] = i.replace(",","").replace("{","").replace("^","")
                                print(list,"repl")
                               
                        cleanlist(texturelist)
                       
                        bpy.ops.material.new()

                        material = bpy.data.materials["Material"]

                        material.node_tree.nodes.new("ShaderNodeMixRGB")

                        def linknodes(input,output):
                            material.node_tree.links.new(input,output)
                           
                        material.node_tree.nodes['Mix'].location[1] = 300
                        material.node_tree.nodes['Mix'].location[0] = -300

                        material.node_tree.nodes.new("ShaderNodeMixRGB")

                        material.node_tree.nodes['Mix.001'].location[1] = 300
                        material.node_tree.nodes['Mix.001'].location[0] = -600

                        linknodes(material.node_tree.nodes['Diffuse BSDF'].inputs['Color'],material.node_tree.nodes['Mix'].outputs['Color'])
                        linknodes(material.node_tree.nodes['Mix'].inputs[1],material.node_tree.nodes['Mix.001'].outputs['Color'])

                        material.node_tree.nodes.new("ShaderNodeTexImage")
                        material.node_tree.nodes['Image Texture'].location[1] = 600
                        material.node_tree.nodes['Image Texture'].location[0] = -900

                        material.node_tree.nodes.new("ShaderNodeTexImage")
                        material.node_tree.nodes['Image Texture.001'].location[1] = 300
                        material.node_tree.nodes['Image Texture.001'].location[0] = -900

                        material.node_tree.nodes.new("ShaderNodeTexImage")
                        material.node_tree.nodes['Image Texture.002'].location[1] = 0
                        material.node_tree.nodes['Image Texture.002'].location[0] = -900

                        linknodes(material.node_tree.nodes['Mix.001'].inputs[1],material.node_tree.nodes['Image Texture'].outputs['Color'])
                        linknodes(material.node_tree.nodes['Mix.001'].inputs[2],material.node_tree.nodes['Image Texture.001'].outputs['Color'])
                        linknodes(material.node_tree.nodes['Mix'].inputs[2],material.node_tree.nodes['Image Texture.002'].outputs['Color'])

                        material.node_tree.nodes.new("ShaderNodeCombineXYZ")
                        material.node_tree.nodes['Combine XYZ'].location[1] = 600
                        material.node_tree.nodes['Combine XYZ'].location[0] = -1200

                        material.node_tree.nodes.new("ShaderNodeCombineXYZ")
                        material.node_tree.nodes['Combine XYZ.001'].location[1] = 300
                        material.node_tree.nodes['Combine XYZ.001'].location[0] = -1200

                        material.node_tree.nodes.new("ShaderNodeCombineXYZ")
                        material.node_tree.nodes['Combine XYZ.002'].location[1] = 0
                        material.node_tree.nodes['Combine XYZ.002'].location[0] = -1200

                        linknodes(material.node_tree.nodes['Image Texture'].inputs[0],material.node_tree.nodes['Combine XYZ'].outputs[0])
                        linknodes(material.node_tree.nodes['Image Texture.001'].inputs[0],material.node_tree.nodes['Combine XYZ.001'].outputs[0])
                        linknodes(material.node_tree.nodes['Image Texture.002'].inputs[0],material.node_tree.nodes['Combine XYZ.002'].outputs[0])

                        material.node_tree.nodes.new("ShaderNodeSeparateXYZ")
                        material.node_tree.nodes['Separate XYZ'].location[1] = 300
                        material.node_tree.nodes['Separate XYZ'].location[0] = -1500

                        linknodes(material.node_tree.nodes['Combine XYZ'].inputs[0],material.node_tree.nodes['Separate XYZ'].outputs[0])
                        linknodes(material.node_tree.nodes['Combine XYZ'].inputs[1],material.node_tree.nodes['Separate XYZ'].outputs[1])

                        linknodes(material.node_tree.nodes['Combine XYZ.001'].inputs[0],material.node_tree.nodes['Separate XYZ'].outputs[1])
                        linknodes(material.node_tree.nodes['Combine XYZ.001'].inputs[1],material.node_tree.nodes['Separate XYZ'].outputs[2])

                        linknodes(material.node_tree.nodes['Combine XYZ.002'].inputs[0],material.node_tree.nodes['Separate XYZ'].outputs[0])
                        linknodes(material.node_tree.nodes['Combine XYZ.002'].inputs[1],material.node_tree.nodes['Separate XYZ'].outputs[2])

                        material.node_tree.nodes.new("ShaderNodeTexCoord")
                        material.node_tree.nodes['Texture Coordinate'].location[1] = 300
                        material.node_tree.nodes['Texture Coordinate'].location[0] = -1800
                       
                        linknodes(material.node_tree.nodes['Separate XYZ'].inputs[0],material.node_tree.nodes['Texture Coordinate'].outputs[0])
                       
                        material.node_tree.nodes.new("ShaderNodeMath")
                        material.node_tree.nodes['Math'].location[1] = 900
                        material.node_tree.nodes['Math'].location[0] = -900
                        material.node_tree.nodes['Math'].operation = "ABSOLUTE"
                       
                        linknodes(material.node_tree.nodes['Mix'].inputs[0],material.node_tree.nodes['Math'].outputs[0])
                       
                        material.node_tree.nodes.new("ShaderNodeMath")
                        material.node_tree.nodes['Math.001'].location[1] = 1200
                        material.node_tree.nodes['Math.001'].location[0] = -900
                        material.node_tree.nodes['Math.001'].operation = "ABSOLUTE"
                       
                        linknodes(material.node_tree.nodes['Mix.001'].inputs[0],material.node_tree.nodes['Math.001'].outputs[0])
                       
                        material.node_tree.nodes.new("ShaderNodeSeparateXYZ")
                        material.node_tree.nodes['Separate XYZ.001'].location[1] = 1200
                        material.node_tree.nodes['Separate XYZ.001'].location[0] = -1500
                       
                        linknodes(material.node_tree.nodes['Math'].inputs[0],material.node_tree.nodes['Separate XYZ.001'].outputs[1])
                        linknodes(material.node_tree.nodes['Math.001'].inputs[0],material.node_tree.nodes['Separate XYZ.001'].outputs[0])
                       
                       
                        linknodes(material.node_tree.nodes['Separate XYZ.001'].inputs[0],material.node_tree.nodes['Texture Coordinate'].outputs[1])
                       
                        #Aplicando transparencia
                        material.node_tree.nodes.new("ShaderNodeMixRGB")

                        material.node_tree.nodes['Mix.002'].location[1] = 500
                        material.node_tree.nodes['Mix.002'].location[0] = -600
                       
                        material.node_tree.nodes.new("ShaderNodeMixRGB")

                        material.node_tree.nodes['Mix.003'].location[1] = 500
                        material.node_tree.nodes['Mix.003'].location[0] = -300
                       
                       
                        linknodes(material.node_tree.nodes['Mix.002'].inputs[1],material.node_tree.nodes['Image Texture'].outputs['Alpha'])
                        linknodes(material.node_tree.nodes['Mix.002'].inputs[2],material.node_tree.nodes['Image Texture.001'].outputs['Alpha'])
                        linknodes(material.node_tree.nodes['Mix.003'].inputs[2],material.node_tree.nodes['Image Texture.002'].outputs['Alpha'])
                       
                        linknodes(material.node_tree.nodes['Mix.003'].inputs[1],material.node_tree.nodes['Mix.002'].outputs['Color'])
                       
                        linknodes(material.node_tree.nodes['Mix.002'].inputs[0],material.node_tree.nodes['Math.001'].outputs[0])
                        linknodes(material.node_tree.nodes['Mix.003'].inputs[0],material.node_tree.nodes['Math'].outputs[0])
                       
                        material.node_tree.nodes.new("ShaderNodeMixShader")
                       
                        material.node_tree.nodes['Mix Shader'].location[1] = 500
                        material.node_tree.nodes['Mix Shader'].location[0] = 100
                       
                        linknodes(material.node_tree.nodes['Mix Shader'].inputs[2],material.node_tree.nodes['Diffuse BSDF'].outputs[0])
                       
                        linknodes(material.node_tree.nodes['Mix Shader'].inputs[0],material.node_tree.nodes['Mix.003'].outputs[0])
                       
                        material.node_tree.nodes.new("ShaderNodeBsdfTransparent")
                       
                        linknodes(material.node_tree.nodes['Mix Shader'].inputs[1],material.node_tree.nodes['Transparent BSDF'].outputs[0])
                       
                        material.node_tree.nodes['Transparent BSDF'].location[1] = 100
                        material.node_tree.nodes['Transparent BSDF'].location[0] = 0

                       
                       
                        linknodes(material.node_tree.nodes['Material Output'].inputs[0],material.node_tree.nodes['Mix Shader'].outputs[0])

                        #####
                       
                       
                        material.node_tree.nodes['Image Texture'].interpolation = "Closest"
                        material.node_tree.nodes['Image Texture.001'].interpolation = "Closest"
                        material.node_tree.nodes['Image Texture.002'].interpolation = "Closest"
                        material.node_tree.nodes['Image Texture'].extension = "EXTEND"
                        material.node_tree.nodes['Image Texture.001'].extension = "EXTEND"
                        material.node_tree.nodes['Image Texture.002'].extension = "EXTEND"
                       
                        if texturelist.__len__() == 1:
                            try:
                                material.node_tree.nodes['Image Texture'].image = bpy.data.images[texturelist[0]]
                                material.node_tree.nodes['Image Texture.001'].image = bpy.data.images[texturelist[0]]
                                material.node_tree.nodes['Image Texture.002'].image = bpy.data.images[texturelist[0]]
                            except KeyError:
                                print("KeyError")
                        elif texturelist.__len__() == 2:
                            try:
                                material.node_tree.nodes['Image Texture'].image = bpy.data.images[texturelist[0]]
                            except:
                                material.node_tree.nodes['Image Texture.001'].image = bpy.data.images[texturelist[1]]
                            material.node_tree.nodes['Image Texture.001'].image = bpy.data.images[texturelist[1]]
                            material.node_tree.nodes['Image Texture.002'].image = bpy.data.images[texturelist[1]]
                        elif texturelist.__len__() > 2:
                            try:
                                material.node_tree.nodes['Image Texture'].image = bpy.data.images[texturelist[0]]
                                material.node_tree.nodes['Image Texture.001'].image = bpy.data.images[texturelist[1]]
                                material.node_tree.nodes['Image Texture.002'].image = bpy.data.images[texturelist[2]]
                            except:
                                material.node_tree.nodes['Image Texture'].image = bpy.data.images[texturelist[1]]
                                material.node_tree.nodes['Image Texture.001'].image = bpy.data.images[texturelist[2]]
                                material.node_tree.nodes['Image Texture.002'].image = bpy.data.images[texturelist[3]]
                        material.name = mname
                       
                    def all(glasssection = "X"):
                       
                        if ndrawtype == ' "glasslike_framed_optional"':
                            if glasssection == "X":
                                cmaterial()
                                bpy.context.object.name = nodo + "sectX"
                            elif glasssection == "L":
                                bpy.context.object.name = nodo + "sectL"
                            elif glasssection == "T":
                                bpy.context.object.name = nodo + "sectT"
                            elif glasssection == "X":
                                bpy.context.object.name = nodo + "sectI"
                        else:
                            bpy.context.object.name = nodo
                            cmaterial()
                           
                        #Creando el grupo.
                        #Creating the group.
                        #Verify if the group exist in this case,is remplaced by the new group.
                        if bpy.data.groups.find(nodo) != -1:
                            bpy.data.groups.remove(bpy.data.groups[nodo])
                        bpy.ops.group.create(name=nodo)
                       
                        grupo = bpy.data.groups[nodo].dupli_offset
                        grupo[0],grupo[1],grupo[2] = bpy.context.object.location
                           
                        if bpy.context.object.material_slots.items() == []:
                            bpy.ops.object.material_slot_add()
                            bpy.context.object.material_slots[''].material = bpy.data.materials[nodo]
                       
                       
                    #Layers
                    grllayers = bpy.context.scene.layers[0:]
                    sgtlayers = bpy.context.scene.layers[0:]
                    glastlayers = bpy.context.scene.layers[0:]
                   
                    # "glasslike_framed_optional"
                    if slayers == True:
                        grllayers = (False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
                        sgtlayers = (False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
                        glastlayers = (False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
                       
                    if ndrawtype == ' "plantlike"' or ndrawtype == ' "plantlike_rooted"':
                        bpy.ops.mesh.primitive_plane_add(location = (lx,ly,lz),radius=0.5, view_align=False, enter_editmode=False)#, #layers=grllayers)
                        bpy.ops.object.editmode_toggle()
                        bpy.ops.transform.rotate(value=-1.5708, axis=(0, 1, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.mesh.primitive_plane_add(location = (lx,ly,lz),radius=0.5, view_align=False, enter_editmode=False)#, layers=grllayers)
                        bpy.ops.transform.rotate(value=-1.5708, axis=(0, 1, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.rotate(value=-1.5708, axis=(0, 0, 1), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.editmode_toggle()
                       
                        if slayers == True:
                            bpy.ops.object.move_to_layer(layers=(False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
                        all()
                    elif ndrawtype == ' "glasslike_framed_optional"':
                        grllayers = bpy.context.scene.layers[0:]
                        sgtlayers = bpy.context.scene.layers[0:]
                       
                        #Creando la cruz
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.object.editmode_toggle()
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.editmode_toggle()
                        all("X")
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 1, 0), "constraint_axis":(True, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(1, -1, 0), "constraint_axis":(True, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-1, -1, -0), "constraint_axis":(True, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(-1, 1, 0), "constraint_axis":(True, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        #Haciendo la L
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.object.editmode_toggle()
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.resize(value=(0.5, 0.5, 0.5), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(0, -0.25, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.resize(value=(0.5, 0.5, 0.5), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(0.25, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        bpy.ops.object.editmode_toggle()
                       
                        all("L")
                        bpy.ops.transform.translate(value=(-1, 1, 0), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=1.5708, axis=(-0, -0, -1), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(2, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=-1.5708, axis=(0, 0, 1), constraint_axis=(False, False, True), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(0, -2, 0), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=1.5708, axis=(-0, -0, -1), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(-2, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                       
                       
                        #Haciendo la I

                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.object.editmode_toggle()
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.editmode_toggle()
                       
                        all("I")
                        bpy.ops.transform.translate(value=(-2, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(4, 0, 0), "constraint_axis":(True, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=1.5708, axis=(-0, -0, -1), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(-2, -2, -0), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 4, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})

                        #Haciendo la T
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.object.editmode_toggle()
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,view_align=False, enter_editmode=False, location=(lx + 4, ly+4, 0), layers=glastlayers)
                        bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(False, True, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.resize(value=(0.5, 0.5, 0.5), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(0.25, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        bpy.ops.object.editmode_toggle()
                        bpy.ops.transform.translate(value=(-3, 0, 0), constraint_axis=(True, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, release_confirm=True, use_accurate=False)
                        all("T")
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=1.5708, axis=(-0, -0, -1), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(3, 3, 0), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=1.5708, axis=(-0, -0, -1), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(3, -3, 0), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        bpy.ops.transform.rotate(value=1.5708, axis=(-0, -0, -1), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                        bpy.ops.transform.translate(value=(-3, -3, -0), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1)
                       
                    elif ndrawtype == ' "signlike"':
                        bpy.ops.mesh.primitive_plane_add(location = (lx,ly,lz),radius=0.5, view_align=False, enter_editmode=False, layers=sgtlayers)
                        all()
                    else:
                        bpy.ops.mesh.primitive_cube_add(radius = 0.5,location = (lx,ly,lz))
                        all()
                   
                    if ndrawtype == ' "plantlike_rooted"' and plantheig != "":
                        import random
                        for i in range(1,random.randrange(int(plantheig[0]),int(plantheig[1]))):
                            bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 1), "constraint_axis":(False, False, True), "constraint_orientation":'GLOBAL', "mirror":False, "proportional":'DISABLED', "proportional_edit_falloff":'SMOOTH', "proportional_size":1, "snap":False, "snap_target":'CLOSEST', "snap_point":(0, 0, 0), "snap_align":False, "snap_normal":(0, 0, 0), "gpencil_strokes":False, "texture_space":False, "remove_on_cancel":False, "release_confirm":False, "use_accurate":False})
                        if slayers == True:
                            bpy.ops.object.move_to_layer(layers=(False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))

                    if aligopt == "linear":
                        lx = lx+1
                    elif aligopt == "2dcube":
                        lx = lx+1
                        if nodecount > 10:
                            lx = 0
                            nodecount = 0
                            ly = ly+1
                    if ndrawtype == ' "glasslike_framed_optional"':
                        lx = lx +12
                    nodecount = nodecount+1
                   
                    if nodecount >400:
                        bpy.ops.object.move_to_layer(layers=(False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False))
                    elif nodecount >300:
                        bpy.ops.object.move_to_layer(layers=(False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False))
                    elif nodecount >200:
                        bpy.ops.object.move_to_layer(layers=(False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False))
                    elif nodecount >100:
                        bpy.ops.object.move_to_layer(layers=(False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True))
                   
                    ndrawtype = ""
                    plantheig = ""
         
        o.close()
        bpy.mnlocatx,bpy.mnlocaty,bpy.mnlocatz,bpy.nodecount = (lx,ly,lz,nodecount)
    importnode()
    return {'FINISHED'}

bl_info = {#Metadato que contiene informacion sobre el script o add-on.
    "name": "Import Nodes",
    "author": "Lazaro",
    "version": (0, 3.1),
    "location": "View3D > Properties > Minetest",
    "description": "A buton to 'Minetest Panel' who inmports nodes of Minetest from a .lua file ",
    "category": "Minetest"}


from bpy_extras.io_utils import ImportHelper
class ImportMinetestNodesfromfile(bpy.types.Operator,ImportHelper):
    """My Object Moving Script"""     
    bl_idname = "minetest.impornodes"   
    bl_label = "Minetest:Import Nodes"   
    bl_options = {'REGISTER', 'UNDO'} 
       
    from bpy.props import StringProperty, BoolProperty, EnumProperty
   
    filename_ext = ".lua"
   
    filter_glob = StringProperty(
            default="*.lua",
            options={'HIDDEN'},
            maxlen=255,  # Max internal buffer length, longer would be clamped.
        )
    option1 = EnumProperty(
            name="Alig",
            description="Form in whit location the nodes",
            items=(
                ('linear', "Linear", "Form of Line"),
                ('2dcube', "2D Cube", "Form of 2DCube"),
            ),
            default='linear',
        )
    option2 = BoolProperty(
            name="Separate by type",
            description="Separate the create nodes by layers",
            default=False,
        )
   
    def execute(self, context):       
        #Funcion que crea las texturas
        #Function who creates the textures.
        import glob
        def importtexture(archivo = ""):
            def importimage():
                for im in list([ip for ip in glob.glob(archivo+"/**",recursive = True) if os.path.splitext((os.path.basename(ip)))[1] == ".png" ]):
                    if bpy.data.images.find(im) != -1:
                        bpy.data.images.remove(bpy.data.images[im])
                    bpy.ops.image.open(filepath = im)
            importimage()
            for im in list([ip for ip in glob.glob(archivo+"/**",recursive = True) if os.path.splitext((os.path.basename(ip)))[1] == ".png" ]):
                if bpy.data.textures.find(im) == -1:
                    if bpy.data.textures.find("Textura") == -1:
                        bpy.ops.texture.new()
                        bpy.data.textures["Texture"].image = bpy.data.images[os.path.basename(im)]
                        bpy.data.textures["Texture"].name = os.path.basename(im)
                    else:
                        bpy.data.textures["Texture"].image = bpy.data.images[os.path.basename(im)]
                        bpy.data.textures["Texture"].name = os.path.basename(im)
                elif bpy.data.textures.find(os.path.basename(im)) != -1:
                    bpy.data.textures.remove(bpy.data.textures[os.path.basename(im)])
       
        if os.path.splitext((os.path.basename(self.filepath)))[1] == ".lua":
            texture = os.path.dirname(self.filepath) + "/textures"
            importtexture(os.path.dirname(self.filepath))
                 # Lets Blender know the operator finished successfully.
            importnoddesexec(self.filepath,self.option1,self.option2) 
            print("bpy.mnlocatx",bpy.mnlocatx)
        else:
            prpath = os.path.dirname(self.filepath)
            importtexture(os.path.dirname(prpath))
            for i in list([f for f in glob.glob(prpath+"/**",recursive = True) if os.path.splitext((os.path.basename(f)))[1] == ".lua" ]):
                importnoddesexec(i,self.option1,self.option2)
                print("bpy.mnlocatx",bpy.mnlocatx)
           
        return {'FINISHED'}


class MinetestImportNodesPanel(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_context = "objectmode"
    bl_label = "Import Nodes"
    bl_region_type = "TOOLS"
    bl_category = "Minetest"   
   
    def draw(self,context):
        layout = self.layout
       
        row = layout.row()
        row.scale_y = 1.0
        row.operator("minetest.impornodes",text = "Import")
   
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
    self.layout.operator(ImportMinetestNodesfromfile.bl_idname, text="Text Import Operator")

def register():
    print("The Minetest Panel was created")
    bpy.utils.register_class(MinetestImportNodesPanel)
    bpy.utils.register_class(ImportMinetestNodesfromfile)
    bpy.types.INFO_MT_file_import.append(menu_func_import)
def unregister():
    print("Closing the Minetest Panel")
    bpy.utils.register_class(MinetestImportNodesPanel)
    bpy.utils.unregister_class(ImportMinetestNodesfromfile)
    bpy.types.INFO_MT_file_import.remove(menu_func_import)
   
if __name__ == "__main__":#Esto permite correr el script desde el editor de texto de Blender.
    register()
 

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 0 guests