Ejemplo n.º 1
0
    def process(self, ga):
        self._item_info = lwsdk.LWItemInfo()

        instance_null = lwsdk.find_object_by_name("InstanceNull",
                                                  self._item_info)
        if not instance_null:
            return lwsdk.AFUNC_OK

        instance_null_id = lwsdk.itemid_to_str(instance_null)
        lwsdk.command("SelectItem %s" % instance_null_id)

        server_name = self._item_info.server(instance_null, "InstancerHandler",
                                             1)
        if not server_name:
            print >> sys.stderr, 'No Instancer server found for object "InstanceNull"!'
            return lwsdk.AFUNC_OK

        server_flags = self._item_info.serverFlags(instance_null,
                                                   "InstancerHandler", 1)
        if (server_flags & lwsdk.LWSRVF_DISABLED):
            lwsdk.command("EnableServer InstancerHandler 0 1")
        else:
            lwsdk.command("EnableServer InstancerHandler 0 0")

        return lwsdk.AFUNC_OK
Ejemplo n.º 2
0
    def evaluate(self, da):
        item_info = lwsdk.LWItemInfo()

        pivot = item_info.param(self._itemid, lwsdk.LWIP_PIVOT, self._time)
        oPos = lwsdk.Vector(da.oPos)
        original = oPos - pivot
        magnitude = lwsdk.Vector.magnitude(oPos, pivot)
        lag_time = self._time - self._lag_rate * magnitude

        xax = item_info.param(self._itemid, lwsdk.LWIP_RIGHT, lag_time)
        yax = item_info.param(self._itemid, lwsdk.LWIP_UP, lag_time)
        zax = item_info.param(self._itemid, lwsdk.LWIP_FORWARD, lag_time)
        pos = item_info.param(self._itemid, lwsdk.LWIP_W_POSITION, lag_time)

        da.source = [
                    pos.x + original.x * \
                    xax.x + original.y * \
                    yax.x + original.z * zax.x,

                    pos.y + original.x * \
                    xax.y + original.y * \
                    yax.y + original.z * zax.y,

                    pos.z + original.x * \
                    xax.z + original.y * \
                    yax.z + original.z * zax.z
                    ]
Ejemplo n.º 3
0
    def __init__(self, context):
        super(split_bone, self).__init__()
        # context has no relevant value in a LayoutTool plug-in

        self._item_info      = lwsdk.LWItemInfo()
        self._bone_info      = lwsdk.LWBoneInfo()
        self._envelope_funcs = lwsdk.LWEnvelopeFuncs()
        self._channel_info   = lwsdk.LWChannelInfo()

        self._frac   = 0.5
        self._dirty  = False
        self._handle = -1
        self._moved  = False

        self._bones = None
Ejemplo n.º 4
0
    def __init__(self, context):
        super(sol, self).__init__()
        self._itemid = context
        self._name = lwsdk.LWItemInfo().name(self._itemid)

        # pre-calculate some values for performance

        self._r = planet_au[self._name] * AU
        self._s = (planet_r[self._name] * math.pow(10, 3)) / AU
        self._b = planet_tilt[self._name]

        self.adjust_scaling()

        # this next calculation is Newton's version of Kepler's 3rd Law.
        # its result has units in seconds (where Kepler's original law was
        # in years), so the result is the number of seconds it takes the
        # object to traverse its orbit (2piR).

        self._p = math.sqrt((4 * math.pow(math.pi, 2) * math.pow(self._r, 3)) /
                            (6.67e-11 * 1.99e30))
Ejemplo n.º 5
0
    def __init__(self,
                 context):  # context has no relevant value in a Master plug-in
        super(ring_test, self).__init__()

        self._item_info = lwsdk.LWItemInfo()

        self._ui = lwsdk.LWPanels()
        self._panel = None

        self._comring = lwsdk.LWComRing()

        self._selected_camera = None
        self._selected_camera_name = None
        self._camera_active = {}
        self._camera_radii = {}
        self._camera_target = {}

        self._target_object = None

        # connect to the channel
        self._comring.ringAttach("ringtest_channel", self, self.ring_event)
