def startWorkerExport(exportData,workerthreat):
  
    for oneObj in exportData.doc.GetObjects():
        mainLightRouting.readAllLightRouting(oneObj,exportData)   
    workerHelpers.applymaterialsToPrimitives(exportData)
    workerHelpers.connectInstances(exportData)
    
    if workerthreat.TestBreak():
        return              
        
    workerHelpers.getAllObjectData(exportData)
    
    if workerthreat.TestBreak():
        return    
    workerHelpers.createAnimatorBlocks(exportData.objList,exportData) 
    
    workerMeshReader.convertMeshes(exportData.allMeshObjects,exportData,workerthreat)   
    
    if exportData.unusedMats==True:
        for awdBlock in exportData.allAWDBlocks:
            if awdBlock.blockType==81:
                if awdBlock.data.isCreated==False and awdBlock.data.colorMat==False:
                    awdBlock.data.isCreated=True                
                    mainMaterials.createMaterial(awdBlock,exportData)
                
    if workerthreat.TestBreak():
        return          
    exportData.status=3    
    
    
    
    workerHelpers.reorderAllBlocks(exportData)
    
    if workerthreat.TestBreak():
        return       
        
    workerHelpers.exportAllData(exportData)
    
    if workerthreat.TestBreak():
        return  
        
    exportData.allStatus+=1
	
    for block in exportData.allAWDBlocks: 
        if block.targetObject is not None:
            block.targetObject.SetName(str(block.name))
    
    for block in exportData.allSceneObjects:
        print "NAME = "+block.data.name
        if block.data.sceneObject is not None:
            block.data.sceneObject.SetName(str(block.name))
def startWorkerExport(exportData, workerthreat):

    for oneObj in exportData.doc.GetObjects():
        mainLightRouting.readAllLightRouting(oneObj, exportData)
    workerHelpers.applymaterialsToPrimitives(exportData)
    workerHelpers.connectInstances(exportData)

    if workerthreat.TestBreak():
        return

    workerHelpers.getAllObjectData(exportData)

    if workerthreat.TestBreak():
        return
    workerHelpers.createAnimatorBlocks(exportData.objList, exportData)

    workerMeshReader.convertMeshes(exportData.allMeshObjects, exportData,
                                   workerthreat)

    if exportData.unusedMats == True:
        for awdBlock in exportData.allAWDBlocks:
            if awdBlock.blockType == 81:
                if awdBlock.data.isCreated == False and awdBlock.data.colorMat == False:
                    awdBlock.data.isCreated = True
                    mainMaterials.createMaterial(awdBlock, exportData)

    if workerthreat.TestBreak():
        return
    exportData.status = 3

    workerHelpers.reorderAllBlocks(exportData)

    if workerthreat.TestBreak():
        return

    workerHelpers.exportAllData(exportData)

    if workerthreat.TestBreak():
        return

    exportData.allStatus += 1

    for block in exportData.allAWDBlocks:
        if block.targetObject is not None:
            block.targetObject.SetName(str(block.name))

    for block in exportData.allSceneObjects:
        print "NAME = " + block.data.name
        if block.data.sceneObject is not None:
            block.data.sceneObject.SetName(str(block.name))
Example #3
0
def connectInstances(exportData):
    for instanceBlock in exportData.unconnectedInstances:
        isPoly = False
        if instanceBlock.data.sceneObject[
                c4d.INSTANCEOBJECT_LINK].GetType() == c4d.Opolygon:
            isPoly = True
        geoInstanceID = instanceBlock.data.sceneObject[
            c4d.INSTANCEOBJECT_LINK].GetName()
        instanceGeoBlock = exportData.allAWDBlocks[int(geoInstanceID)]
        if instanceGeoBlock is not None:
            geoBlockID = instanceGeoBlock.data.geoBlockID
            geoBlock = exportData.allAWDBlocks[int(geoBlockID)]
            if geoBlock is not None:
                instanceBlock.data.geoBlockID = geoBlockID
                geoBlock.data.sceneBlocks.append(instanceBlock)
                if isPoly == False:
                    instanceBlock.data.lightPickerIdx = mainLightRouting.getObjectLights(
                        instanceBlock.targetObject, exportData
                    )  # get the LightPicker for this sceneObject (if the lightpicker does not allready exists, it will be created)
                    if str(geoBlock.blockType) == str(11):
                        if instanceBlock.data.isRenderInstance == True:
                            if geoBlock.data.colorStyle == False:
                                instanceBlock.data.saveMaterials = [
                                    geoBlock.data.baseMat
                                ]
                            if geoBlock.data.colorStyle == True:
                                if geoBlock.data.hasMats == True:
                                    instanceBlock.data.saveMaterials = [
                                        geoBlock.data.baseMat
                                    ]
                                if geoBlock.data.hasMats == False:
                                    materials = getMaterials(
                                        instanceBlock.data.sceneObject, [],
                                        True, exportData)
                                    if len(materials) > 0:
                                        instanceBlock.data.saveMaterials = [
                                            materials[len(materials) - 1]
                                        ]
                                    else:
                                        instanceBlock.data.saveMaterials = [-1]
                        if instanceBlock.data.isRenderInstance == False:
                            materials = getMaterials(
                                instanceBlock.data.sceneObject, [], True,
                                exportData)
                            thisMaterial = None
                            if len(materials) > 0:
                                thisMaterial = materials[len(materials) - 1]
                            if geoBlock.data.hasMats == True:
                                thisMaterial = geoBlock.data.baseMat
                            returnList = getObjectColorMode(
                                instanceBlock.data.sceneObject, thisMaterial,
                                exportData)
                            instanceBlock.data.saveMaterials = [
                                returnList[1][0]
                            ]
                        matCount = 0
                        for mat in instanceBlock.data.saveMaterials:
                            matAwdBlock = exportData.allAWDBlocks[int(mat)]
                            if matAwdBlock is not None:
                                repeat = False
                                if len(matAwdBlock.data.materialsList) == 0:
                                    matAwdBlock.data.materialsList.append(mat)
                                    matAwdBlock.data.lightPicker = instanceBlock.data.lightPickerIdx
                                    matAwdBlock.data.repeat = False
                                    foundMat = mat
                                else:
                                    foundMat = -1
                                    for matID in matAwdBlock.data.materialsList:
                                        if exportData.allAWDBlocks[int(
                                                matID
                                        )].data.lightPicker == instanceBlock.data.lightPickerIdx:
                                            if exportData.allAWDBlocks[int(
                                                    matID
                                            )].data.repeat == repeat:
                                                foundMat = matID
                                    if foundMat == -1:
                                        foundMat = copyAsNewMaterialBlock(
                                            exportData, matAwdBlock,
                                            instanceBlock.data.lightPickerIdx,
                                            repeat)
                                instanceBlock.data.saveMaterials[
                                    matCount] = foundMat
                                if matAwdBlock.data.isCreated == False and matAwdBlock.data.colorMat == False:
                                    matAwdBlock.data.isCreated = True
                                    mainMaterials.createMaterial(
                                        matAwdBlock.data, exportData)
                                #if instanceBlock.lightPickerIdx>0:
                                #matAwdBlock.lightPickerID=instanceBlock.lightPickerIdx
                                if matAwdBlock.tagForExport == False:
                                    matAwdBlock.tagForExport = True
                            matCount += 1

        instanceBlock.geoBlockID = geoBlockID
