Notifications
Clear all

[Closed] GoZ Startup macro

Hi

Has anyone looked at modifying the macro_GoZ.ms startupscript to add post-import actions.

I wanted to change it a little bit, setting wirecolor, changing materials etc as a post import from Zbrush commandlines and also some pre export to zbrush commands.
But I cant figure out where in the script I’m supposed to put those commands.

5 Replies

I think there are several macros, they are also have strange names such as “GoZ test1 classof”, “GoZ test2 (polyop)”, “GoZ test3 (move), and so on.

TBH, I haven’t looked too much into them.

Shameless plug: You could give GoMax a try. It imports materials as well.

Hi maxscripters,

I’m currently having a look at avoiding Goz maxscript to change the renderer back to mental ray.

I’m using as many other users Vray as my renderer. Seems like beloved Blur Studios guys are using Zbrush and vray as well … they must have end up with a way around inside house. After googling and forum searches, I still have no clue about the existance of a modified script.

So here I decided to go. Pointed out where in the script is situated the renderer switch but I’m not a maxscripter at all.

Will have a try at it but any help would be apreciated if someone as a bit of knowledge and spare time to help.

This is where in Macro_GoZ.ms it comes in line 1016, and goes like this :

-- Activates Mental-Ray as current renderer 
    mental_ray_Preferences.mrExtensionsActive = true
    if ((classof renderers.current) != mental_ray_renderer) then
        renderers.current = mental_ray_renderer()

    if (nodeCreationCase) then (
        -- Creates the shader 
        local goz_shader = standard()

if (s_verboseMaterial) then format ” creation of shader ! %
” (classof goz_shader)
–local mray_material = mental_ray()
goz_shader.showInViewport = true
goz_shader.specularLevel = 35
goz_shader.glossiness = 25

        -- Diffuse map 
        if (textureMap != undefined) then (

if (s_verboseMaterial) then format ” setting texture map

local bmap = BitmapTexture filename:textureMap
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
goz_shader.diffuseMap = bmap
)

        -- Normal map 
        if (normalMap != undefined) then (

if (s_verboseMaterial) then format ” setting normal map

local bmap = BitmapTexture filename:normalMap
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
goz_shader.bumpMap = Normal_Bump normal_map:bmap flipgreen:true
goz_shader.bumpMapAmount = 100.0
)
maxObj.m_node.material = goz_shader

        -- Displacement map 
        if (displacementMap != undefined) then (

if (s_verboseMaterial) then format ” setting displacement map

local bmap = BitmapTexture filename:displacementMap
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
local hmap = max_HeightMapDisplacement()
hmap.minHeight = -(displacementFactor/2.0)
hmap.maxHeight = (displacementFactor/2.0)
hmap.heightMap = bmap
local prevMat = meditMaterials[1]
meditMaterials[1] = maxObj.m_node.material
meditMaterials[1].mental_ray__material_custom_attribute.DisplacementLocked = false
meditMaterials[1].mental_ray__material_custom_attribute.Displacement = hmap
meditMaterials[1] = prevMat
)

    ) else (  -- (maxObj.m_node != undefined)

        -- Gets the shader 
        local goz_shader = maxObj.m_node.material
        if (goz_shader == undefined) then (

if (s_verboseMaterial) then format ” no shader in the node !

)
if (goz_shader != undefined) then (
if (s_verboseMaterial) then format ” Existing shader ! %
” (classof goz_shader)
– Diffuse map
if (textureMap != undefined) then (
if (goz_shader.diffuseMap == undefined) then (
local bmap = BitmapTexture filename:textureMap
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
goz_shader.diffuseMap = bmap
) else (
goz_shader.diffuseMap.filename = textureMap
goz_shader.diffuseMap.reload()
)
)

            -- Normal map 
            if (normalMap != undefined) then (

if (s_verboseMaterial) then format “a normal map is defined %
” normalMap
if (goz_shader.bumpMap == undefined) then (
if (s_verboseMaterial) then format “there were no bump-map: creates a new bump-map %
” normalMap
local bmap = BitmapTexture filename:normalMap
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
goz_shader.bumpMap = Normal_Bump normal_map:bmap flipgreen:true
goz_shader.bumpMapAmount = 100.0
) else (
if (s_verboseMaterial) then format “there were already a bump-map: updates it %
” normalMap
goz_shader.bumpMap.normal_map.filename = normalMap
goz_shader.bumpMap.normal_map.reload()
)
)

            -- Displacement map 
            if (displacementMap != undefined) then (

if (s_verboseMaterial) then format “Displacement map found: updates the material… %
” displacementMap
local prevMat = meditMaterials[1]
meditMaterials[1] = maxObj.m_node.material
meditMaterials[1].mental_ray__material_custom_attribute.DisplacementLocked = false
if (meditMaterials[1].mental_ray__material_custom_attribute.Displacement == undefined) then (
if (s_verboseMaterial) then format “No previous displacement map: creates a new one… %
” displacementMap
local bmap = BitmapTexture filename:displacementMap
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
local hmap = max_HeightMapDisplacement()
hmap.minHeight = -(displacementFactor/2.0)
hmap.maxHeight = (displacementFactor/2.0)
hmap.heightMap = bmap
meditMaterials[1].mental_ray__material_custom_attribute.Displacement = hmap
) else (
if (s_verboseMaterial) then format “Previous displacement map found: just updates the filename and displacement factor… %
” displacementMap
meditMaterials[1].mental_ray__material_custom_attribute.Displacement.minHeight = -(displacementFactor/2.0)
meditMaterials[1].mental_ray__material_custom_attribute.Displacement.maxHeight = (displacementFactor/2.0)
meditMaterials[1].mental_ray__material_custom_attribute.Displacement.heightMap.filename = displacementMap
meditMaterials[1].mental_ray__material_custom_attribute.Displacement.heightMap.reload()
)
meditMaterials[1] = prevMat
)
)
)

    fclose matfile
)
undefined

)