Ejemplo n.º 6
0
    def process(self, ga):
        ui = lwsdk.LWPanels()
        panel = ui.create('Final Fantasy 7:Remake  Import')

        controlWidth = 64
        c1 = panel.load_ctl('Select File', controlWidth)
        c1.set_str(self._filepath)

        if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0:
            ui.destroy(panel)
            return lwsdk.AFUNC_OK

        self.filepath = c1.get_str()
        progress_count = 8

        t1 = time.time()

        interface_info = lwsdk.LWInterfaceInfo()
        if not (interface_info.generalFlags & lwsdk.LWGENF_PARENTINPLACE):
            ga.evaluate(ga.data, "ParentInPlace")

        #set bind pose at frame -10
        ga.evaluate(ga.data, "GoToFrame -10")

        interface_info = lwsdk.LWInterfaceInfo()
        selected_items = interface_info.selected_items()

        #if a mesh not selected create a parent null for the bones
        if not selected_items:
            result = ga.evaluate(ga.data, "AddNull Root")
            interface_info = lwsdk.LWInterfaceInfo()
            selected_items = interface_info.selected_items()
            buildItemID = selected_items[0]
        else:
            item_info = lwsdk.LWItemInfo()
            mytype = item_info.type(selected_items[0])
            if mytype == lwsdk.LWI_OBJECT:
                buildItemID = selected_items[0]
            else:
                result = ga.evaluate(ga.data, "AddNull Root")
                interface_info = lwsdk.LWInterfaceInfo()
                selected_items = interface_info.selected_items()
                buildItemID = selected_items[0]

        #get weightmap count
        object_functions = lwsdk.LWObjectFuncs()
        numWeights = object_functions.numVMaps(lwsdk.LWVMAP_WGHT)

        files = path_wrangler(self.filepath)
        files.get_files()

        md = open(files.data['uexp'], 'rb')
        ua = open(files.data['uasset'], 'rb')

        meshName = files.data['meshName']
        submesh_name = files.data['submesh_name']

        arm = False
        weightData = {}
        Weight_array = []
        vertexArray = []
        NA = []
        normal_array = []

        UVs0 = []
        UVs1 = []
        UVs2 = []
        UVs3 = []
        UVs4 = []

        faces = []

        names = readUasset(ua)
        ua.close()

        pattern0 = re.compile(
            b'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00........')
        for x in xrange(20000):
            s1 = struct.unpack("18s", md.read(18))[0]
            if pattern0.match(s1):
                c0 = struct.unpack("<L", md.read(4))[0]
                c1 = struct.unpack("<L", md.read(4))[0]
                c2 = struct.unpack("<L", md.read(4))[0]
                c3 = struct.unpack("<L", md.read(4))[0]
                c4 = struct.unpack("<L", md.read(4))[0]
                if (c0 and c1 and c2 and c3 and c4 > 1000000000):
                    break
                else:
                    md.seek(-20, 1)
            md.seek(-17, 1)

        materialCount = struct.unpack("<L", md.read(4))[0]

        materials = {}
        for m in xrange(materialCount):
            materials[m] = {}
            materials[m]['val0'] = struct.unpack("<l", md.read(4))[0]
            stringIndex = struct.unpack("<L", md.read(4))[0]
            unk0 = struct.unpack("<L", md.read(4))[0]
            unk1 = struct.unpack("<L", md.read(4))[0]
            unk2 = struct.unpack("<L", md.read(4))[0]
            unk3 = struct.unpack("<f", md.read(4))[0]
            unk4 = struct.unpack("<f", md.read(4))[0]
            unk5 = struct.unpack("<L", md.read(4))[0]
            unk6 = struct.unpack("<L", md.read(4))[0]

            materials[m]['name'] = names[stringIndex]

        boneCount = struct.unpack("<L", md.read(4))[0]
        joint_data = {}
        joint_names = []
        for i in xrange(boneCount):
            string_index = struct.unpack("<L", md.read(4))[0]
            jName = names[string_index]
            unk = struct.unpack("<L", md.read(4))[0]
            parent = struct.unpack("<l", md.read(4))[0]

            joint_data[i] = {"name": jName, "parent": parent}

        boneCount2 = struct.unpack("<L", md.read(4))[0]

        progress_count += boneCount2
        if not moninit(progress_count, "Importing", title='Progress'):
            raise Exception('Hell!')

        boneArray = []
        psn = {}
        IDs = []
        for bn in range(boneCount2):
            boneName = joint_data[bn]["name"]
            BNparent = joint_data[bn]["parent"]

            m1 = struct.unpack("<10f", md.read(40))

            ps0 = (m1[4], m1[5], m1[6])
            #BNps = np.asarray(ps0)

            rt0_ = (m1[3], m1[0], m1[1], m1[2])
            rt0 = quat2mat(rt0_)

            if BNparent == -1:
                BNparent = 0

            #BNps = [mi[3,1], mi[3,2], mi[3,0]]
            BNps = ps0
            psn[bn] = BNps

            #BNrt = mat2euler(mi, axes='ryxz')

            ga.evaluate(ga.data,
                        "SelectItem %s" % lwsdk.itemid_to_str(buildItemID))
            layoutCommand = "AddBone " + boneName
            result = ga.evaluate(ga.data, layoutCommand)

            # no influence except for weight maps
            result = ga.evaluate(ga.data, 'BoneStrength 0')
            interface_info = lwsdk.LWInterfaceInfo()
            selected_items = interface_info.selected_items()
            itemID = selected_items[0]
            IDs.append(itemID)

            #UpdateMotion needed for parent in place
            if bn != 0:
                ga.evaluate(ga.data, 'UpdateMotion')
                ga.evaluate(
                    ga.data,
                    "ParentItem %s" % lwsdk.itemid_to_str(IDs[BNparent]))

            layoutCommand = "Position " + str(BNps[0]) + " " + str(
                BNps[1]) + " " + str(BNps[2])
            result = ga.evaluate(ga.data, layoutCommand)

            if bn == 0:
                result = ga.evaluate(ga.data, "BoneRestLength 0.5")
            else:
                lenX = psn[BNparent][0] - BNps[0]
                lenY = psn[BNparent][1] - BNps[1]
                lenZ = psn[BNparent][2] - BNps[2]

                #dont use full bone length....dummy
                boneLength = math.sqrt(lenX * lenX + lenY * lenY +
                                       lenZ * lenZ) * 0.6
                result = ga.evaluate(ga.data,
                                     "BoneRestLength " + str(boneLength))

            #BNrt = quat2euler(rt0_, axes='szyx')
            BNrt = quat2euler(rt0_, axes='ryxz')
            rotx = (180.0 / math.pi) * BNrt[0]
            roty = (180.0 / math.pi) * BNrt[1]
            rotz = (180.0 / math.pi) * BNrt[2]

            layoutCommand = "Rotation " + str(rotx) + " " + str(
                roty) + " " + str(rotz)
            result = ga.evaluate(ga.data, layoutCommand)

            if bn == 0:
                layoutCommand = "Rotation " + str(180.0) + " " + str(
                    180.0) + " " + str(0.0)
                result = ga.evaluate(ga.data, layoutCommand)

            # if 'autokey' is not turned on, we need to explicitly
            # create keys for the object at the current time offset
            if not (interface_info.generalFlags & lwsdk.LWGENF_AUTOKEY):
                ga.evaluate(ga.data, "CreateKey %f" % interface_info.curTime)

            #keys created at frame -10 so delete any at frame 0
            ga.evaluate(ga.data, 'DeleteKey 0')

            if (numWeights > 0):
                if bn != 0:
                    for b in range(numWeights):
                        weightName = object_functions.vmapName(
                            lwsdk.LWVMAP_WGHT, b)
                        if weightName == boneName:
                            layoutCommand = 'BoneWeightMapName ' + boneName
                            result = ga.evaluate(ga.data, layoutCommand)
                            result = ga.evaluate(ga.data, 'BoneWeightMapOnly')
            ga.evaluate(ga.data, 'RecordRestPosition')

            monstep()

        #-----------------------------------------------------------#
        boneCount3 = struct.unpack("<L", md.read(4))[0]
        md.seek(boneCount3 * 12, 1)
        vertexGroups = {}
        unk0 = struct.unpack("<L", md.read(4))[0]
        unk1 = struct.unpack("B", md.read(1))[0]
        unk2 = struct.unpack("B", md.read(1))[0]
        groupCount = struct.unpack("<L", md.read(4))[0]
        for m in xrange(groupCount):
            z1 = struct.unpack("<H", md.read(2))[0]
            ID = struct.unpack("<H", md.read(2))[0]

            md.seek(24, 1)
            vertexGroups[ID] = {'range': 0, 'bones': []}

            # pragma region bone palette
            start = struct.unpack("<L", md.read(4))[0]
            count = struct.unpack("<L", md.read(4))[0]
            vertexGroups[ID]['bones_np'] = np.zeros((boneCount2, ), dtype=int)
            bone_names = []
            for bn in xrange(count):
                bid = struct.unpack("<H", md.read(2))[0]
                vertexGroups[ID]['bones_np'][bn] = bid
                vertexGroups[ID]['bones'].append(bid)
                bone_names.append(joint_data[bid]["name"])
            # pragma endregion bone palette

            size = struct.unpack("<L", md.read(4))[0]
            stop = start + size
            vertexGroups[ID]['range'] = np.arange(start, stop)
            vertexGroups[ID]["start"] = start
            vertexGroups[ID]["stop"] = stop
            vertexGroups[ID]["size"] = size
            vertexGroups[ID]["names"] = bone_names

            md.seek(34, 1)
            FFx4 = readHexString(md, 4)
            flag = struct.unpack("<L", md.read(4))[0]
            if flag:  # extra data for this group
                count = struct.unpack("<L", md.read(4))[0]
                md.seek(count * 16, 1)
            else:
                null = struct.unpack("<L", md.read(4))[0]

        process_surfaces(files, vertexGroups, materials)
        #-----------------------------------------------------------#

        ga.evaluate(ga.data, 'SelectAllBones')
        #ga.evaluate(ga.data, 'RecordRestPosition')
        bonemayastyledraw()
        itemiconscale(0.2)

        monend()

        elapsed = time.time() - t1
        print "Time: " + str(elapsed)

        md.close()

        return lwsdk.AFUNC_OK