def addToExportList(exportData,awdBlock):
    if awdBlock.isReordered==True:
        return awdBlock.saveBlockID
    if awdBlock.isReordered==False:
        if awdBlock.tagForExport==True:
            if awdBlock.blockType==254:#NameSpace
                pass#doThis=True
            if awdBlock.blockType==255:#metadata
                pass#doThis=True    
            if awdBlock.blockType==1:
                pass#triangel
            if awdBlock.blockType==11:
                pass#primitive
            if awdBlock.blockType==21:
                pass#scene       
            if awdBlock.blockType==22:#container
                parentBlock=exportData.allAWDBlocks[int(awdBlock.data.dataParentBlockID)]
                if parentBlock is not None:
                    awdBlock.data.dataParentBlockID=addToExportList(exportData,parentBlock)
                    
            if awdBlock.blockType==23:#meshinstance
                parentBlock=exportData.allAWDBlocks[int(awdBlock.data.dataParentBlockID)]
                if parentBlock is not None:
                    awdBlock.data.dataParentBlockID=addToExportList(exportData,parentBlock)
                geoBlock=exportData.allAWDBlocks[int(awdBlock.data.geoBlockID)]
                if geoBlock is not None:
                    awdBlock.data.saveGeoBlockID=addToExportList(exportData,geoBlock)           
                awdBlock.data.saveMaterials2=[]
                print str((awdBlock.data.saveGeoBlockID))+"   geoBlock.saveSubMeshes"
                for mat in awdBlock.data.saveMaterials:
                    matBlockID=addToExportList(exportData,exportData.allAWDBlocks[int(mat)])
                    awdBlock.data.saveMaterials2.append(matBlockID)
                    #print "awdBlock.saveMaterials2 = "+str(awdBlock.saveMaterials2)
                      
            if awdBlock.blockType==41:#light
                parentBlock=exportData.allAWDBlocks[int(awdBlock.data.dataParentBlockID)]
                if parentBlock is not None:
                    awdBlock.data.dataParentBlockID=addToExportList(exportData,parentBlock)
                    
            if awdBlock.blockType==42:#camera
                parentBlock=exportData.allAWDBlocks[int(awdBlock.data.dataParentBlockID)]
                
            if awdBlock.blockType==51:#lightPicker
                exportData.lightPickerCounter+=1
                awdBlock.data.name+=str(exportData.lightPickerCounter)
                for light in awdBlock.data.lightList:
                    lightID=addToExportList(exportData,exportData.allAWDBlocks[int(light)])
                    awdBlock.data.saveLightList.append(lightID)
                
            if awdBlock.blockType==81:#material
                
                lightPickerBlock=exportData.allAWDBlocks[int(awdBlock.data.lightPicker)]
                if lightPickerBlock is not None:
                    awdBlock.data.saveMatProps.append(22)
                    awdBlock.data.lightPickerID=addToExportList(exportData,lightPickerBlock)
                if awdBlock.data.isCreated==False and awdBlock.data.colorMat==False:
                    awdBlock.data.isCreated=True                
                    mainMaterials.createMaterial(awdBlock.data,exportData)
                if awdBlock.data.saveMatType==2:
                    textureBlock=exportData.allAWDBlocks[int(awdBlock.data.saveColorTextureID)]
                    if textureBlock is not None:
                        awdBlock.data.saveColorTextureID=addToExportList(exportData,textureBlock)
                    normalTextureBlock=exportData.allAWDBlocks[int(awdBlock.data.saveNormalTextureID)]
                    if normalTextureBlock is not None:
                        awdBlock.data.saveNormalTextureID=addToExportList(exportData,normalTextureBlock)
                    ambientTextureBlock=exportData.allAWDBlocks[int(awdBlock.data.saveAmbientTextureID)]
                    if ambientTextureBlock is not None:
                        awdBlock.data.saveAmbientTextureID=addToExportList(exportData,ambientTextureBlock)
                    specTextureBlock=exportData.allAWDBlocks[int(awdBlock.data.saveSpecTextureID)]
                    if specTextureBlock is not None:
                        awdBlock.data.saveSpecTextureID=addToExportList(exportData,specTextureBlock)
                
            if awdBlock.blockType==82:#texture
                pass
            if awdBlock.blockType==83:#cubetexture
                pass#      awdBlock.dataParentBlockID=addToExportList(exportData,parentBlock)                    
            if awdBlock.blockType==101:#skeleton
                pass
            if awdBlock.blockType==102:#skeletonpose
                pass
            if awdBlock.blockType==103:#skeletonanimation
                for pose in awdBlock.data.framesIDSList:
                    awdBlock.data.framesIDSList2.append(addToExportList(exportData,pose))
            if awdBlock.blockType==121:#uvanimation
                pass
            if awdBlock.blockType==111:#VertexState
                targetMesh=exportData.allAWDBlocks[int(awdBlock.data.targetMesh)]
                if targetMesh is not None:
                    awdBlock.data.saveTargetMesh=addToExportList(exportData,targetMesh)

            if awdBlock.blockType==112:#VertexAnimation
                targetMesh=exportData.allAWDBlocks[int(awdBlock.data.targetMesh)]
                if targetMesh is not None:
                    awdBlock.data.saveTargetMesh=addToExportList(exportData,targetMesh)
                    
            if awdBlock.blockType==113:#AnimationSet
                awdBlock.data.saveTargetMesh=addToExportList(exportData,awdBlock.data.targetMesh)
                geoBlock=exportData.allAWDBlocks[int(awdBlock.data.targetMesh.data.geoBlockID)]
                if len(geoBlock.data.saveSubMeshes[0].weightsBuffer)>0:
                    awdBlock.data.jointsPerVert=len(geoBlock.data.saveSubMeshes[0].weightsBuffer)/(len(geoBlock.data.saveSubMeshes[0].vertexBuffer)/3)
                print "AnimationNodes in Set = "+str(len(geoBlock.data.saveSubMeshes[0].weightsBuffer))
                print "AnimationNodes in Set = "+str(len(geoBlock.data.saveSubMeshes[0].vertexBuffer))
                print "AnimationNodes in Set = "+str(awdBlock.data.jointsPerVert)
                for anim in awdBlock.data.poseBlockIDs:
                    awdBlock.data.savePoseBlockIDs.append(addToExportList(exportData,anim))
             
            if awdBlock.blockType==122:#Animator
                awdBlock.data.saveMeshID=addToExportList(exportData,awdBlock.data.targetMeshBlock)
                awdBlock.data.saveAnimSetID=addToExportList(exportData,awdBlock.data.animSetBlock)
                print "awdBlock.data.skeleton "+str(awdBlock.data.skeleton)
                if awdBlock.data.skeleton is not None:
                    print "awdBlock.data.skeleton "+str(awdBlock.data.skeleton)
                    awdBlock.data.saveSkeletonID=addToExportList(exportData,awdBlock.data.skeleton)
                print "awdBlock.data.saveSkeletonID "+str(awdBlock.data.saveSkeletonID)
                #awdBlock.saveSkeletonID=addToExportList(exportData,exportData.skeleton)
                        
            print "Reordered Block type = "+str(awdBlock.blockType)+"  /  "+  str(awdBlock.data) 
            awdBlock.saveBlockID=int(len(exportData.allSaveAWDBlocks))
            awdBlock.isReordered=True
            awdBlock.data.saveBlockID=awdBlock.saveBlockID
            exportData.allSaveAWDBlocks.append(awdBlock.data)
            return awdBlock.saveBlockID
