コード例 #1
0
    def TDALGlb(cls):
        skyfile = r'C:\Program Files\Marmoset\Toolbag 3\data\sky\Indoor Fluorescents.tbsky'
        # exportpath = r'O:\201808_H3D_extension\300models\glb\\'
        importpath = (r'O:\201808_H3D_extension\300models\OutputForGlb')
        retargetpath = (r'O:\201808_H3D_extension\300models\Output')
        fbxfiles = []
        for dirpath, dnames, fnames in os.walk(importpath):
            for f in fnames:
                if f.endswith(".fbx"):
                    fbxfiles.append(os.path.join(dirpath, f))

        # print (fbxfiles)

        for fbxfile in fbxfiles:

            templist = fbxfile.split('\\')[:-2]
            temppath = "\\".join(templist)

            sceneObjName = (templist[len(templist) - 1])
            newoutput = temppath.replace(importpath, retargetpath)

            # exportpath =

            scene = mset.newScene()
            skyobj = mset.findObject('Sky')
            skyobj.loadSky(skyfile)
            mycam = mset.findObject('Main Camera')
            # mycam.position = [120, 30, 120]
            mycam.position = [70, 30, 105]
            mycam.rotation = [0, 33.5, 0.0]

            Externalfbx = mset.ExternalObject()
            Externalfbx.path = fbxfile
            Externalfbx.name = sceneObjName
            mset.frameScene()
            screenShotPath = newoutput + '.jpg'

            mset.exportScreenshot(path=screenShotPath,
                                  width=839,
                                  height=416,
                                  sampling=8,
                                  transparency=False)

            # export glb
            glbpath = newoutput + '.glb'
            if os.path.exists(newoutput):
                mset.exportGLTF(path=glbpath,
                                quality=1,
                                metalnessThreshold=0.8)
                print("export %s success" % (glbpath))
コード例 #2
0
    def export_MakeScreenShot(cls, screenshotpath):
        skyfile = r'C:\Program Files\Marmoset\Toolbag 3\data\sky\Indoor Fluorescents.tbsky'
        savepath = screenshotpath + '.jpg'
        if os.path.isfile(skyfile):
            skyobj = mset.findObject('Sky')
            skyobj.loadSky(skyfile)

            camera = mset.findObject('Main Camera')
            camera.position = [70, 30, 105]
            camera.rotation = [0, 33.5, 0.0]
            mset.frameScene()
            mset.exportScreenshot(path=savepath,
                                  width=839,
                                  height=416,
                                  sampling=8,
                                  transparency=False)