Ejemplo n.º 7
0
    def process(self, generic_access):
        #launch interface

        ui = lwsdk.LWPanels()
        panel = ui.create('Package Scene')
        panel.setw(750)

        # The consolidate option doesn't move anything, but grabs all assets and puts them in the content structure
        # you're currently using

        self.consolidate_check = panel.bool_ctl("Consolidate files only")
        self.consolidate_check.move(150, self.consolidate_check.y() )
        self.consolidate_check.set_event(self.consolidate_active )

        # The panel.dir_ctl() call creates a requester in which you'll choose the destination folder

        self.target_folder = panel.dir_ctl("Destination folder:", 98)
        self.target_folder.set_event(self.refresh_items)
        self.preserve_check = panel.bool_ctl("Preserve Existing Structure")

        # Subfolders are folders that go below the Objects, Scenes, and Images folders, should they be needed.

        self.asset_string = panel.str_ctl("Subfolder:", 72)
        self.asset_string.set_event(self.refresh_items)

        # This gives the user the option of whether to copy complete image sequences or not.
        # If the user opts not to copy the sequences, only the first image of the sequence will be copied

        self.imseq_check = panel.bool_ctl("Copy Image Sequences")
        self.imseq_check.set_event(self.imseq_active)

        # This selection box gives the user the option to either consolidate all images (including sequences)
        # into the target Images directory, or to have subfolders created for image sequences to keep
        # them neat and tidy

        self.imsub_list = []
        self.imsub_list.append("Root Images folder")
        self.imsub_list.append("Sequence-named subfolder")
        self.imsub_choice = panel.hchoice_ctl("Image sequence destination:", self.imsub_list)
        self.imseq_active(self, self.imseq_active)

        # This displays the eventual path destinations for the individual asset types

        self.sc_string = panel.dir_ctl("Scenes path:", 98)
        self.ob_string = panel.dir_ctl("Objects path:", 98)
        self.im_string = panel.dir_ctl("Images path:", 98)
        self.dyn_string = panel.dir_ctl("Dynamics path:", 98)
        self.ies_string = panel.dir_ctl("Photometric lights path:",98)
        self.rad_string = panel.dir_ctl("Radiosity Cache path:",98)
        self.vert_string = panel.dir_ctl("Vertex Cache path:",98)

        self.radsave_check = panel.bool_ctl("Copy Radiosity cache file")
        self.radsave_check.set_event(self.radcache_active)
        self.radcache_active(self, self.radcache_active)
        self.radsave_check.set_int(1)
        self.rad_string.unghost()
        self.reload_check = panel.bool_ctl("Reload Original Scene")

        panel.align_controls_vertical([self.consolidate_check,
                                       self.target_folder,
                                       self.preserve_check,
                                       self.asset_string,
                                       self.imseq_check,
                                       self.imsub_choice,
                                       self.sc_string,
                                       self.ob_string,
                                       self.im_string,
                                       self.dyn_string,
                                       self.ies_string,
                                       self.rad_string,
                                       self.vert_string,
                                       self.radsave_check,
                                       self.reload_check])

        self.target_folder.set_str(self.content_dir)
        self.refresh_items(None,None)
        if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0:
            ui.destroy(panel)
            return lwsdk.AFUNC_OK

        #end interface ------------------------------------------------------------------------

        #getting values ------------------------------------------------------------------------

        self.consolidate = self.consolidate_check.get_int()

        self.target_dir = self.target_folder.get_str()
        self.preserve = self.preserve_check.get_int()
        self.asset_str = self.asset_string.get_str()

        self.imseq = self.imseq_check.get_int()
        self.imsub = self.imsub_choice.get_int()

        self.ob_dir = self.ob_string.get_str()
        self.sc_dir = self.sc_string.get_str()
        self.im_dir = self.im_string.get_str()
        self.dyn_dir = self.dyn_string.get_str()
        self.ies_dir = self.ies_string.get_str()
        self.rad_dir = self.rad_string.get_str()
        self.vert_dir = self.vert_string.get_str()
        self.radsave = self.radsave_check.get_int()

        self.reload = self.reload_check.get_int()
        
        #end getting values ------------------------------------------------------------------------

        self.comring.ringAttach(self.RINGNAME,self,self.comring_event)
        data = self.comring.encodeData("s:512#2",(self.content_dir, self.target_dir));
        self.comring.ringMessage(self.RINGNAME,1,data); # event #1 would be "copy to new content"
        #self.comring.ringDetatch(self.RINGNAME)

        #begin image processing ------------------------------------------------------------------------
        if self.images.first() != None:  # there are images to be worked on
            if self.consolidate == True:
                asset_str = ""

                self.target_dir = self.content_dir
                self.ob_dir = self.consol_string("Objects")
                self.sc_dir = self.consol_string("Scenes")
                self.im_dir = self.consol_string("Images")
                self.dyn_dir = self.consol_string("Dynamics")
                self.ies_dir = self.consol_string("Lights")
                self.rad_dir = self.consol_string("Radiosity")
                self.vert_dir = self.consol_string("VertCache")

            for currentImage in self.imageMasterList:            
                #construct new path
                currentfile = self.images.filename(currentImage,0)  #current filename from the big list
                currentname = self.images.name(currentImage)
                if self.content_dir in currentfile:
                    validContent = True
                else:
                    validContent = False