def convertMesh(meshBlock, exportData, workerthreat):
    exportData.doc.SetActiveObject(meshBlock.data.sceneObject)
    if not meshBlock.data.sceneObject.GetTag(5604):
        return
    if not meshBlock.data.sceneObject.GetTag(5600):
        return

    createGeoMaterials = []  # this will store the list of materials used to split the polygons into submeshes
    applyToinstanceMaterials = (
        []
    )  # a list of materials that will be applied for each instance that is using this geometry
    allmaterials = []
    allInstanceMaterials = []
    allSelections = workerHelpers.getAllPolySelections(
        meshBlock.data.sceneObject, exportData
    )  # get all the polygon-selections as a list of helperclass.PolySelection
    baseGeoMaterials = workerHelpers.getMaterials(
        meshBlock.data.sceneObject, allSelections, False, exportData
    )  # get all the Materials that are applied by a textureTag on the PolygonObject directly
    useSelectionsComplete = False
    useInstanceSelection = []
    print "baseGeoMaterials " + str(baseGeoMaterials)
    if (
        len(baseGeoMaterials) > 0
    ):  # if a material is directly applied to the polygonObject, all instances will have this same materials (if they have not a different objectColorMode)
        print "useSelectionsComplete"
        for instanceBlock in meshBlock.data.sceneBlocks:
            if instanceBlock.data.isRenderInstance == True:
                instanceBlock = meshBlock
            textBaseMat = baseGeoMaterials[
                0
            ]  # the first material in this list should allways be a material not restricted by polySelection (e.g. the 'baseMaterial')
            useSelections, returnBasemat = workerHelpers.getObjectColorMode(
                instanceBlock.data.sceneObject, textBaseMat, exportData
            )  # get the BaseMaterial used by this Instance, and a boolean, if the selections should be used on this instance or not
            applyToinstanceMaterials.append(returnBasemat)
            useInstanceSelection.append(useSelections)
            if useSelections == True:  # if the selections are used on this Instance:
                useSelectionsComplete = True  # the polygonObject must be split into the selections

        if useSelectionsComplete == True:  # if the polygonObject must be split:
            print "useSelectionsComplete"
            createGeoMaterials = workerSubMeshReader.cleanMaterialRestriction(
                meshBlock.data, baseGeoMaterials
            )  # get all the Materials and make shure that each polygon is used ba only one material, delete unused materials
            instanceCnt = 0
            useFirst = True
            if str(createGeoMaterials[0][1].name) != "Base":
                useFirst = False
            for instanceBlock in meshBlock.data.sceneBlocks:
                newInstanceMats = []
                geoMatCnt = 0
                if useFirst == True:
                    newInstanceMats.append(applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt = 1
                while geoMatCnt < len(createGeoMaterials):
                    if useInstanceSelection[instanceCnt] == True:
                        newInstanceMats.append(createGeoMaterials[geoMatCnt][0])
                    if useInstanceSelection[instanceCnt] == False:
                        newInstanceMats.append(applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt += 1
                instanceBlock.data.saveMaterials = newInstanceMats
                instanceCnt += 1

    if (
        len(baseGeoMaterials) == 0
    ):  # if no materials are directly applied, we check all instances for their directly applied and inherited materials and the baseobject for the inherited too.

        instanceCnt = 0
        for instanceBlock in meshBlock.data.sceneBlocks:
            instanceMaterials = workerHelpers.getMaterials(
                instanceBlock.data.sceneObject, allSelections, True, exportData
            )  # search for all materials that are applied to the instance-object (including inheritet tags)
            textBaseMat = None
            if (
                instanceBlock.data.isRenderInstance == True
            ):  # if the instance is considered a renderInstance, we use the baseObject (meshblock.sceneObject) for the ObjectColorMode-check
                instanceBlock = meshBlock
            if len(instanceMaterials) > 0:
                textBaseMat = instanceMaterials[0]
            useSelections, returnMat = workerHelpers.getObjectColorMode(
                instanceBlock.data.sceneObject, textBaseMat, exportData
            )
            if len(instanceMaterials) == 0:
                instanceMaterials.append([])
            instanceMaterials[0] = returnMat
            useInstanceSelection.append(useSelections)
            if useSelections == True:  # if the selections are used on this Instance:
                useSelectionsComplete = True  # the polygonObject must be split into the selections
            allInstanceMaterials.append(instanceMaterials)
            applyToinstanceMaterials.append(instanceMaterials[0])
            if instanceCnt == 0:
                baseGeoMaterials = instanceMaterials
            instanceCnt += 1

        if useSelectionsComplete == True:  # if the polygonObject must be split:
            allMatsDic = {}
            allmaterials = []
            instanceCnt = 0
            allCleanMats = []
            for instanceBlock in meshBlock.data.sceneBlocks:
                if useInstanceSelection[instanceCnt] == True:
                    print str(allInstanceMaterials[instanceCnt])
                    cleanedMats = workerSubMeshReader.cleanMaterialRestriction(
                        meshBlock.data, allInstanceMaterials[instanceCnt]
                    )  # get all the Materials and make shure that each polygon is used ba only one material, delete unused materials
                    allCleanMats.append(cleanedMats)
                    for cleanedMat in cleanedMats:
                        matExists = allMatsDic.get(str(cleanedMat[1].name), None)
                        if matExists is None:
                            allMatsDic[str(cleanedMat[1].name)] = cleanedMat
                            cleanedMat.append(instanceBlock)
                            allmaterials.append(cleanedMat)
                if useInstanceSelection[instanceCnt] == False:
                    allCleanMats.append([allInstanceMaterials[instanceCnt][0]])
                instanceCnt += 1
            createGeoMaterials = workerSubMeshReader.mergeMaterialRestriction(meshBlock.data, allmaterials)
            instanceCnt = 0
            useFirst = True
            if str(createGeoMaterials[0][1].name) != "Base":
                useFirst = False
            for instanceBlock in meshBlock.data.sceneBlocks:
                newInstanceMats = []
                geoMatCnt = 0
                if useFirst == True:
                    newInstanceMats.append(applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt = 1
                while geoMatCnt < len(createGeoMaterials):
                    if useInstanceSelection[instanceCnt] == True:
                        foundOnInstance = applyToinstanceMaterials[instanceCnt][
                            0
                        ]  # if this will not be changed, the baseMaterial will be set for this Submesh
                        for intMat in allCleanMats[instanceCnt]:
                            if str(intMat[1].name) == str(createGeoMaterials[geoMatCnt][1].name):
                                foundOnInstance = intMat[0]
                                break
                            nameCnt = 0
                            for name in createGeoMaterials[geoMatCnt][1].multiNames:
                                if str(intMat[1].name) == str(name):
                                    foundOnInstance = createGeoMaterials[geoMatCnt][1].multiMats[nameCnt]
                                nameCnt += 1
                        newInstanceMats.append(foundOnInstance)
                    if (
                        useInstanceSelection[instanceCnt] == False
                    ):  # if the instance does not use selections, we just apply the baseMaterial of this instance to all submeshes
                        newInstanceMats.append(applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt += 1
                instanceBlock.data.saveMaterials = newInstanceMats
                instanceCnt += 1

    if useSelectionsComplete == False:  # if the polygonObject must not be split
        createGeoMaterials = workerSubMeshReader.clearSubmeshIndexe(meshBlock.data, baseGeoMaterials)
        instanceCnt = 0
        for instanceBlock in meshBlock.data.sceneBlocks:
            newInstanceMats = []
            geoMatCnt = 0
            newInstanceMats.append(applyToinstanceMaterials[instanceCnt][0])
            instanceBlock.data.saveMaterials = newInstanceMats
            instanceCnt += 1

    if workerthreat.TestBreak():
        return
    poseAnimationDic = {}
    # for all materialBlocks that will be applied to MeshInstanceBlocks, we make shure that they are fully created (the textureBlocks will be created here) and set to tagForExport = True
    for instanceBlock in meshBlock.data.sceneBlocks:
        print "finalMats = " + str(instanceBlock.data.saveMaterials)

        # collect all vertexAnimations found on the InstanceObjects of the Geoemtrys on the Geometry itself (use dictionary to makes shure each animation is only used once)
        for vertexanimationBlock in instanceBlock.data.poseAnimationBlocks:
            addposeAnimationBlock(meshBlock.data.poseAnimationBlocks, vertexanimationBlock, poseAnimationDic)

        instanceBlock.data.lightPickerIdx = mainLightRouting.getObjectLights(
            instanceBlock.data.sceneObject, exportData
        )  # get the LightPicker for this sceneObject (if the lightpicker does not allready exists, it will be created)
        matCount = 0
        for mat in instanceBlock.data.saveMaterials:
            matAwdBlock = exportData.allAWDBlocks[int(mat)]
            if matAwdBlock is not None:
                repeat = False
                if len(matAwdBlock.data.materialsList) == 0:
                    matAwdBlock.data.materialsList.append(mat)
                    matAwdBlock.data.lightPicker = instanceBlock.data.lightPickerIdx
                    matAwdBlock.data.repeat = False
                    foundMat = mat
                else:
                    foundMat = -1
                    for matID in matAwdBlock.data.materialsList:
                        if exportData.allAWDBlocks[int(matID)].data.lightPicker == instanceBlock.data.lightPickerIdx:
                            if exportData.allAWDBlocks[int(matID)].data.repeat == repeat:
                                foundMat = matID
                    if foundMat == -1:
                        foundMat = workerHelpers.copyAsNewMaterialBlock(
                            exportData, matAwdBlock, instanceBlock.data.lightPickerIdx, repeat
                        )
                instanceBlock.data.saveMaterials[matCount] = foundMat
                if matAwdBlock.data.isCreated == False and matAwdBlock.data.colorMat == False:
                    matAwdBlock.data.isCreated = True
                    mainMaterials.createMaterial(matAwdBlock.data, exportData)
                # if instanceBlock.data.lightPickerIdx>0:
                #    matAwdBlock.data.lightPickerID=instanceBlock.data.lightPickerIdx
                matAwdBlock.tagForExport = True
            matCount += 1

    for mat in createGeoMaterials:  # create a SubMeshBlock for every Material/selection found and used
        # print "create Submesh: "+str(mat[0])
        meshBlock.data.saveSubMeshes.append(
            classesAWDBlocks.awdSubMesh(mat[0], mat[1].name, mat[1].selectionIndexe, mat[2])
        )
    if workerthreat.TestBreak():
        return

    # for instanceMat in allInstanceMaterials

    # for mat in finalMats:    # create a SubMeshBlock for every Material/selection found
    #    for instanceBlock in meshBlock.sceneBlocks:
    #        saveMaterials=

    # if the meshBlock has a WeightTag-applied, we check if the mesh is used by one single skeleton or not.
    weightTag = meshBlock.data.sceneObject.GetTag(c4d.Tweights)
    if weightTag is not None:
        jointCount = weightTag.GetJointCount()
        allSkeletons = getUsedSkeletons(jointCount, weightTag, exportData.jointIDstoSkeletonBlocks, exportData.doc)
        if len(allSkeletons) == 0:
            print "Warning - No Joints are bound to a valid Skeleton"
        if len(allSkeletons) > 1:
            print "Warning - Not all Joints are bound to the same Skeleton"
        if len(allSkeletons) == 1:
            meshBlock.data.weightTag = weightTag

    if workerthreat.TestBreak():
        return

    # morphs=[]
    # for morphState in allPointAndUvMorpTag:
    # if morphState.morphedObject==cur_mesh:
    # morphs.append(morphState)
    # for submesh in new_submeshes:
    # for morphState in morphs:
    # submorphVerts=[]
    # submorphUVs=[]
    # submorphActiv=False
    # submorphdata=[submorphVerts,submorphUVs,submorphActiv,morphState.morphName,morphState.tagName,morphState.tagObject]
    # submesh.morphs.append(submorphdata)
    # print ("parse = "+str(meshBlock.sceneObject.GetName()))
    workerSubMeshReader.collectSubmeshData(
        meshBlock.data, exportData, workerthreat
    )  # parse this object into a awd2-geometry-block

    if workerthreat.TestBreak():  # when the user has cancelled the process:
        return  # we stop executing and return

    subMeshNr = 0
    for subMesh in meshBlock.data.saveSubMeshes:  # for every SubMeshBlock that has been created:
        if workerthreat.TestBreak():  # we check if the user cancelled the process
            return  # and return if he has
        workerSubMeshReader.transformUVS(subMesh)  # transform the uvs if needed (to allow for tilling etc)
        if workerthreat.TestBreak():  # check if the user cancelled the process
            return  # and return if he has
        workerSubMeshReader.buildGeometryStreams(
            subMesh, exportData.scale, meshBlock.data.poseAnimationBlocks, subMeshNr
        )  # build the AWD-geometry-streams for all submeshes
        subMeshNr += 1
Example #6
0
def convertMesh(meshBlock, exportData, workerthreat):
    exportData.doc.SetActiveObject(meshBlock.data.sceneObject)
    if not meshBlock.data.sceneObject.GetTag(5604):
        return
    if not meshBlock.data.sceneObject.GetTag(5600):
        return

    createGeoMaterials = [
    ]  # this will store the list of materials used to split the polygons into submeshes
    applyToinstanceMaterials = [
    ]  # a list of materials that will be applied for each instance that is using this geometry
    allmaterials = []
    allInstanceMaterials = []
    allSelections = workerHelpers.getAllPolySelections(
        meshBlock.data.sceneObject, exportData
    )  # get all the polygon-selections as a list of helperclass.PolySelection
    baseGeoMaterials = workerHelpers.getMaterials(
        meshBlock.data.sceneObject, allSelections, False, exportData
    )  # get all the Materials that are applied by a textureTag on the PolygonObject directly
    useSelectionsComplete = False
    useInstanceSelection = []
    print "baseGeoMaterials " + str(baseGeoMaterials)
    if len(
            baseGeoMaterials
    ) > 0:  # if a material is directly applied to the polygonObject, all instances will have this same materials (if they have not a different objectColorMode)
        print "useSelectionsComplete"
        for instanceBlock in meshBlock.data.sceneBlocks:
            if instanceBlock.data.isRenderInstance == True:
                instanceBlock = meshBlock
            textBaseMat = baseGeoMaterials[
                0]  # the first material in this list should allways be a material not restricted by polySelection (e.g. the 'baseMaterial')
            useSelections, returnBasemat = workerHelpers.getObjectColorMode(
                instanceBlock.data.sceneObject, textBaseMat, exportData
            )  # get the BaseMaterial used by this Instance, and a boolean, if the selections should be used on this instance or not
            applyToinstanceMaterials.append(returnBasemat)
            useInstanceSelection.append(useSelections)
            if useSelections == True:  # if the selections are used on this Instance:
                useSelectionsComplete = True  # the polygonObject must be split into the selections

        if useSelectionsComplete == True:  # if the polygonObject must be split:
            print "useSelectionsComplete"
            createGeoMaterials = workerSubMeshReader.cleanMaterialRestriction(
                meshBlock.data, baseGeoMaterials
            )  # get all the Materials and make shure that each polygon is used ba only one material, delete unused materials
            instanceCnt = 0
            useFirst = True
            if str(createGeoMaterials[0][1].name) != "Base":
                useFirst = False
            for instanceBlock in meshBlock.data.sceneBlocks:
                newInstanceMats = []
                geoMatCnt = 0
                if useFirst == True:
                    newInstanceMats.append(
                        applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt = 1
                while geoMatCnt < len(createGeoMaterials):
                    if useInstanceSelection[instanceCnt] == True:
                        newInstanceMats.append(
                            createGeoMaterials[geoMatCnt][0])
                    if useInstanceSelection[instanceCnt] == False:
                        newInstanceMats.append(
                            applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt += 1
                instanceBlock.data.saveMaterials = newInstanceMats
                instanceCnt += 1

    if len(
            baseGeoMaterials
    ) == 0:  # if no materials are directly applied, we check all instances for their directly applied and inherited materials and the baseobject for the inherited too.

        instanceCnt = 0
        for instanceBlock in meshBlock.data.sceneBlocks:
            instanceMaterials = workerHelpers.getMaterials(
                instanceBlock.data.sceneObject, allSelections, True, exportData
            )  # search for all materials that are applied to the instance-object (including inheritet tags)
            textBaseMat = None
            if instanceBlock.data.isRenderInstance == True:  # if the instance is considered a renderInstance, we use the baseObject (meshblock.sceneObject) for the ObjectColorMode-check
                instanceBlock = meshBlock
            if len(instanceMaterials) > 0:
                textBaseMat = instanceMaterials[0]
            useSelections, returnMat = workerHelpers.getObjectColorMode(
                instanceBlock.data.sceneObject, textBaseMat, exportData)
            if len(instanceMaterials) == 0:
                instanceMaterials.append([])
            instanceMaterials[0] = returnMat
            useInstanceSelection.append(useSelections)
            if useSelections == True:  # if the selections are used on this Instance:
                useSelectionsComplete = True  # the polygonObject must be split into the selections
            allInstanceMaterials.append(instanceMaterials)
            applyToinstanceMaterials.append(instanceMaterials[0])
            if instanceCnt == 0:
                baseGeoMaterials = instanceMaterials
            instanceCnt += 1

        if useSelectionsComplete == True:  # if the polygonObject must be split:
            allMatsDic = {}
            allmaterials = []
            instanceCnt = 0
            allCleanMats = []
            for instanceBlock in meshBlock.data.sceneBlocks:
                if useInstanceSelection[instanceCnt] == True:
                    print str(allInstanceMaterials[instanceCnt])
                    cleanedMats = workerSubMeshReader.cleanMaterialRestriction(
                        meshBlock.data, allInstanceMaterials[instanceCnt]
                    )  # get all the Materials and make shure that each polygon is used ba only one material, delete unused materials
                    allCleanMats.append(cleanedMats)
                    for cleanedMat in cleanedMats:
                        matExists = allMatsDic.get(str(cleanedMat[1].name),
                                                   None)
                        if matExists is None:
                            allMatsDic[str(cleanedMat[1].name)] = cleanedMat
                            cleanedMat.append(instanceBlock)
                            allmaterials.append(cleanedMat)
                if useInstanceSelection[instanceCnt] == False:
                    allCleanMats.append([allInstanceMaterials[instanceCnt][0]])
                instanceCnt += 1
            createGeoMaterials = workerSubMeshReader.mergeMaterialRestriction(
                meshBlock.data, allmaterials)
            instanceCnt = 0
            useFirst = True
            if str(createGeoMaterials[0][1].name) != "Base":
                useFirst = False
            for instanceBlock in meshBlock.data.sceneBlocks:
                newInstanceMats = []
                geoMatCnt = 0
                if useFirst == True:
                    newInstanceMats.append(
                        applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt = 1
                while geoMatCnt < len(createGeoMaterials):
                    if useInstanceSelection[instanceCnt] == True:
                        foundOnInstance = applyToinstanceMaterials[instanceCnt][
                            0]  # if this will not be changed, the baseMaterial will be set for this Submesh
                        for intMat in allCleanMats[instanceCnt]:
                            if str(intMat[1].name) == str(
                                    createGeoMaterials[geoMatCnt][1].name):
                                foundOnInstance = intMat[0]
                                break
                            nameCnt = 0
                            for name in createGeoMaterials[geoMatCnt][
                                    1].multiNames:
                                if str(intMat[1].name) == str(name):
                                    foundOnInstance = createGeoMaterials[
                                        geoMatCnt][1].multiMats[nameCnt]
                                nameCnt += 1
                        newInstanceMats.append(foundOnInstance)
                    if useInstanceSelection[
                            instanceCnt] == False:  # if the instance does not use selections, we just apply the baseMaterial of this instance to all submeshes
                        newInstanceMats.append(
                            applyToinstanceMaterials[instanceCnt][0])
                    geoMatCnt += 1
                instanceBlock.data.saveMaterials = newInstanceMats
                instanceCnt += 1

    if useSelectionsComplete == False:  # if the polygonObject must not be split
        createGeoMaterials = workerSubMeshReader.clearSubmeshIndexe(
            meshBlock.data, baseGeoMaterials)
        instanceCnt = 0
        for instanceBlock in meshBlock.data.sceneBlocks:
            newInstanceMats = []
            geoMatCnt = 0
            newInstanceMats.append(applyToinstanceMaterials[instanceCnt][0])
            instanceBlock.data.saveMaterials = newInstanceMats
            instanceCnt += 1

    if workerthreat.TestBreak():
        return
    poseAnimationDic = {}
    # for all materialBlocks that will be applied to MeshInstanceBlocks, we make shure that they are fully created (the textureBlocks will be created here) and set to tagForExport = True
    for instanceBlock in meshBlock.data.sceneBlocks:
        print "finalMats = " + str(instanceBlock.data.saveMaterials)

        # collect all vertexAnimations found on the InstanceObjects of the Geoemtrys on the Geometry itself (use dictionary to makes shure each animation is only used once)
        for vertexanimationBlock in instanceBlock.data.poseAnimationBlocks:
            addposeAnimationBlock(meshBlock.data.poseAnimationBlocks,
                                  vertexanimationBlock, poseAnimationDic)

        instanceBlock.data.lightPickerIdx = mainLightRouting.getObjectLights(
            instanceBlock.data.sceneObject, exportData
        )  # get the LightPicker for this sceneObject (if the lightpicker does not allready exists, it will be created)
        matCount = 0
        for mat in instanceBlock.data.saveMaterials:
            matAwdBlock = exportData.allAWDBlocks[int(mat)]
            if matAwdBlock is not None:
                repeat = False
                if len(matAwdBlock.data.materialsList) == 0:
                    matAwdBlock.data.materialsList.append(mat)
                    matAwdBlock.data.lightPicker = instanceBlock.data.lightPickerIdx
                    matAwdBlock.data.repeat = False
                    foundMat = mat
                else:
                    foundMat = -1
                    for matID in matAwdBlock.data.materialsList:
                        if exportData.allAWDBlocks[int(
                                matID
                        )].data.lightPicker == instanceBlock.data.lightPickerIdx:
                            if exportData.allAWDBlocks[int(
                                    matID)].data.repeat == repeat:
                                foundMat = matID
                    if foundMat == -1:
                        foundMat = workerHelpers.copyAsNewMaterialBlock(
                            exportData, matAwdBlock,
                            instanceBlock.data.lightPickerIdx, repeat)
                instanceBlock.data.saveMaterials[matCount] = foundMat
                if matAwdBlock.data.isCreated == False and matAwdBlock.data.colorMat == False:
                    matAwdBlock.data.isCreated = True
                    mainMaterials.createMaterial(matAwdBlock.data, exportData)
                #if instanceBlock.data.lightPickerIdx>0:
                #    matAwdBlock.data.lightPickerID=instanceBlock.data.lightPickerIdx
                matAwdBlock.tagForExport = True
            matCount += 1

    for mat in createGeoMaterials:  # create a SubMeshBlock for every Material/selection found and used
        #print "create Submesh: "+str(mat[0])
        meshBlock.data.saveSubMeshes.append(
            classesAWDBlocks.awdSubMesh(mat[0], mat[1].name,
                                        mat[1].selectionIndexe, mat[2]))
    if workerthreat.TestBreak():
        return

    #for instanceMat in allInstanceMaterials

    #for mat in finalMats:    # create a SubMeshBlock for every Material/selection found
    #    for instanceBlock in meshBlock.sceneBlocks:
    #        saveMaterials=

    # if the meshBlock has a WeightTag-applied, we check if the mesh is used by one single skeleton or not.
    weightTag = meshBlock.data.sceneObject.GetTag(c4d.Tweights)
    if weightTag is not None:
        jointCount = weightTag.GetJointCount()
        allSkeletons = getUsedSkeletons(jointCount, weightTag,
                                        exportData.jointIDstoSkeletonBlocks,
                                        exportData.doc)
        if len(allSkeletons) == 0:
            print "Warning - No Joints are bound to a valid Skeleton"
        if len(allSkeletons) > 1:
            print "Warning - Not all Joints are bound to the same Skeleton"
        if len(allSkeletons) == 1:
            meshBlock.data.weightTag = weightTag

    if workerthreat.TestBreak():
        return

    #morphs=[]
    #for morphState in allPointAndUvMorpTag:
    #if morphState.morphedObject==cur_mesh:
    #morphs.append(morphState)
    #for submesh in new_submeshes:
    #for morphState in morphs:
    #submorphVerts=[]
    #submorphUVs=[]
    #submorphActiv=False
    #submorphdata=[submorphVerts,submorphUVs,submorphActiv,morphState.morphName,morphState.tagName,morphState.tagObject]
    #submesh.morphs.append(submorphdata)
    #print ("parse = "+str(meshBlock.sceneObject.GetName()))
    workerSubMeshReader.collectSubmeshData(
        meshBlock.data, exportData,
        workerthreat)  # parse this object into a awd2-geometry-block

    if workerthreat.TestBreak():  # when the user has cancelled the process:
        return  # we stop executing and return

    subMeshNr = 0
    for subMesh in meshBlock.data.saveSubMeshes:  # for every SubMeshBlock that has been created:
        if workerthreat.TestBreak(
        ):  # we check if the user cancelled the process
            return  # and return if he has
        workerSubMeshReader.transformUVS(
            subMesh)  # transform the uvs if needed (to allow for tilling etc)
        if workerthreat.TestBreak():  # check if the user cancelled the process
            return  # and return if he has
        workerSubMeshReader.buildGeometryStreams(
            subMesh, exportData.scale, meshBlock.data.poseAnimationBlocks,
            subMeshNr)  # build the AWD-geometry-streams for all submeshes
        subMeshNr += 1
Example #7
0
def addToExportList(exportData, awdBlock):
    if awdBlock.isReordered == True:
        return awdBlock.saveBlockID
    if awdBlock.isReordered == False:
        if awdBlock.tagForExport == True:
            if awdBlock.blockType == 254:  #NameSpace
                pass  #doThis=True
            if awdBlock.blockType == 255:  #metadata
                pass  #doThis=True
            if awdBlock.blockType == 1:
                pass  #triangel
            if awdBlock.blockType == 11:
                pass  #primitive
            if awdBlock.blockType == 21:
                pass  #scene
            if awdBlock.blockType == 22:  #container
                parentBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.dataParentBlockID)]
                if parentBlock is not None:
                    awdBlock.data.dataParentBlockID = addToExportList(
                        exportData, parentBlock)

            if awdBlock.blockType == 23:  #meshinstance
                parentBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.dataParentBlockID)]
                if parentBlock is not None:
                    awdBlock.data.dataParentBlockID = addToExportList(
                        exportData, parentBlock)
                geoBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.geoBlockID)]
                if geoBlock is not None:
                    awdBlock.data.saveGeoBlockID = addToExportList(
                        exportData, geoBlock)
                awdBlock.data.saveMaterials2 = []
                print str((awdBlock.data.saveGeoBlockID
                           )) + "   geoBlock.saveSubMeshes"
                for mat in awdBlock.data.saveMaterials:
                    matBlockID = addToExportList(
                        exportData, exportData.allAWDBlocks[int(mat)])
                    awdBlock.data.saveMaterials2.append(matBlockID)
                    #print "awdBlock.saveMaterials2 = "+str(awdBlock.saveMaterials2)

            if awdBlock.blockType == 41:  #light
                parentBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.dataParentBlockID)]
                if parentBlock is not None:
                    awdBlock.data.dataParentBlockID = addToExportList(
                        exportData, parentBlock)

            if awdBlock.blockType == 42:  #camera
                parentBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.dataParentBlockID)]

            if awdBlock.blockType == 51:  #lightPicker
                exportData.lightPickerCounter += 1
                awdBlock.data.name += str(exportData.lightPickerCounter)
                for light in awdBlock.data.lightList:
                    lightID = addToExportList(
                        exportData, exportData.allAWDBlocks[int(light)])
                    awdBlock.data.saveLightList.append(lightID)

            if awdBlock.blockType == 81:  #material

                lightPickerBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.lightPicker)]
                if lightPickerBlock is not None:
                    awdBlock.data.saveMatProps.append(22)
                    awdBlock.data.lightPickerID = addToExportList(
                        exportData, lightPickerBlock)
                if awdBlock.data.isCreated == False and awdBlock.data.colorMat == False:
                    awdBlock.data.isCreated = True
                    mainMaterials.createMaterial(awdBlock.data, exportData)
                if awdBlock.data.saveMatType == 2:
                    textureBlock = exportData.allAWDBlocks[int(
                        awdBlock.data.saveColorTextureID)]
                    if textureBlock is not None:
                        awdBlock.data.saveColorTextureID = addToExportList(
                            exportData, textureBlock)
                    normalTextureBlock = exportData.allAWDBlocks[int(
                        awdBlock.data.saveNormalTextureID)]
                    if normalTextureBlock is not None:
                        awdBlock.data.saveNormalTextureID = addToExportList(
                            exportData, normalTextureBlock)
                    ambientTextureBlock = exportData.allAWDBlocks[int(
                        awdBlock.data.saveAmbientTextureID)]
                    if ambientTextureBlock is not None:
                        awdBlock.data.saveAmbientTextureID = addToExportList(
                            exportData, ambientTextureBlock)
                    specTextureBlock = exportData.allAWDBlocks[int(
                        awdBlock.data.saveSpecTextureID)]
                    if specTextureBlock is not None:
                        awdBlock.data.saveSpecTextureID = addToExportList(
                            exportData, specTextureBlock)

            if awdBlock.blockType == 82:  #texture
                pass
            if awdBlock.blockType == 83:  #cubetexture
                pass  #      awdBlock.dataParentBlockID=addToExportList(exportData,parentBlock)
            if awdBlock.blockType == 101:  #skeleton
                pass
            if awdBlock.blockType == 102:  #skeletonpose
                pass
            if awdBlock.blockType == 103:  #skeletonanimation
                for pose in awdBlock.data.framesIDSList:
                    awdBlock.data.framesIDSList2.append(
                        addToExportList(exportData, pose))
            if awdBlock.blockType == 121:  #uvanimation
                pass
            if awdBlock.blockType == 111:  #VertexState
                targetMesh = exportData.allAWDBlocks[int(
                    awdBlock.data.targetMesh)]
                if targetMesh is not None:
                    awdBlock.data.saveTargetMesh = addToExportList(
                        exportData, targetMesh)

            if awdBlock.blockType == 112:  #VertexAnimation
                targetMesh = exportData.allAWDBlocks[int(
                    awdBlock.data.targetMesh)]
                if targetMesh is not None:
                    awdBlock.data.saveTargetMesh = addToExportList(
                        exportData, targetMesh)

            if awdBlock.blockType == 113:  #AnimationSet
                awdBlock.data.saveTargetMesh = addToExportList(
                    exportData, awdBlock.data.targetMesh)
                geoBlock = exportData.allAWDBlocks[int(
                    awdBlock.data.targetMesh.data.geoBlockID)]
                if len(geoBlock.data.saveSubMeshes[0].weightsBuffer) > 0:
                    awdBlock.data.jointsPerVert = len(
                        geoBlock.data.saveSubMeshes[0].weightsBuffer) / (len(
                            geoBlock.data.saveSubMeshes[0].vertexBuffer) / 3)
                print "AnimationNodes in Set = " + str(
                    len(geoBlock.data.saveSubMeshes[0].weightsBuffer))
                print "AnimationNodes in Set = " + str(
                    len(geoBlock.data.saveSubMeshes[0].vertexBuffer))
                print "AnimationNodes in Set = " + str(
                    awdBlock.data.jointsPerVert)
                for anim in awdBlock.data.poseBlockIDs:
                    awdBlock.data.savePoseBlockIDs.append(
                        addToExportList(exportData, anim))

            if awdBlock.blockType == 122:  #Animator
                awdBlock.data.saveMeshID = addToExportList(
                    exportData, awdBlock.data.targetMeshBlock)
                awdBlock.data.saveAnimSetID = addToExportList(
                    exportData, awdBlock.data.animSetBlock)
                print "awdBlock.data.skeleton " + str(awdBlock.data.skeleton)
                if awdBlock.data.skeleton is not None:
                    print "awdBlock.data.skeleton " + str(
                        awdBlock.data.skeleton)
                    awdBlock.data.saveSkeletonID = addToExportList(
                        exportData, awdBlock.data.skeleton)
                print "awdBlock.data.saveSkeletonID " + str(
                    awdBlock.data.saveSkeletonID)
                #awdBlock.saveSkeletonID=addToExportList(exportData,exportData.skeleton)

            print "Reordered Block type = " + str(
                awdBlock.blockType) + "  /  " + str(awdBlock.data)
            awdBlock.saveBlockID = int(len(exportData.allSaveAWDBlocks))
            awdBlock.isReordered = True
            awdBlock.data.saveBlockID = awdBlock.saveBlockID
            exportData.allSaveAWDBlocks.append(awdBlock.data)
            return awdBlock.saveBlockID