– parameters read in the xmax file
global s_textureMapFile = undefined
global s_normalMapFile = undefined
global s_displacementMapFile = undefined
global s_displacementFactor = 0.1

– inputs for updateMaterials functions
global s_materialToUpdate = undefined
global s_materialToUpdate_justReload = false

– —————————- Standard Material ——————————
function setupStandardMaterial gozObj = – updates s_viewportMaterial from loaded Maps
(
if (s_verboseMaterial) then format “setupStandardMaterial called!

local theMaterial = s_materialToUpdate

if ((IsKindOf theMaterial standard) == false) then (
    if (s_verboseMaterial) then format "updateStandardMaterial: bad material type (%)

” (classof theMaterial)
)

if (isKindOf theMaterial Standard) then (   -- good material type

    theMaterial.showInViewport = true
    theMaterial.specularLevel = 35
    theMaterial.glossiness = 25
    -- diffuse map
    if ((s_textureMapFile != undefined) AND (doesFileExist s_textureMapFile)) then (
        if (s_materialToUpdate_justReload) then (
             if (IsKindOf theMaterial.diffuseMap BitmapTexture) then (
                if (s_verboseMaterial) then format " diffuseMap : just rename and reload texture file


theMaterial.diffuseMap.filename = s_textureMapFile
theMaterial.diffuseMap.reload()
) else (
if (s_verboseMaterial) then format ” diffuseMap : cannot just_reload

)
) else ( – create the textures
if (s_verboseMaterial) then format ” create BitmapTexture for diffuseMap

theMaterial.diffuseMap = BitmapTexture()
theMaterial.diffuseMap.filename = s_textureMapFile
if (s_UVsAreVFlipped == false) then theMaterial.diffuseMap.coords.V_Tiling = -1
theMaterial.diffuseMap.coords.Blur = 0.01
)
)

    -- normal map
    if ((s_normalMapFile != undefined) AND (doesFileExist s_normalMapFile)) then (
        if (s_materialToUpdate_justReload) then (
            if ((IsKindOf theMaterial.bumpMap Normal_Bump) AND (IsKindOf theMaterial.bumpMap.normal_map BitmapTexture)) then (
                if (s_verboseMaterial) then format " normalMap : just rename and reload texture file


theMaterial.bumpMap.normal_map.filename = s_normalMapFile
theMaterial.bumpMap.normal_map.reload()
) else (
if (s_verboseMaterial) then format “normalMap : cannot just_reload

)
) else ( – create the textures
if (s_verboseMaterial) then format ” create BitmapTexture for normal

local bmap = BitmapTexture filename:s_normalMapFile
bmap.coords.Blur = 0.01
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
theMaterial.bumpMap = Normal_Bump normal_map:bmap flipgreen:true
theMaterial.bumpMapAmount = 100.0
)
)

    -- Displacement map : la il faut passer par le slot pour acceder au champs "mental ray connection"
    if ((s_displacementMapFile != undefined) AND (doesFileExist s_displacementMapFile)) then (
        if (s_materialToUpdate_justReload) then (
            local prevMat = meditMaterials[1]
            meditMaterials[1] = s_materialToUpdate
            meditMaterials[1].mental_ray__material_custom_attribute.DisplacementLocked = false
            local hmap = meditMaterials[1].mental_ray__material_custom_attribute.Displacement
            if (IsKindOf hmap max_HeightMapDisplacement) then (
                if (IsKindOf hmap.heightMap BitmapTexture) then (
                    hmap.heightMap.filename = s_displacementMapFile
                    hmap.heightMap.reload()
                )
            )
            meditMaterials[1] = prevMat
        ) else (
            if (s_verboseMaterial) then format "create BitmapTexture, HMap and use(swap) slot[1] for Displacement


local bmap = BitmapTexture filename:s_displacementMapFile
if (s_UVsAreVFlipped == false) then bmap.coords.V_Tiling = -1
bmap.coords.Blur = 0.01
local hmap = max_HeightMapDisplacement()
hmap.minHeight = -(s_displacementFactor/2.0)
hmap.maxHeight = (s_displacementFactor/2.0)
hmap.heightMap = bmap
local prevMat = meditMaterials[1]
meditMaterials[1] = s_materialToUpdate
meditMaterials[1].mental_ray__material_custom_attribute.DisplacementLocked = false
meditMaterials[1].mental_ray__material_custom_attribute.Displacement = hmap
meditMaterials[1] = prevMat
)
)
)
)