# sequence section ----
                if '(sequence)' in currentname and self.imseq == True:              #is a sequence and wants to copy it
                    if validContent == True and self.preserve == 1:                 #wants to preserve, and has a chance
                        #target is the destination content + original directory
                        image_target = os.path.join(self.target_dir,os.path.dirname(currentfile).replace(self.content_dir,'').strip('\\/') )   
                    else:                                                           #don't want to preserve or can't
                        image_target = self.im_dir                                  #not valid content directory, can't preserve
                    
                    first_image = self.copy_sequence(currentfile, currentname, image_target, self.imsub)    # process and copy sequence
                    self.images.replace(currentImage, first_image)

# image section ----------
                else:                                                               #not a sequence
                    if validContent == True and self.preserve == 1:                 #wants to preserve, and has a chance
                        #target is the destination content + original directory
                        image_target = os.path.join(self.target_dir,os.path.dirname(currentfile).replace(self.content_dir,'').strip('\\/') )
                    else:
                        image_target = self.make_content_target(currentfile,self.im_dir)    #get the destination target path
                        self.psCopy(currentfile, image_target)                          #copy, making directories if necessary
                        self.images.replace(currentImage, image_target)                 #replace old image with new
        else:  # no images loaded
            pass # "No Images to copy"

# end image processing -----------------------------

        lwsdk.command("ContentDirectory " + self.target_dir)

