def real_world_length(self): """ nCloth simulates in meters; so, convert and return the space scale in the scene's working units. """ self._real_world_length = convertUnit(float( \ self.nucleus.attr('spaceScale').get()), fromUnit='m') return self._real_world_length
def real_world_length(self, value=None): """ Sets the real world length according to the scene's working units and also sets the nCloth nucleus space scale to compensate. """ if value: # Run a conversion formula to adjust for any variance between the # size of the object in the real world vs. the size of the object in Maya. max_length, bbs = 0, self.shared_transforms \ and [st.getBoundingBox() for st in self.shared_transforms] \ or [self.transform.getBoundingBox()] for bb in bbs: max_length = max(max_length, bb.width(), bb.height(), bb.depth()) self._real_world_length = float(convertUnit(value)) ss = self._real_world_length / max_length ss = float(convertUnit(ss, toUnit='m')[:-1]) else: # No value was passed. Assume the units are accurate to the scene's # working units. self._real_world_length = float(convertUnit(1, toUnit='m')[:-1]) ss = self._real_world_length self.nucleus.attr('spaceScale').set(ss)
def create_scaled_ncloth_prompt(msg=None): lines = [] if msg: lines.append(msg) rwl = promptBox('Create Scaled nCloth', os.linesep.join(lines +[ \ 'What is the real-world length of the longest object in', 'your selection (e.g. 7ft, 2in, etc. or scene)?']), 'Create Scaled nCloth', 'Cancel') if rwl: if rwl.lower() == 'scene': return create_scaled_ncloth_auto() try: rwl = float(convertUnit(rwl)) except RuntimeError: return create_scaled_ncloth_prompt( \ msg='Conversion error: invalid units. Please try again.') return create_scaled_ncloth_auto(rwl=rwl)
def convert_points(points): for i, p in enumerate(points): for j, p2 in enumerate(p): points[i][j] = float(convertUnit(p2, fromUnit='cm')) return points