– —————————- Mental Ray Material ——————————
function setupMentalRayMaterial gozObj =
(
if (s_verboseMaterial) then format “setupMentalRayMaterial called!

local theMaterial = s_materialToUpdate
if ((IsKindOf theMaterial mental_ray) == false) then (
if (s_verboseMaterial) then format “setupMentalRayMaterial: bad material type (%)
” (classof theMaterial)
)

if (s_textureMapFile != undefined) then (
    theMaterial.Surface = BitmapTexture filename:s_textureMapFile
    if (s_UVsAreVFlipped == false) then theMaterial.Surface.coords.V_Tiling = -1
    theMaterial.Surface.coords.Blur = 0.01
)

if (s_normalMapFile != undefined) then (
    if (getVersion() > 12000) then ( --this one does not work, but at least it doesnt crash :/  //This has to be >12000 (Above 3dsMax 2010) instead of >=12000
        theMaterial.Bump = Normals_Make_Normal ()
        theMaterial.Bump.Color_shader  = Normal_Bump flipgreen:true
        theMaterial.Bump.Color_shader.normal_map = BitmapTexture filename: s_normalMapFile
    ) else (
        theMaterial.Bump = max_Bump() -- this is the one for version bellow 13000
        theMaterial.Bump.Map = Normal_Bump flipgreen:true
        theMaterial.Bump.Map.normal_map = BitmapTexture filename: s_normalMapFile
    )                                        
)

if (s_displacementMapFile != undefined) then (
    theMaterial.Displacement = max_HeightMapDisplacement()
    theMaterial.Displacement.heightMap = BitmapTexture filename: s_displacementMapFile
    theMaterial.Displacement.maxHeight = s_displacementFactor / 2
    theMaterial.Displacement.minHeight = -(s_displacementFactor / 2)
)                                

)

– —————————- DirectX9 Material ——————————

function setupDirectX9Material gozObj =
(
if (s_verboseMaterial) then format “setupDirectX9Material called!

local theMaterial = s_materialToUpdate
if ((IsKindOf theMaterial DirectX_9_Shader) == false) then (
if (s_verboseMaterial) then format “setupDirectX9Material: bad material type (%)
” (classof theMaterial)
)

if (IsKindOf theMaterial DirectX_9_Shader) then (

    if (s_materialToUpdate_justReload) then (                        -- update case : just update textures
        if ((findString theMaterial.effectFile "StandardFX.fx") != undefined) then (
            if (theMaterial.g_TopDiffuseEnable) then (
                theMaterial.g_TopTexture = openbitmap s_textureMapFile
                if (s_verboseMaterial) then format " reset the diffuseMap filename (openbitmap)


)
if (theMaterial.g_NormalEnable) then (
theMaterial.g_NormalTexture = openbitmap s_normalMapFile
if (s_verboseMaterial) then format ” reset the normal Map filename (openbitmap)

)
)

    ) else (                                                        -- creation case: set everything we want
        theMaterial.effectFile = "$maps\\fx\\StandardFX.fx"
        theMaterial.renderMaterial = undefined
        theMaterial.technique = 0
        theMaterial.n = 50
        theMaterial.k_s = (color 64 64 64)
        theMaterial.k_d = (color 160 160 160)
        theMaterial.k_a = (color 0 0 0)

        if (s_textureMapFile != undefined) then (
            theMaterial.g_TopDiffuseEnable = true
            theMaterial.g_TopTexture = openbitmap s_textureMapFile
        ) else (
            theMaterial.g_TopDiffuseEnable = false
        )

        if (s_normalMapFile != undefined) then (
            theMaterial.g_NormalEnable = true
            theMaterial.g_NormalTexture = openbitmap s_normalMapFile
        ) else (
            theMaterial.g_NormalEnable = false
        )
    )
)

)