# begin object processing ---------------------------------------------

#get object list

        item_info = lwsdk.LWItemInfo()
        obj_info = lwsdk.LWObjectInfo()

        objlist = []
        myobj = item_info.first( lwsdk.LWI_OBJECT, lwsdk.LWITEM_NULL )
        if myobj != lwsdk.LWITEM_NULL:
            objlist.append( myobj )
            while myobj != lwsdk.LWITEM_NULL:
                myobj = item_info.next( myobj )
                if myobj != lwsdk.LWITEM_NULL:
                    objlist.append( myobj )
#get destination path

            for obj in objlist:
                #if item_info.name( obj ) != obj_info.filename( obj ):   # probably isn't a null object
                if obj_info.numPoints( obj ) != 1 and obj_info.numPolygons( obj ) != 0:
                    if self.preserve == True and os.path.dirname(obj_info.filename( obj )) != self.content_dir and self.content_dir in obj_info.filename( obj ):   # valid and can preserve
                        ob_path = obj_info.filename( obj ).replace(self.content_dir,'')
                        new_path = os.path.join(self.ob_dir, ob_path)
                    else:
                        new_path = os.path.join(self.ob_dir, os.path.basename(obj_info.filename( obj )))
                    try:
                        os.makedirs( os.path.dirname(new_path) )
                    except:
                        try:
                            os.makedirs( os.path.dirname(new_path) + os.sep )
                        except:
                            myerr = sys.exc_value
#save object to new path
                    if os.path.lexists( os.path.dirname(new_path) ) == True:
                        lwsdk.command("SelectByName " + item_info.name( obj ))
                        lwsdk.command("SaveObject " + new_path)
                else:
                    pass # "Must be null"

# end object processing ------------------