def connectInstances(exportData):
    for instanceBlock in exportData.unconnectedInstances:
        isPoly = False
        if instanceBlock.data.sceneObject[c4d.INSTANCEOBJECT_LINK].GetType() == c4d.Opolygon:
            isPoly = True
        geoInstanceID = instanceBlock.data.sceneObject[c4d.INSTANCEOBJECT_LINK].GetName()
        instanceGeoBlock = exportData.allAWDBlocks[int(geoInstanceID)]
        if instanceGeoBlock is not None:
            geoBlockID = instanceGeoBlock.data.geoBlockID
            geoBlock = exportData.allAWDBlocks[int(geoBlockID)]
            if geoBlock is not None:
                instanceBlock.data.geoBlockID = geoBlockID
                geoBlock.data.sceneBlocks.append(instanceBlock)
                if isPoly == False:
                    instanceBlock.data.lightPickerIdx = mainLightRouting.getObjectLights(
                        instanceBlock.targetObject, exportData
                    )  # get the LightPicker for this sceneObject (if the lightpicker does not allready exists, it will be created)
                    if str(geoBlock.blockType) == str(11):
                        if instanceBlock.data.isRenderInstance == True:
                            if geoBlock.data.colorStyle == False:
                                instanceBlock.data.saveMaterials = [geoBlock.data.baseMat]
                            if geoBlock.data.colorStyle == True:
                                if geoBlock.data.hasMats == True:
                                    instanceBlock.data.saveMaterials = [geoBlock.data.baseMat]
                                if geoBlock.data.hasMats == False:
                                    materials = getMaterials(instanceBlock.data.sceneObject, [], True, exportData)
                                    if len(materials) > 0:
                                        instanceBlock.data.saveMaterials = [materials[len(materials) - 1]]
                                    else:
                                        instanceBlock.data.saveMaterials = [-1]
                        if instanceBlock.data.isRenderInstance == False:
                            materials = getMaterials(instanceBlock.data.sceneObject, [], True, exportData)
                            thisMaterial = None
                            if len(materials) > 0:
                                thisMaterial = materials[len(materials) - 1]
                            if geoBlock.data.hasMats == True:
                                thisMaterial = geoBlock.data.baseMat
                            returnList = getObjectColorMode(instanceBlock.data.sceneObject, thisMaterial, exportData)
                            instanceBlock.data.saveMaterials = [returnList[1][0]]
                        matCount = 0
                        for mat in instanceBlock.data.saveMaterials:
                            matAwdBlock = exportData.allAWDBlocks[int(mat)]
                            if matAwdBlock is not None:
                                repeat = False
                                if len(matAwdBlock.data.materialsList) == 0:
                                    matAwdBlock.data.materialsList.append(mat)
                                    matAwdBlock.data.lightPicker = instanceBlock.data.lightPickerIdx
                                    matAwdBlock.data.repeat = False
                                    foundMat = mat
                                else:
                                    foundMat = -1
                                    for matID in matAwdBlock.data.materialsList:
                                        if (
                                            exportData.allAWDBlocks[int(matID)].data.lightPicker
                                            == instanceBlock.data.lightPickerIdx
                                        ):
                                            if exportData.allAWDBlocks[int(matID)].data.repeat == repeat:
                                                foundMat = matID
                                    if foundMat == -1:
                                        foundMat = copyAsNewMaterialBlock(
                                            exportData, matAwdBlock, instanceBlock.data.lightPickerIdx, repeat
                                        )
                                instanceBlock.data.saveMaterials[matCount] = foundMat
                                if matAwdBlock.data.isCreated == False and matAwdBlock.data.colorMat == False:
                                    matAwdBlock.data.isCreated = True
                                    mainMaterials.createMaterial(matAwdBlock.data, exportData)
                                # if instanceBlock.lightPickerIdx>0:
                                # matAwdBlock.lightPickerID=instanceBlock.lightPickerIdx
                                if matAwdBlock.tagForExport == False:
                                    matAwdBlock.tagForExport = True
                            matCount += 1

        instanceBlock.geoBlockID = geoBlockID