コード例 #3
0
def refresh_scene():
    if os.path.exists(os.path.join(temps_path, "marmo_vars.json")):
        mset.newScene()

        with open(os.path.join(temps_path, "marmo_vars.json"),
                  'r') as openfile:
            marmo_json = json.load(openfile)

        # Create baker object
        baker = mset.BakerObject()

        # Setting up the baker
        baker.outputPath = marmo_json["file_path"]
        baker.outputBits = marmo_json["bits_per_channel"]
        baker.outputSamples = marmo_json["samples"]
        baker.edgePadding = "None"
        baker.outputSoften = 0.5
        baker.useHiddenMeshes = True
        baker.ignoreTransforms = False
        baker.smoothCage = True
        baker.ignoreBackfaces = True
        baker.multipleTextureSets = False
        baker.outputWidth = marmo_json["resolution_x"]
        baker.outputHeight = marmo_json["resolution_y"]

        # Disable all maps
        for maps in baker.getAllMaps():
            maps.enabled = False

        # Configure maps
        normalMap = baker.getMap("Normals")
        normalMap.enabled = marmo_json["export_normals"]
        normalMap.suffix = 'normal'
        normalMap.flipY = marmo_json["flipy_normals"]
        normalMap.flipX = False
        normalMap.dither = False

        curvatureMap = baker.getMap("Curvature")
        curvatureMap.enabled = marmo_json["export_curvature"]

        occlusionMap = baker.getMap("Ambient Occlusion")
        occlusionMap.rayCount = marmo_json["ray_count_occlusion"]
        occlusionMap.enabled = marmo_json["export_occlusion"]

        heightMap = baker.getMap("Height")
        heightMap.innerDistance = 0
        heightMap.enabled = marmo_json["export_height"]
        if marmo_json["flat_height"]:
            heightMap.outerDistance = .01
        else:
            heightMap.outerDistance = marmo_json["cage_height"] / 2 - .02

        matIDMap = baker.getMap("Material ID")
        matIDMap.enabled = marmo_json["export_matid"]

        # Import the models
        baker.importModel(os.path.join(temps_path, "grabdoc_temp_model.fbx"))

        # Set cage offset
        mset.findObject('Low').maxOffset = marmo_json["cage_height"] + .01

        tb_version = mset.getToolbagVersion()

        # Change skybox to Evening Clouds
        if tb_version < 4000:
            mset.findObject('Sky').loadSky(marmo_json["marmo_sky_path"])

        # Rotate all models 90 degrees
        bakeGroup = mset.findObject('GrabDoc')
        bakeGroup.rotation = [90, 0, 0]

        # Make a folder for Mat ID materials
        for mat in mset.getAllMaterials():
            if mat.name.startswith("GD_"):
                mat.setGroup('Mat ID')

        # Baker
        if marmo_json["auto_bake"]:
            baker.bake()

            # Open folder on export
            if marmo_json["open_folder"]:
                os.startfile(marmo_json["file_path_no_ext"])

            # Close marmo if the option is selected
            if marmo_json["close_after_bake"]:
                mset.quit()

            # Hide the _High group
            mset.findObject('High').visible = False

            # Scale up the high poly plane
            mset.findObject('GrabDoc_high GD_Background Plane').scale = [
                300, 300, 300
            ]

            findDefault = mset.findMaterial("Default")

            # Material preview
            if marmo_json["export_normals"]:
                findDefault.getSubroutine('surface').setField(
                    'Normal Map',
                    marmo_json["file_path"][:-4] + '_normal' + '.png')

            if marmo_json["export_occlusion"]:
                findDefault.setSubroutine('occlusion', 'Occlusion')
                findDefault.getSubroutine('occlusion').setField(
                    'Occlusion Map',
                    marmo_json["file_path"][:-4] + '_ao' + '.png')

            # Rename bake material
            findDefault.name = 'Bake Material'

        os.remove(os.path.join(temps_path, "marmo_vars.json"))
コード例 #4
0
Data = ''
with open(WorkDir + "MaterialStylesheet.json", "r") as f:
    Data = f.read()
Items = json.loads(Data)

# Import FBX
mesh = mset.importModel(WorkDir + "MarmosetMesh.fbx")

# Set Timeline
mset.getTimeline().selectionStart = Items["FRAMERANGE"][0]
mset.getTimeline().selectionEnd = Items["FRAMERANGE"][1]
mset.getTimeline().currentFrame = Items['CURRENTFRAME']

# Set Sky
if Items['SKYLIGHT']["UseCustom"] == 1:
    mset.findObject("Sky").importImage(Items['SKYLIGHT']["CustomSkyLight"])
else:
    mset.findObject("Sky").loadSky("data/sky/%s" % Items['SKYLIGHT']["Preset"])

# Set Camera
if Items["CAMERA"] != "":
    mset.setCamera(mset.findObject(Items["CAMERA"]))

# Load and Assign Material to matching Mesh
for item in Items['TEXDATA']:
    MeshName = Items['TEXDATA'][item]['Mesh']
    MaterialName = Items['TEXDATA'][item]['Material']
    SceneMesh = mset.findObject(MeshName)
    Material = mset.findMaterial(MaterialName)

    MaterialTextures = list(Items['TEXDATA'][item].keys())