# begin scene processing -----------------
        if self.preserve == 1 and self.content_dir in self.scene.filename and os.path.dirname(self.scene.filename) != self.content_dir:
            sc_sub = self.scene.filename.replace(self.content_dir,'')
            new_scene = os.path.join(self.sc_dir, sc_sub, self.scene.name)
        else:
            new_scene = os.path.join(self.sc_dir, self.scene.name)

        try:
            os.makedirs( os.path.dirname(new_scene) )
        except:
            try:
                os.makedirs( os.path.dirname(new_scene) + os.sep )
            except:
                myerr = sys.exc_value

        if os.path.lexists( os.path.dirname(new_scene) ) == True:
            tempdir = tempfile.mkdtemp()
            tempscene = os.path.join(tempdir, self.scene.name)
            lwsdk.command("SaveSceneCopy " + tempscene)

        infile = open(tempscene, "r")
        lines = infile.readlines()
        infile.close()

        outfile = open(new_scene, 'w')

        photo_on = False
        bdd_on = False
        mdd_on = False
        vert_on = False
        mddnode_on = False
        flock_on = False

        # scan scene for ancillary files
        for l in lines:
            l = l.replace('\n','')  # strip newline

            # 1. Get path
            # 2. Find old item
            # 3. Prepare new path
            # 4. Copy old item to new path
            # 5. Write new path to Scene file

            #process bdd files

            #if ".bdd" in l:  # l is the line out of the Scene file
            if "FX_Break" in l:     # l is the line out of the Scene file
                bdd_on = True   # Switch this on, since we've found a BDD line
                outfile.write(l + "\n")

            elif ".bdd" in l and bdd_on == True:
                bddunc = False  # Start out assuming it is NOT a UNC path
                if l.startswith("\\\\"):
                    bddunc = True       # If the line starts with at double-backslash, fair bet it's a UNC path
                ls = l.replace('\\','/')
                oldbddpath = os.path.join(self.content_dir, ls )
                if self.preserve == True:
                    if content_dir in oldbddpath:
                        preserve = True
                    else:
                        preserve = False
                if preserve == True and self.preserve == True:
                    newbddpath = os.path.join(self.target_dir, os.path.dirname(ls), os.path.basename(ls) )
                else:
                    newbddpath = os.path.join(self.dyn_dir, os.path.basename(ls) )
                self.psCopy(oldbddpath.replace('\\','/'), newbddpath.replace('\\','/') )
                if bddunc == True:
                    outfile.write( newbddpath + "\n")
                else:
                    outfile.write( l + "\n")

            elif "EndPlugin" in l and bdd_on == True:
                outfile.write(l + "\n")
                outfile.write("\n")
                bdd_on = False

            elif "FX_MotionDrive" in l:
                mdd_on = True
                outfile.write(l + "\n")
            elif ".mdd" in l and mdd_on == True:
                mdd_on = False
                l = l.replace('\\','/')
                oldmddpath = os.path.join(self.content_dir, l)
                if self.preserve == True:
                    newmddpath = os.path.join(self.target_dir, l)
                else:
                    newmddpath = os.path.join( self.dyn_dir, os.path.basename(l) )
                self.psCopy(oldmddpath, newmddpath)
                outfile.write( l + "\n" )

            elif "MD_Plug" in l:
                vert_on = True
                outfile.write( l + "\n" )

            elif ".mdd" in l and vert_on == True and mddnode_on == False:
                vertunc = False
                oldvertpath = os.path.join( self.content_dir, l.strip().replace('\"','') )
                if oldvertpath.startswith("\\\\"):
                    vertunc = True
                ls = l.strip().replace('\"','').split('\\/')
                newvertpath = os.path.join( self.vert_dir, os.path.basename(l.strip().replace('\"','') )  )
                if vertunc == True:
                    oldvertnorm = os.path.normpath(oldvertpath)
                    oldvertnorm = oldvertnorm.replace(r'\\\\',r'\\')
                    self.psCopy(oldvertnorm, newvertpath)
                else:
                    self.psCopy(oldvertpath, newvertpath)
                outline = '    \"' + self.strip_first_slash(newvertpath[len(self.target_dir):]) + '\"\n'
                outfile.write(outline)
                vert_on = False

            elif ".xml" in l and vert_on == True and mddnode_on == False:
                xmlunc = False
                oldvertpath = os.path.join( self.content_dir, l.strip().replace('\"','') )
                oldmc = os.path.splitext(oldvertpath)[0] + ".mc"
                if oldvertpath.startswith("\\\\"):
                    xmlunc = True
                ls = l.strip().replace('\"','').split('\\/')
                newvertpath = os.path.join( self.vert_dir, os.path.basename(l.strip().replace('\"','') )  )
                newmc = os.path.splitext(newvertpath)[0] + ".mc"
                if xmlunc == True:
                    oldvertnorm = os.path.normpath(oldvertpath)
                    oldvertnorm = oldvertnorm.replace(r'\\\\',r'\\')
                    oldmcnorm = os.path.normpath(oldmc)
                    oldmcnorm = oldmcnorm.replace(r'\\\\',r'\\')
                    self.psCopy(oldvertnorm, newvertpath)
                    self.psCopy(oldmcnorm, newmc)
                    self.copy_mc_sequence(oldmcnorm, newmc)
                else:
                    self.psCopy(oldvertpath, newvertpath)
                    self.psCopy(oldmc, newmc)
                    self.copy_mc_sequence(oldmc, newmc)
                outline = '    \"' + self.strip_first_slash(newvertpath[len(self.target_dir):]) + '\"\n'
                outfile.write(outline)
                vert_on = False

            elif "{ MDReader" in l:
                outfile.write( l + "\n" )

            elif "MDD_Node" in l:
                mddnode_on = True
                outfile.write( l + "\n")

            elif ".mdd" in l and mddnode_on == True and vert_on == False:
                mddnode_on = False
                l = l.replace('\\','/')
                oldvertpath = os.path.join( self.content_dir, l.strip().replace('\"','') )
                ls = l.strip().replace('\"','').split('\\/')
                newvertpath = os.path.join( self.vert_dir, os.path.basename(l.strip().replace('\"','') )  )
                self.psCopy(oldvertpath, newvertpath)
                outline = '\"' + self.strip_first_slash(newvertpath[len(self.target_dir):]) + '\"\n'
                outfile.write('        Filename ' + outline )

            # Process Particle FX files
            elif ".pfx" in l:
                pfxunc = False
                lsplit = l.split(None,5)
                ls = os.path.normpath(lsplit[5])
                if ls.startswith("\\\\"):    #UNC path
                    pfxunc = True
                if '\\' in ls or '/' in ls:  # this section is for the Mac, if it's having trouble
                    lsp = ls.split('\\')     # dealing with backslashes
                    ls = lsp[-1]
                oldpfxpath = os.path.join( self.content_dir,lsplit[5] )

                if self.content_dir in oldpfxpath:
                    preserve = True
                else:
                    preserve = False

                if preserve == 1 and self.preserve == 1:
                    newpfxpath = os.path.join(self.target_dir,lsplit[5])
                else:
                    newpfxpath = os.path.join(self.dyn_dir, os.path.basename(ls) )
                psCopySource = oldpfxpath.replace('\\','/')
                psCopyDest = newpfxpath.replace('\\','/')
                self.psCopy(psCopySource, psCopyDest)

                lsplit[5] = newpfxpath

                outline = ' '.join(lsplit)
                outfile.write(" " + outline + "\n")

            # Process IES Lights
            elif "Plugin LightHandler" in l and "PhotometricLight" in l:
                outfile.write("Plugin LightHandler 1 PhotometricLight\n")
                photo_on = True

            elif photo_on == True and "File \"" in l:
                oldiespath = l[8:-1]
                if oldiespath[:1] == ":":
                    oldiespath = os.sep + oldiespath[1:]
                newiespath = os.path.join(self.ies_dir, os.path.basename(oldiespath))
                if newiespath[:1] == ":":
                    newiespath = os.sep + newiespath[1:] 
                outfile.write('  File \"' + self.strip_first_slash(newiespath) + '\"\n')
                self.psCopy(oldiespath, newiespath)
                photo_on = False

            # Process Radiosity Cache files
            elif "RadiosityCacheFilePath" in l and self.radsave == True:
                l = l.split(None,1)[1]
                oldradpath_drive = os.path.splitdrive(l)[0]
                oldradpath_path = os.path.dirname(os.path.splitdrive(l)[1])
                oldradpath_file = os.path.basename(l)
                if oldradpath_drive != None:
                    oldradpath = os.path.join(oldradpath_drive, oldradpath_path, oldradpath_file).replace('\\','/')
                    if oldradpath[:1] == ":":
                        oldradpath = os.sep + oldradpath[1:]
                else:
                    oldradpath = os.path.join(self.content_dir, l)
                newradpath = os.path.join(self.rad_dir, oldradpath_file).replace('\\','/')
                if newradpath[:1] == ":":
                    newradpath = os.sep + newradpath[1:]
                self.psCopy(oldradpath, newradpath )
                outfile.write('RadiosityCacheFilePath ' + self.strip_first_slash(newradpath) + "\n")

            #Copy flocking cache data
            elif "FlockMaster" in l:
                outfile.write(l + "\n")
                flock_on = True
                flock_count = 1

            elif flock_on == True and flock_count == 1:
                outfile.write(l + "\n")
                flock_count = flock_count + 1

            elif flock_on == True and flock_count == 2:
                flock_count = flock_count + 1
                flockunc = False
                lsplit = l.replace("\"",'')
                ls = os.path.normpath(lsplit)
                if ls.startswith("\\\\"):
                    flockunc = True
                if '\\' in ls or '/' in ls:
                    lsp = ls.split('\\')
                    ls = lsp[-1]
                oldflockpath = os.path.join( self.content_dir, lsplit)
                if self.preserve == True:
                    if self.content_dir in oldflockpath:
                        preserve = True
                    else:
                        preserve = False
                if self.preserve == True and preserve == True:
                    newflockpath = os.path.join(self.dyn_dir, ls)
                else:
                    newflockpath = os.path.join(self.dyn_dir, os.path.basename(ls))
                psCopySource = os.path.normpath(oldflockpath)
                psCopyDest = os.path.normpath(newflockpath)
                self.psCopy(psCopySource, psCopyDest)
                newflockwrite = '\"' + newflockpath.replace('\\','\\\\') + '\"'

            elif flock_on == True and "EndPlugin" in l:
                flock_on = False
                outfile.write(l + "\n")

            else:   #if nothing matched, just pass the line right through to the new scene
                outfile.write( l + "\n")

        # copy over Bullet dynamics cache file
        if os.path.lexists(os.path.join( self.content_dir, "Dynamics") ):
            dynasource = os.path.join( self.content_dir, "Dynamics", self.scene.name[:-4]) + ".dynacache"
            dynadest = os.path.join( self.dyn_dir, os.path.basename( dynasource ) )
            self.psCopy(dynasource, dynadest)

        outfile.close()

        self.psCopy(tempscene, new_scene)
        if self.reload == True:
            lwsdk.command("LoadScene " + self.scene.filename)
        else:
            lwsdk.command("LoadScene " + new_scene)

        os.remove(tempscene)
        os.rmdir(tempdir)

        return lwsdk.AFUNC_OK
