Fandom

Jmc2obj Wiki

Blender

6pages on
this wiki
Add New Page
Comments12 Share

Tutorial videosEdit

See the video tutorials contributed by MyEPICBoredom

GuideEdit

If you do not know already how to use Jmc2obj, please read the How-to article.

Before exporting your world, make sure "Offset" is set to "Center." Otherwise, your selection may not import in the center of the Blender 3D View. You may also want to check "Create separate object for each chunk," which will allow you to hide single chunks. You can also choose "Create separate object for each block," if you'd like. Keep in mind that if you choose either of these options, the file size will increase.

If you export the world with settings as they are, the textures will be blurred. To fix this, set "Pre-scale textures," in Jmc2obj higher (x16 provides highest quality). Note that if you select "Export all textures in a single file," you may need to manually UV map the textures.

Now you are ready to export both the textures and the word itself. Make sure the textures are exported to a "tex" folder inside the location that you export the world, otherwise the textures will not load.

To import the .obj you exported, start Blender and delete the cube. Then, click File in the upper-left, hover your mouse over Import, then select Wavefront (.obj). Now find your .obj file. Once you find it, select it by clicking it, and click Import OBJ in the upper-right. Importing the .obj may take some time, depending on your hardware and the file size.

One thing to note is that the larger the world, the more RAM Blender will use. Be as efficient as possible in exporting your worlds in order to avoid hitting any RAM limits.

ScriptsEdit

(NOTE: These scripts may become outdated with future versions of Blender.)

A script to fix material properties after importing into Blender:

import bpy
import re

for name, texture in bpy.data.textures.items():
    if re.search(r'^(Kd|D)', name):
        # fixup image paths (// means relative to the .blender file)
        texture.image.filepath = re.sub("^.*tex/", "//tex/", texture.image.filepath)

        texture.use_alpha = False
        texture.use_mipmap = False
        texture.use_interpolation = False
        texture.filter_type = 'BOX'

for name, material in bpy.data.materials.items():
    # If the spec color is black, set spec intensity to 0
    # This helps with LuxRender texture conversion because the built-in converter
    # only looks at the intensity and if it's not 0 it'll create a Glossy material
    sc = material.specular_color
    if sc.v == 0.0: 
        material.specular_intensity = 0.0

    material.use_transparent_shadows = True

    material.preview_render_type = 'CUBE'   # seems appropriate :)


The following script is handy if you want to import multiple OBJ files produced by Jmc2obj into blender; when you import multiple OBJs Blender will duplicate the material definitions. This script can be run after the imports to fix that.

# The purpose of this script is to remove duplicate materials caused by importing
# multiple .obj files (generated by jmc2obj) into the same blender file.

import bpy
import re

count = 0
for name, obj in bpy.data.objects.items():
    if obj.type != 'MESH':
        continue

    #print(name)
    for ms in obj.material_slots.values():
        mat_name = ms.material.name

        #print('\t', mat_name, end=)
        if re.search(r'\.[0-9]{3}$', mat_name):
            replace_mat_name = mat_name[:-4]
            if replace_mat_name in bpy.data.materials:
                ms.material = bpy.data.materials[replace_mat_name]
                count += 1
                #print('  ->  ', replace_mat_name, end=)
        #print()

print('Replaced {0} materials.'.format(count))

Rendering with LuxRenderEdit

Using LuxRender to render your Minecraft worlds from Blender can give great results.

This script created by reddit user VeraLapsa automates the process of creating the LuxRender materials after importing an OBJ file into Blender. See the original post for more information.

import bpy, bl_operators
import json, math, os

def apply_blender_texture(report, scene, blender_mat):

    try:
        luxrender_mat = blender_mat.luxrender_material

        if luxrender_mat.type in ('matte'):
            lmmatte = luxrender_mat.luxrender_mat_matte
            lmmatte.Kd_colortexturename = blender_mat.active_texture.name
            lmmatte.Kd_usecolortexture = True
        elif luxrender_mat.type in ('glossy'):
            lmglossy = luxrender_mat.luxrender_mat_glossy
            lmglossy.Kd_colortexturename = blender_mat.active_texture.name
            lmglossy.Kd_usecolortexture = True
        else:
            return

        lmt = blender_mat.luxrender_transparency

        #if blender_mat.name in ('tall_grass'):
        #   lmt.transparent = True
            
        if lmt.transparent:
            lmt.alpha_source = 'texture'
            lmt.alpha_floattexturename = blender_mat.texture_slots[1].name
            lmt.alpha_usefloattexture = True

        if blender_mat.name in ('glass', 'water', 'water_flowing'):
            luxrender_mat.set_type('glass')
            lmglass = luxrender_mat.luxrender_mat_glass
            lmglass.Kr_colortexturename = blender_mat.active_texture.name
            lmglass.Kr_usecolortexture = True
            lmglass.Kt_colortexturename = blender_mat.active_texture.name
            lmglass.Kt_usecolortexture = True
            lmglass.index_floatvalue = 1.52
        if blender_mat.name in ('water', 'water_flowing'):
            lmglass.index_floatvalue = 1.332830
            lmt.transparent = False

        report({'INFO'}, 'Applyed texture "%s" to LuxRender' % blender_mat.name)
    except Exception as err:
        report({'ERROR'}, 'Cannot convert material "%s": %s' % (blender_mat.name, err))
        #print('Material conversion failed on line %d' % err.__traceback__.tb_lineno)


class VERA_convert_all_textures(bpy.types.Operator):
    bl_idname = 'luxrender.convert_all_textures'
    bl_label = 'Convert all Blender textures'

    def execute(self, context):
        for blender_mat in bpy.data.materials:
            # Don't convert materials from linked-in files
            if blender_mat.library == None:
                apply_blender_texture(self.report, context.scene, blender_mat)
                
        return {'FINISHED'}

class VERA_convert_texture(bpy.types.Operator):
    bl_idname = 'luxrender.convert_texture'
    bl_label = 'Convert selected Blender texture'

    material_name = bpy.props.StringProperty(default="")

    def execute(self, context):
        if self.properties.material_name == "":
            blender_mat = context.object.active_material
        else:
            blender_mat = bpy.data.materials[self.properties.material_name]

            apply_blender_texture(self.report, context.scene, blender_mat)
        return {'FINISHED'}

class VERA_MC_Panel(bpy.types.Panel):
    bl_label = "Vera's Minecraft Scripts"
    bl_idname = "OBJECT_PT_Vera_mc_scripts"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"

    def draw(self, context):
        layout = self.layout

        row = layout.row(align=True)
        row.operator("luxrender.convert_all_textures", icon='WORLD_DATA')

        row = layout.row(align=True)
        row.operator("luxrender.convert_texture", icon='MATERIAL_DATA')


def register():
    bpy.utils.register_class(VERA_convert_texture)
    bpy.utils.register_class(VERA_convert_all_textures)
    bpy.utils.register_class(VERA_MC_Panel)

def unregister():
    bpy.utils.unregister_class(VERA_convert_texture)
    bpy.utils.unregister_class(VERA_convert_all_textures)
    bpy.utils.unregister_class(VERA_MC_Panel)

if __name__ == "__main__":
    register()

Rendering with Cycles Edit

If you want to render with cycles - you can use this script to do the basic setup for Minecraft Textures.

The script moved to the repository:

https://github.com/jmc2obj/j-mc-2-obj/blob/master/conf/contrib/BLENDER_cycles_277.py

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.