————————— ImportMaterial from xmax file -> ShellMaterial —————————
function ImportMaterial_xmax_Shell gozObj matFilename nodeCreationCase =
(
–print “— ImportMaterial_xmax_Shell —”
local maxObj = gozObj.m_maxObject
if ((maxObj!=undefined) and (maxObj!=s_severalMaxObjects)) then
(
matfile = safeOpenFile matFilename “rb”

    -- Parses the file. 
    s_textureMapFile = undefined
    s_normalMapFile = undefined
    s_displacementMapFile = undefined
    s_displacementFactor = 0.1
    local i, j, k
    while (not isEndOfFile matfile) do (
        item = ReadLong matfile
        case item of (
            8:  -- Texture map 
            (
                local count = ReadLong matfile
                s_textureMapFile = ReadString matfile
                readPaddingData matfile count

if (s_verbose) then format “Texture map read = %
” s_textureMapFile
)

            9:  -- Normal map 
            (
                local count = ReadLong matfile
                s_normalMapFile = ReadString matfile
                readPaddingData matfile count

if (s_verbose) then format “Normal map read = %
” s_normalMapFile
)

            10:  -- Displacement map 
            (
                s_displacementFactor = ReadFloat matfile
                local count = ReadLong matfile
                s_displacementMapFile = ReadString matfile
                readPaddingData matfile count

if (s_verbose) then format “Displacement map read = %
” s_displacementMapFile
)
)
)
fclose matfile

    -- Activates Mental-Ray as current renderer 
    mental_ray_Preferences.mrExtensionsActive = true
    if ((classof renderers.current) != mental_ray_renderer) then
        renderers.current = mental_ray_renderer()

    -- Creates or updates the material ?
    local goz_shader = maxObj.m_node.material
    local viewportMaterial = undefined
    local renderMaterial = undefined
    
    if (s_verboseMaterial) then format "nodeCreationCase = %

” nodeCreationCase
local createMaterial = false
if (nodeCreationCase) then (
createMaterial = true
) else if (gozObj.m_materialCreated == false) then (
if (IsKindOf gozObj.m_node.material standard) then (
if (s_verboseMaterial) then format “createMaterial -> true (1er passage ZB -> 3DS et material = standard)

createMaterial = true
)
)
if (createMaterial == true) then (
s_materialToUpdate_justReload = false
local viewportShaderType = 1 – 0:standard 1:DirectX 2:mentalRay
local renderShaderType = 0
if (globalDXDisplayManager.isDXActive() == false) then (
format “isDXActive() == false -> use standard material only!

viewportShaderType = 0
)

        local createShellMaterial = true
        if (viewportShaderType == renderShaderType) then createShellMaterial = false

        if (s_verboseMaterial) then format "viewportShaderType=%    renderShaderType=%   createShellMaterial=%

” viewportShaderType renderShaderType createShellMaterial
if (viewportShaderType == 1) then viewportMaterial = DirectX_9_Shader()
else viewportMaterial = standard()

        if (createShellMaterial == true) then (
            if (renderShaderType == 2) then renderMaterial = mental_ray()
              else renderMaterial = standard()
        )
          
        if (createShellMaterial == true) then (
            if (s_verboseMaterial) then format "Creating a Shell_Material! 


goz_shader = Shell_Material viewportMtlIndex: 0 renderMtlIndex: 1 name:“My_ShellMaterial”
goz_shader.originalMaterial = viewportMaterial
goz_shader.bakedMaterial = renderMaterial
) else (
goz_shader = viewportMaterial
)
goz_shader.showInViewport = true
maxObj.m_node.material = goz_shader
gozObj.m_materialCreated = true

    ) else (             -- the material already exists in the node, check if we can update this material (just reload)
        s_materialToUpdate_justReload = true
        if (IsKindOf maxObj.m_node.material Shell_Material) then (
            viewportMaterial = maxObj.m_node.material.originalMaterial
            renderMaterial = maxObj.m_node.material.bakedMaterial
            if (s_verboseMaterial) then format " JustReload case: Shell_Material found !


) else if (IsKindOf maxObj.m_node.material Standard) then (
viewportMaterial = maxObj.m_node.material
if (s_verboseMaterial) then format ” JustReload case: Standard material found !

) else if (IsKindOf maxObj.m_node.material DirectX_9_Shader) then (
viewportMaterial = maxObj.m_node.material
if (s_verboseMaterial) then format ” JustReload case: DirectX_9_Shader found !

)
)

    -- set up viewport Material
    if (isKindOf viewportMaterial standard) then (
        s_materialToUpdate = viewportMaterial
        setupStandardMaterial gozObj
    ) else if (isKindOf viewportMaterial DirectX_9_Shader) then (
        s_materialToUpdate = viewportMaterial
        setupDirectX9Material gozObj
    )
    
    -- set up render Material (only if different from viewport material)
    if ((renderMaterial != undefined) AND (renderMaterial != viewportMaterial)) then (
        if (isKindOf renderMaterial standard) then (
            s_materialToUpdate = renderMaterial
            setupStandardMaterial gozObj 
        ) else if (isKindOf renderMaterial mental_ray) then (
            s_materialToUpdate = renderMaterial
            setupMentalRayMaterial gozObj
        )
    )

    -- sinon pour copier un fichier (texture) : DosCommand "copy " + 
)
undefined

)