Ejemplo n.º 8
0
    def process(self, ga):
        ui = lwsdk.LWPanels()
        panel = ui.create('Scatter Objects')

        c1 = panel.dist_ctl('Radius')
        c2 = panel.bool_ctl('X')
        c3 = panel.bool_ctl('Y')
        c4 = panel.bool_ctl('Z')

        c1.set_float(self._radius)
        c2.set_int(1 if self._include_x else 0)
        c3.set_int(1 if self._include_y else 0)
        c4.set_int(1 if self._include_z else 0)

        panel.align_controls_vertical([c1, c2, c3, c4])
        panel.size_to_layout(5, 5)

        if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0:
            ui.destroy(panel)
            return lwsdk.AFUNC_OK

        self._radius = c1.get_float()
        self._include_x = (c2.get_int() == 1)
        self._include_y = (c3.get_int() == 1)
        self._include_z = (c4.get_int() == 1)

        ui.destroy(panel)

        item_info = lwsdk.LWItemInfo()

        interface_info = lwsdk.LWInterfaceInfo()
        current_time = interface_info.curTime
        autokey_is_on = ((interface_info.generalFlags & lwsdk.LWGENF_AUTOKEY) != 0)
        selected_items = interface_info.selected_items()

        for obj in selected_items:
            r = random()
            x_invert = -1 if r < 0.5 else 1
            x_value = 0.0
            if self._include_x:
                x_value = random() * self._radius * x_invert

            r = random()
            y_invert = -1 if r < 0.5 else 1
            y_value = 0.0
            if self._include_y:
                y_value = random() * self._radius * y_invert

            r = random()
            z_invert = -1 if r < 0.5 else 1
            z_value = 0.0
            if self._include_z:
                z_value = random() * self._radius * z_invert

            ga.evaluate(ga.data, "SelectItem %s" % lwsdk.itemid_to_str(obj))
            ga.evaluate(ga.data, "Position %f %f %f" % (x_value, y_value, z_value))

            if not autokey_is_on:
                ga.evaluate(ga.data, "CreateKey %f" % current_time)

        return lwsdk.AFUNC_OK
