def target_change(self, control, data): if not self._selected_camera: return self._camera_target[self._selected_camera_name] = ( True if control.get_int() else False) if self._target_object: lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(self._selected_camera)) if self._camera_target[self._selected_camera_name]: lwsdk.command("TargetItem %s" % lwsdk.itemid_to_str(self._target_object)) else: lwsdk.command("TargetItem 0") # send some sample data to the ringtest.p plug-in # each time the target is changed. this is just # dummy data strings = ("Falicitations!", "Salutations!", "Greetings!") floats = (6.6666, 7.7777, 8.8888, 9.9999, 0.0000) ring_data = self._comring.encodeData(('s:100#3', 'i', 'd', 'f#5'), (strings, 67832, 34.8765, floats)) if ring_data: self._comring.ringMessage("ringtest_channel", 2, ring_data) self._comring.releaseData(ring_data)
def effector_change(self, control, data): self._target_object = control.get_addr() if self._target_object: # tell the ringtest.p plug-in it has a new target object ring_data = self._comring.encodeData('k', (self._target_object, )) if ring_data: self._comring.ringMessage("ringtest_channel", 1, ring_data) self._comring.releaseData(ring_data) if len(self._camera_target): for i in self._camera_target.keys(): if self._camera_target[i]: lwsdk.command("SelectItemByName %s" % i) lwsdk.command("TargetItem %s" % lwsdk.itemid_to_str(self._target_object)) lwsdk.command("RefreshNow") else: # tell the ringtest.p plug-in it has no target object ring_data = self._comring.encodeData('k', (0, )) if ring_data: self._comring.ringMessage("ringtest_channel", 1, ring_data) self._comring.releaseData(ring_data)
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
def tool_up(self, event): if (self._handle >= 0) and self._moved: new_bones = deepcopy(self._bones) # Make sure ParentInPlace is OFF pip = ((lwsdk.LWInterfaceInfo().generalFlags & lwsdk.LWGENF_PARENTINPLACE) == lwsdk.LWGENF_PARENTINPLACE) if pip: lwsdk.command("ParentInPlace") for bone in self._bones: new_bones.append(self.split_bone(bone, self._frac)) if pip: lwsdk.command("ParentInPlace") for i in range(len(new_bones)): if i == 0: lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(new_bones[i].id)) else: lwsdk.command("AddToSelection %s" % lwsdk.itemid_to_str(new_bones[i].id)) self._handle = -1
def radius_change(self, control, data): if not self._selected_camera: return self._camera_radii[self._selected_camera_name] = control.get_float() if self._camera_active[self._selected_camera_name]: # tell the ringtest.p plug-in to alter its radius ring_data = self._comring.encodeData( 'd', (self._camera_radii[self._selected_camera_name] / 100.0, )) if ring_data: ring_code = int(lwsdk.itemid_to_str(self._selected_camera), 16) self._comring.ringMessage("ringtest_channel", ring_code, ring_data) self._comring.releaseData(ring_data) lwsdk.command("RefreshNow")
def camera_change(self, control, data): self._selected_camera = control.get_addr() if self._selected_camera: self._selected_camera_name = self._item_info.name( self._selected_camera) lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(self._selected_camera)) self._controls[2].unghost() if (not len(self._camera_active)) or (self._selected_camera_name not in self._camera_active): self._controls[2].set_int(0) self._controls[3].ghost() self._controls[4].ghost() else: if (not len(self._camera_radii)) or ( self._selected_camera_name not in self._camera_radii): self._camera_radii[self._selected_camera_name] = 100.0 if (not len(self._camera_target)) or ( self._selected_camera_name not in self._camera_target): self._camera_target[self._selected_camera_name] = False self._controls[2].set_int(1 if self._camera_active[ self._selected_camera_name] else 0) if self._camera_active[self._selected_camera_name]: self._controls[3].unghost() self._controls[4].unghost() if len(self._camera_target) and (self._selected_camera_name in self._camera_target): self._controls[3].set_int(1 if self._camera_target[ self._selected_camera_name] else 0) if len(self._camera_radii) and (self._selected_camera_name in self._camera_radii): self._controls[4].set_float( self._camera_radii[self._selected_camera_name]) else: self._controls[2].ghost() self._controls[3].ghost() self._controls[4].ghost()
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
def split_bone(self, bone, split): cur_time = lwsdk.LWTimeInfo().time; pos = self._item_info.param(bone.id, lwsdk.LWIP_W_POSITION, cur_time) rest_pos = Vector(self._bone_info.restParam(bone.id, lwsdk.LWIP_POSITION)) rest_rot = Vector(self._bone_info.restParam(bone.id, lwsdk.LWIP_ROTATION)) rest_rot *= math.pi / 180.0 rest_len = bone.restlength # Clone the existing bone # Make the new bone the parent, existing bone the child lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(bone.id)) lwsdk.command("Clone 1") selected_items = lwsdk.LWInterfaceInfo().selected_items() new_bone = PyBone(selected_items[0], self._item_info.parent(selected_items[0]), self._bone_info.type(selected_items[0]), self._bone_info.restLength(selected_items[0])) # Make new bone child of original parent lwsdk.command("ParentItem %s" % lwsdk.itemid_to_str(bone.parent)) # Motion options corrections: # - Don't copy over the goal lwsdk.command("GoalItem 0") if new_bone.type == lwsdk.LWBONETYPE_ZAXIS: temp_vector = Vector(0,0,1) split_pos = temp_vector * (rest_len * split) # Make new bone shorter to the split lwsdk.command("BoneRestLength %g" % (rest_len * split)) # Make corrections to existing bone # - Parent it to the new bone # - Place at the split position # - Shorten it to the remainder of original length # - Reset scale and rotation (as those are now done by new bone) lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(bone.id)) lwsdk.command("ParentItem %s" % lwsdk.itemid_to_str(new_bone.id)) # Set positions self.set_vec_chan_to_value(bone.id, 0, split_pos) lwsdk.command("PivotPosition 0 0 0") lwsdk.command("BoneRestPosition %s" % str(split_pos)) lwsdk.command("BoneRestLength %g" % (rest_len * (1-split))) # Set rotations self.set_vec_chan_to_value(bone.id, 3, Vector(0,0,0)) lwsdk.command("PivotRotation 0 0 0") lwsdk.command("BoneRestRotation 0 0 0") # Set scales self.set_vec_chan_to_value(bone.id, 6, Vector(1,1,1)); lwsdk.command("DirtyMotion") lwsdk.command("UpdateMotion") # Move children to take into account shortened bone child_id = self._item_info.firstChild(bone.id) while child_id: lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(child_id)) self.add_value_to_vec_chan(child_id, 0, -split_pos); if self._item_info.type(child_id) == lwsdk.LWI_BONE: child_pos = Vector(self._bone_info.restParam(child_id, lwsdk.LWIP_POSITION)) child_pos -= split_pos; lwsdk.command("BoneRestPosition %s" % str(child_pos)) lwsdk.command("DirtyMotion") lwsdk.command("UpdateMotion") child_id = self._item_info.nextChild(bone.id, child_id) else: axispos, axis = self.get_world_bone_axis(bone) # Move new bone to split position new_rest_pos = rest_pos * split lwsdk.command("BoneRestPosition %s" % str(new_rest_pos)) # newPos = split * pos self.mul_value_to_vec_chan(new_bone.id, 0, split) lwsdk.command("BoneRestRotation 0 0 0") self.set_vec_chan_to_value(new_bone.id, 3, Vector(0,0,0)) self.set_vec_chan_to_value(new_bone.id, 6, Vector(1,1,1)) lwsdk.command("DirtyMotion") lwsdk.command("UpdateMotion") # Make corrections to existing bone # - Parent it to the new bone lwsdk.command("SelectItem %s" % lwsdk.itemid_to_str(bone.id)) lwsdk.command("ParentItem %s" % lwsdk.itemid_to_str(new_bone.id)) # - Correct place to account for new bone parent # New bone parent has no rotation and unit scale, # so only difference is a position offset new_rest_pos = rest_pos * (1.0 - split) lwsdk.command("BoneRestPosition %s" % str(new_rest_pos)) # newPos = (1.0 - split) * pos self.mul_value_to_vec_chan(bone.id, 0, 1.0 - split) lwsdk.command("DirtyMotion") lwsdk.command("UpdateMotion") return new_bone
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
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
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
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
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