function ImportObject gozObj fileName =
(
local retObj = undefined
local extension3 = substring fileName (fileName.count-3) 4
local extension4 = substring fileName (fileName.count-4) 5
if (extension3 == “.3ds”) then(
retObj = gozObj.m_maxObject
importFile fileName #noPrompt
)
if (extension3 == “.obj”) then (
retObj = ImportObject_obj gozObj fileName

    local matFileName = (substring fileName 1 (fileName.count-4)) + ".xmax"
    -- NEW : use Shell Material
    --ImportMaterial_xmax gozObj matFileName s_nodeCreationCase       -- NB: s_nodeCreationCase is set in ImportObject_obj
    ImportMaterial_xmax_Shell gozObj matFileName s_nodeCreationCase       -- NB: s_nodeCreationCase is set in ImportObject_obj
) 
if (extension4 == ".xmax") then (
    local file = safeOpenFile fileName "rb"
    -- in deprected ms file: retObj = ImportObject_xmax gozObj file
    fclose file
)
retObj

)

I guess I just have to change all the mental ray parameters to vray ones but as I said, I’m not a maxscripter at all.

I’ll start to play with it and see what happen but don’t expect anything from me. Just testing for now. If good start and hopes, or help from anyone, I’ll push things more in depth to get a proper transitions inbetween Zbrush and Vray.

I’m basically trying to make things moving forward. Once again, any help more than apreciated.

Thanks guys,

Okay, this is what I got so far :

_ No more renderer switch (GoZ will now keep Vray active with all the current setup )

BUT unfortunately,

_ No material import yet and not soon from me I guess ( it’s the tricky part, too many lines of code for many divers cases and for my poor knowledge moreover :shrug: )

That means you’ll be able to change geometry and textures as you wish in Zbrush and still use GoZ to send geometry back in Max, BUT have to manually save diffuse, normal and displacement from Zbrush to custom paths and having those paths assigned in your Vray material.

You’ll update your Vray shader by simply overwriting assigned maps which is for me way less frustrating than resetting up my renderer everytime !

Still a quick beta version, tested quickly but it seems to work so far.

This is it for now. I’m scary by the amount of code I have to go through to make it importing maps as well, so I can’t promise anything.

Installation :

First, make a copy of your Macro_GoZ.ms located in C:\Program Files\Autodesk\3ds Max 2011\Scripts\Startup, I personnally renamed it Macro_GoZ.msSAV so it’s not recognized anymore.
And copy in the same location this new one.

Note that I’m using Max 2011, I don’t know if this will work in other versions. But let me know if you have questions or troubles.

Hope this can help some people around.

Ni2ko ! THANK YOU !

Let me know if you are experiencing problems, as I said, it might not work perfeclty.
I have some bugs sometimes, but dunno if it comes from Zbrush, GoZ, or my modified script.