Ejemplo n.º 9
0
    def __init__(self, context):
        super(frame_timer, self).__init__()

        self._itemid = context
        self._name = lwsdk.LWItemInfo().name(self._itemid)
Ejemplo n.º 10
0
    def process(self, ga):
        item_info = lwsdk.LWItemInfo()
        object_info = lwsdk.LWObjectInfo()
        instancer_funcs = lwsdk.LWItemInstancerFuncs()
        instance_info = lwsdk.LWItemInstanceInfo()
        interface_info = lwsdk.LWInterfaceInfo()

        current_time = interface_info.curTime
        autokey_is_on = ((interface_info.generalFlags & lwsdk.LWGENF_AUTOKEY)
                         != 0)

        selected_item = interface_info.selected_items()[0]
        selected_item_id = lwsdk.itemid_to_str(selected_item)

        # find the Instancer that owns the selected object
        found_instancer = None
        obj = item_info.first(lwsdk.LWI_OBJECT, None)
        while obj and (not found_instancer):
            instancer = object_info.instancer(obj)
            if instancer:
                instance = instancer_funcs.first(instancer)
                while instance and (not found_instancer):
                    if instance_info.item(instance) == selected_item:
                        # found it!
                        found_instancer = instancer
                        break
                    instance = instancer_funcs.next(instancer, instance)
            obj = item_info.next(obj)

        if not found_instancer:
            print >> sys.stderr, 'Object "%s" is NOT instanced!' % item_info.name(
                selected_item)
            return lwsdk.AFUNC_OK

        instances = []
        instance = instancer_funcs.first(found_instancer)
        while instance:
            if instance_info.item(instance) == selected_item:
                instances.append(instance)
            instance = instancer_funcs.next(found_instancer, instance)

        # values used for progress
        current_index = 1.0
        target_index = len(instances) * 1.0

        for instance in instances:
            pos = instance_info.pos(instance, 0)
            # Note: InstanceInfo.rotation() returns radians!
            rot = instance_info.rotation(instance, 0)
            scl = instance_info.scale(instance, 0)

            lwsdk.command("SelectItem %s" % selected_item_id)
            lwsdk.command("Clone 1")

            lwsdk.command("Position %s" % str(pos))
            # Note: Rotation expects degrees!
            lwsdk.command("Rotation %s" % str(Vector.to_degrees(rot)))
            lwsdk.command("Scale %s" % str(scl))
            if not autokey_is_on:
                lwsdk.command("CreateKey %f" % current_time)

            lwsdk.command("StatusMsg {%f}Baking instances..." %
                          (current_index / target_index))
            current_index += 1.0

        lwsdk.command("SelectItem %s" % selected_item_id)

        lwsdk.command("StatusMsg Baking complete.")

        return lwsdk.AFUNC_OK