Example #1
0
    def ArrangeSelection(self, x, y, z):
        slimItems = self.GetSelObjects()
        if len(slimItems) < 2:
            return
        minV = trinity.TriVector(slimItems[0].dunX, slimItems[0].dunY,
                                 slimItems[0].dunZ)
        maxV = minV.CopyTo()
        commandArgs = []
        centreAxis = trinity.TriVector()
        for slimItem in slimItems:
            centreAxis.x = centreAxis.x + slimItem.dunX
            centreAxis.y = centreAxis.y + slimItem.dunY
            centreAxis.z = centreAxis.z + slimItem.dunZ

        centreAxis.Scale(1.0 / len(slimItems))
        stepCount = float(len(slimItems))
        totalOffset = trinity.TriVector(x * stepCount, y * stepCount,
                                        z * stepCount)
        totalOffset.Scale(-0.5)
        counter = 0
        for slimItem in slimItems:
            offset = trinity.TriVector(x, y, z)
            offset.Scale(counter)
            pos = centreAxis + totalOffset + offset
            counter += 1
            dungeonHelper.SetObjectPosition(slimItem.dunObjectID, pos.x, pos.y,
                                            pos.z)
Example #2
0
    def RotateSelected(self, yaw, pitch, roll):
        slimItems = self.GetSelObjects()
        if len(slimItems) == 0:
            return
        nq = trinity.TriQuaternion()
        nq.SetYawPitchRoll(yaw / 180.0 * pi, pitch / 180.0 * pi,
                           roll / 180.0 * pi)
        posCtr = trinity.TriVector()
        for slimItem in slimItems:
            posCtr += trinity.TriVector(slimItem.dunX, slimItem.dunY,
                                        slimItem.dunZ)

        posCtr.Scale(1.0 / len(slimItems))
        for slimItem in slimItems:
            q = trinity.TriQuaternion()
            rot = getattr(slimItem, 'dunRotation', None)
            if rot is not None:
                yaw, pitch, roll = rot
                q.SetYawPitchRoll(yaw / 180.0 * pi, pitch / 180.0 * pi,
                                  roll / 180.0 * pi)
            q.Multiply(nq)
            y, p, r = q.GetYawPitchRoll()
            y = y / pi * 180.0
            p = p / pi * 180.0
            r = r / pi * 180.0
            translation = trinity.TriVector(slimItem.dunX, slimItem.dunY,
                                            slimItem.dunZ)
            translation -= posCtr
            translation.TransformQuaternion(nq)
            translation += posCtr
            dungeonHelper.SetObjectPosition(slimItem.dunObjectID,
                                            translation.x, translation.y,
                                            translation.z)
            dungeonHelper.SetObjectRotation(slimItem.dunObjectID, y, p, r)
Example #3
0
 def JitterSelection(self, x, y, z):
     slimItems = self.GetSelObjects()
     if len(slimItems) == 0:
         return
     commandArgs = []
     for slimItem in slimItems:
         ox = slimItem.dunX + x * random.random() * 2 - x
         oy = slimItem.dunY + y * random.random() * 2 - y
         oz = slimItem.dunZ + z * random.random() * 2 - z
         dungeonHelper.SetObjectPosition(slimItem.dunObjectID, ox, oy, oz)
Example #4
0
    def RotateSelected(self, yaw, pitch, roll):
        slimItems = self.GetSelObjects()
        if len(slimItems) == 0:
            return
        yawRad = yaw / 180.0 * math.pi
        pitchRad = pitch / 180.0 * math.pi
        rollRad = roll / 180.0 * math.pi
        rotationToAdd = geo2.QuaternionRotationSetYawPitchRoll(
            yawRad, pitchRad, rollRad)
        posCtr = geo2.VectorD(0, 0, 0)
        for slimItem in slimItems:
            posCtr += geo2.VectorD(slimItem.dunX, slimItem.dunY, slimItem.dunZ)

        geo2.Scale(posCtr, 1.0 / len(slimItems))
        for slimItem in slimItems:
            rot = getattr(slimItem, 'dunRotation', None)
            slimItemRotation = geo2.QuaternionIdentity()
            if rot is not None:
                yaw, pitch, roll = rot
                slimItemRotation = geo2.QuaternionRotationSetYawPitchRoll(
                    yaw / 180.0 * math.pi, pitch / 180.0 * math.pi,
                    roll / 180.0 * math.pi)
            y, p, r = geo2.QuaternionRotationGetYawPitchRoll(slimItemRotation)
            slimItemRotation = geo2.QuaternionMultiply(rotationToAdd,
                                                       slimItemRotation)
            y, p, r = geo2.QuaternionRotationGetYawPitchRoll(slimItemRotation)
            y = y / math.pi * 180.0
            p = p / math.pi * 180.0
            r = r / math.pi * 180.0
            translation = geo2.VectorD(slimItem.dunX, slimItem.dunY,
                                       slimItem.dunZ)
            translation -= posCtr
            geo2.QuaternionTransformVector(rotationToAdd, translation)
            translation += posCtr
            dungeonHelper.SetObjectPosition(slimItem.dunObjectID,
                                            translation.x, translation.y,
                                            translation.z)
            dungeonHelper.SetObjectRotation(slimItem.dunObjectID, y, p, r)