Beispiel #1
0
    def _renderimgurl(self,
                      camposx=None,
                      camposy=None,
                      camposz=None,
                      camortx=None,
                      camorty=None,
                      camortz=None,
                      camortw=None):
        cament = naali.getCamera()
        p = cament.placeable
        orgpos = Vec(0, 0, 0)
        orgort = Quat(1, 0, 0, 0)

        if camposx is not None:
            pos = Vec(*(float(v) for v in [camposx, camposy, camposz]))
            p.Position = pos

        if camortx is not None:
            ort = Quat(*(float(v)
                         for v in [camortw, camortx, camorty, camortz]))
            p.Orientation = ort

        baseurl, imgname = save_screenshot()

        p.Position = orgpos
        p.Orientation = orgort
        return baseurl, imgname
Beispiel #2
0
    def getPivotPos(self, ents):
        '''Median position used as pivot point'''
        xs = [e.placeable.Position.x() for e in ents]
        ys = [e.placeable.Position.y() for e in ents]
        zs = [e.placeable.Position.z() for e in ents]

        minpos = Vec(min(xs), min(ys), min(zs))
        maxpos = Vec(max(xs), max(ys), max(zs))
        median = (minpos + maxpos) / 2

        return median
Beispiel #3
0
    def getPivotPos(self, ents):
        xs = [e.placeable.Position.x() for e in ents]
        ys = [e.placeable.Position.y() for e in ents]
        zs = [e.placeable.Position.z() for e in ents]

        minpos = Vec(min(xs), min(ys), min(zs))
        maxpos = Vec(max(xs), max(ys), max(zs))
        #median = (minpos + maxpos) / 2
        #there is some type prob with pythonqt and operator overloads, so this workaround is needed:
        median = minpos.__add__(maxpos).__div__(2)
        #print "Min:", minpos
        #print "Max:", minpos
        #print "Median:", median

        return median
Beispiel #4
0
    def hideManipulator(self):
        #r.logInfo("hiding manipulator")
        if self.usesManipulator:
            try:  #XXX! without this try-except, if something is selected, the viewer will crash on exit
                #print "Hiding arrows!"
                if self.manipulator is not None:
                    self.manipulator.placeable.Scale = Vec(0.0, 0.0,
                                                           0.0)  #ugly hack
                    self.manipulator.placeable.Position = Vec(
                        0.0, 0.0, 0.0)  #another ugly hack

                self.grabbed_axis = None
                self.grabbed = False

            except RuntimeError, e:
                r.logDebug("hideManipulator failed")
Beispiel #5
0
    def changescale(self, i, v):
        ent = self.active
        if ent is not None:
            qscale = ent.placeable.Scale
            oldscale = list((qscale.x(), qscale.y(), qscale.z()))
            scale = list((qscale.x(), qscale.y(), qscale.z()))

            if not self.float_equal(scale[i], v):
                scale[i] = v
                if self.window.mainTab.scale_lock.checked:
                    #XXX BUG does wrong thing - the idea was to maintain aspect ratio
                    diff = scale[i] - oldscale[i]
                    for index in range(len(scale)):
                        #print index, scale[index], index == i
                        if index != i:
                            scale[index] += diff

                ent.placeable.Scale = Vec(scale[0], scale[1], scale[2])

                if not self.dragging:
                    r.networkUpdate(ent.id)

                #self.window.update_scalevals(scale)

                self.modified = True
Beispiel #6
0
    def _manipulate(self, ent, amountx, amounty, lengthx, lengthy):
        if self.grabbed:
            qscale = ent.placeable.Scale
            scale = list((qscale.x(), qscale.y(), qscale.z()))
            rightvec = Vector3(r.getCameraRight())
            upvec = Vector3(r.getCameraUp())

            if self.grabbed_axis == self.AXIS_BLUE:
                mov = lengthy
                scale[self.grabbed_axis] -= mov
            else:
                mov = lengthx
                div = abs(rightvec[self.grabbed_axis])
                if div == 0:
                    div = 0.01  #not the best of ideas but...
                mov *= rightvec[self.grabbed_axis] / div
                scale[self.grabbed_axis] += mov

            newscale = Vec(scale[0], scale[1], scale[2])
            ent.placeable.Scale = newscale
            self.controller.updateSelectionBox(ent)
            qprim = ent.prim
            if qprim is not None:
                children = qprim.GetChildren()
                for child_id in children:
                    child = r.getEntity(int(child_id))
                    child.placeable.Scale = newscale
Beispiel #7
0
 def __init__(self, entity=None, comp=None, changetype=None):
     circuits.BaseComponent.__init__(self)
     self.entity = entity
     self.comp = comp
     if self.comp is not None: #normal run, check for nonEC run now
         # Todo: OnChanged() is deprecated
         comp.connect("OnChanged()", self.onChanged)
     self.rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 1)
Beispiel #8
0
 def _manipulate(self, ent, amountx, amounty, lengthx, lengthy):
     rightvec = Vector3(r.getCameraRight())
     upvec = Vector3(r.getCameraUp())
     changevec = (amountx * rightvec) - (amounty * upvec)
     qpos = ent.placeable.Position
     entpos = Vector3(qpos.x(), qpos.y(), qpos.z())
     newpos = entpos + changevec
     newpos = Vec(newpos.x, newpos.y, newpos.z)
     ent.placeable.Position = newpos
     ent.network.Position = newpos
Beispiel #9
0
    def _manipulate(self, ent, amountx, amounty, changevec):
        if self.grabbed and self.grabbed_axis is not None:
            local = self.controller.useLocalTransform
            mov = changevec.length() * 30
            ort = ent.placeable.Orientation

            if amountx < 0 and amounty < 0:
                dir = -1
            elif amountx < 0 and amounty >= 0:
                dir = 1
                if not local and self.grabbed_axis == self.AXIS_BLUE:
                    dir *= -1
            elif amountx >= 0 and amounty < 0:
                dir = -1
            elif amountx >= 0 and amounty >= 0:
                dir = 1

            mov *= dir

            if local:
                if self.grabbed_axis == self.AXIS_RED:
                    axis = Vec(1, 0, 0)
                elif self.grabbed_axis == self.AXIS_GREEN:
                    axis = Vec(0, 1, 0)
                elif self.grabbed_axis == self.AXIS_BLUE:
                    axis = Vec(0, 0, 1)

                ort = ort * Quat.fromAxisAndAngle(axis, mov)
            else:
                euler = quat_to_euler(ort)

                if self.grabbed_axis == self.AXIS_RED:  #rotate around x-axis
                    euler[0] -= math.radians(mov)
                elif self.grabbed_axis == self.AXIS_GREEN:  #rotate around y-axis
                    euler[1] += math.radians(mov)
                elif self.grabbed_axis == self.AXIS_BLUE:  #rotate around z-axis
                    euler[2] += math.radians(mov)

                ort = euler_to_quat(euler)

            ent.placeable.Orientation = ort
            ent.network.Orientation = ort
Beispiel #10
0
    def camcontrol(self, rotate=None, move=None):
        cament = naali.getCamera()
        p = cament.placeable
        #print p.Position, p.Orientation

        if rotate is not None:
            ort = p.Orientation
            rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), float(rotate))
            ort *= rot
            p.Orientation = ort

        if move is not None:
            pos = p.Position
            pos += Vec(float(move), 0, 0)
            p.Position = pos

        baseurl, imgname = save_screenshot()
        imgurl = baseurl + imgname

        #return "%s, %s" % (p.Position, p.Orientation)
        return relhtml % imgurl
Beispiel #11
0
    def render(self, camposx=None, camposy=None, camposz=None, camang=None):
#, camortx=None, camorty=None, camortz=None, camortw=None):
        cament = naali.getCamera()
        p = cament.placeable

        if camposx is not None:
            pos = Vec(*(float(v) for v in [camposx, camposy, camposz]))
            p.position = pos

        if camang is not None:
            ort = p.orientation
            start = Quat(0, 0, -0.707, -0.707)
            rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), -float(camang))
            new = start * rot
            p.orientation = new

        #if camortx is not None:
        #    ort = Quat(*(float(v) for v in [camortw, camortx, camorty, camortz]))
        #    p.orientation = ort

        #return str(p.position), str(p.orientation) #self.render1()
        baseurl, imgname = save_screenshot()
        imgurl = baseurl + imgname

        pos = p.position
        ort = p.orientation
        #vec, ang = toAngleAxis(p.orientation)
        #print vec, ang
        euler = mu.quat_to_euler(ort)
        ang = euler[0]
        if ang < 0:
            ang = 360 + ang

        return abshtml % (imgurl,
                          ang,
                          pos.x(), pos.y(), pos.z()
                          #ort.scalar(), ort.x(), ort.y(), ort.z(),
                          )
Beispiel #12
0
    def setManipulatorScale(self, ents):
        if ents is None or len(ents) == 0:
            return

        campos = naali.getCamera().placeable.Position
        ent = ents[-1]
        entpos = ent.placeable.Position
        length = (campos - entpos).length()

        v = self.MANIPULATORSCALE
        factor = length * .1
        newv = Vec(v) * factor
        try:
            self.manipulator.placeable.Scale = newv
        except AttributeError:
            pass
Beispiel #13
0
class MoveManipulator(Manipulator):
    NAME = "MoveManipulator"
    MANIPULATOR_MESH_NAME = "axis1.mesh"

    MANIPULATORSCALE = Vec(0.15, 0.15, 0.15)
    MANIPULATORORIENTATION = Quat(1, 1, 0, 0)

    BLUEARROW = [1, 2]
    REDARROW = [5, 6]
    GREENARROW = [3, 4]

    AXIS_RED = 1
    AXIS_GREEN = 0
    AXIS_BLUE = 2

    MATERIALNAMES = {
        0: "axis_black",  #shodows?
        1: "axis_blue",
        2: None,  #"axis_blue", 
        3: "axis_green",
        4: None,  #"axis_green",
        5: "axis_red",
        6: None,  #"axis_red"
    }

    def _manipulate(self, ent, amountx, amounty, lengthx, lengthy):
        if self.grabbed:
            rightvec = Vector3(r.getCameraRight())
            upvec = Vector3(r.getCameraUp())
            qpos = ent.placeable.Position
            if self.grabbed_axis == self.AXIS_BLUE:
                mov = lengthy
                qpos.setZ(qpos.z() - mov)
            else:
                mov = lengthx
                div = abs(rightvec[self.grabbed_axis])
                if div == 0:
                    div = 0.01  #not the best of ideas but...
                mov *= rightvec[self.grabbed_axis] / div
                if self.grabbed_axis == self.AXIS_GREEN:
                    qpos.setX(qpos.x() + mov)
                else:
                    qpos.setY(qpos.y() + mov)

            ent.placeable.Position = qpos
            ent.network.Position = qpos
Beispiel #14
0
    def changepos(self, i, v):
        #XXX NOTE / API TODO: exceptions in qt slots (like this) are now eaten silently
        #.. apparently they get shown upon viewer exit. must add some qt exc thing somewhere
        #print "pos index %i changed to: %f" % (i, v)
        ent = self.active

        if ent is not None:
            qpos = ent.placeable.Position
            pos = list(
                (qpos.x(), qpos.y(), qpos.z())
            )  #should probably wrap Vector3, see test_move.py for refactoring notes.

            if not self.float_equal(pos[i], v):
                pos[i] = v
                #converted to list to have it mutable
                newpos = Vec(pos[0], pos[1], pos[2])
                ent.placeable.Position = newpos
                ent.network.Position = newpos
                self.manipulator.moveTo(self.sels)

                self.modified = True
                if not self.dragging:
                    r.networkUpdate(ent.id)
Beispiel #15
0
class Manipulator:
    NAME = "Manipulator"
    MANIPULATOR_MESH_NAME = "axes.mesh"
    USES_MANIPULATOR = True
    CURSOR_HOVER_SHAPE = Qt.OpenHandCursor
    CURSOR_HOLD_SHAPE = Qt.ClosedHandCursor

    MANIPULATORORIENTATION = Quat(1, 0, 0, 0)
    MANIPULATORSCALE = Vec(1, 1, 1)

    MATERIALNAMES = None

    AXIS_RED = 0
    AXIS_GREEN = 1
    AXIS_BLUE = 2

    # some handy shortcut rotations for quats
    ninty_around_x = Quat(math.sqrt(0.5), math.sqrt(0.5), 0, 0)
    ninty_around_y = Quat(math.sqrt(0.5), 0, math.sqrt(0.5), 0)
    ninty_around_z = Quat(math.sqrt(0.5), 0, 0, math.sqrt(0.5))

    def __init__(self, creator):
        self.controller = creator
        self.manipulator = None
        self.grabbed_axis = None
        self.grabbed = False
        self.usesManipulator = self.USES_MANIPULATOR
        self.manipulator = None
        self.highlightedSubMesh = None
        self.axisSubmesh = None

    def compareIds(self, id):
        if self.usesManipulator:
            if self.manipulator.id == id:
                return True
        return False

    def moveTo(self, ents):
        if self.manipulator:
            pos = self.getPivotPos(ents)
            #print "Showing at: ", pos
            self.manipulator.placeable.Position = pos

    def getManipulatorPosition(self):
        if self.manipulator:
            return self.manipulator.placeable.Position
        return None

    def createManipulator(self):
        if self.manipulator is None and self.usesManipulator:
            ent = r.createEntity(self.MANIPULATOR_MESH_NAME, 606847240)
            return ent

    def stopManipulating(self):
        self.grabbed_axis = None
        self.grabbed = False
        remove_custom_cursor(self.CURSOR_HOLD_SHAPE)

    def initVisuals(self):
        #r.logInfo("initVisuals in manipulator " + str(self.NAME))
        if self.manipulator is None:
            self.manipulator = self.createManipulator()
            self.hideManipulator()

    def showManipulator(self, ents):
        #print "Showing arrows!"
        if self.usesManipulator and len(ents) > 0:
            self.moveTo(ents)
            self.manipulator.placeable.Scale = self.MANIPULATORSCALE
            if self.controller.useLocalTransform:
                # first according object, then manipulator orientation - otherwise they go wrong order
                self.manipulator.placeable.Orientation = ents[
                    0].placeable.Orientation * self.MANIPULATORORIENTATION
            else:
                self.manipulator.placeable.Orientation = self.MANIPULATORORIENTATION

        self.setManipulatorScale(ents)

    def getPivotPos(self, ents):
        '''Median position used as pivot point'''
        xs = [e.placeable.Position.x() for e in ents]
        ys = [e.placeable.Position.y() for e in ents]
        zs = [e.placeable.Position.z() for e in ents]

        minpos = Vec(min(xs), min(ys), min(zs))
        maxpos = Vec(max(xs), max(ys), max(zs))
        median = (minpos + maxpos) / 2

        return median

    def hideManipulator(self):
        #r.logInfo("hiding manipulator")
        if self.usesManipulator:
            try:  #XXX! without this try-except, if something is selected, the viewer will crash on exit
                #print "Hiding arrows!"
                if self.manipulator is not None:
                    self.manipulator.placeable.Scale = Vec(0.0, 0.0,
                                                           0.0)  #ugly hack
                    self.manipulator.placeable.Position = Vec(
                        0.0, 0.0, 0.0)  #another ugly hack

                self.grabbed_axis = None
                self.grabbed = False
                remove_custom_cursors()

            except RuntimeError, e:
                r.logDebug("hideManipulator failed")
Beispiel #16
0
from PythonQt import QtGui
from PythonQt.QtGui import QVector3D as Vec
from PythonQt.QtGui import QGroupBox, QVBoxLayout, QPushButton

import rexviewer as r

#componenthandlers don't necessarily need to be naali modules,
#but this one needs to listen to update events to do mouse hover tricks
import circuits

#should be in the EC data
OPENPOS = Vec(101.862, 82.6978, 24.9221)
CLOSEPOS = Vec(99.65, 82.6978, 24.9221)
"""for changing the cursor on hover"""
import PythonQt
qapp = PythonQt.Qt.QApplication.instance()
import PythonQt.QtGui as gui
cursor = gui.QCursor()


def setcursor(ctype):
    cursor.setShape(ctype)
    current = qapp.overrideCursor()
    if current != None:
        if current.shape() != ctype:
            qapp.setOverrideCursor(cursor)
    else:
        qapp.setOverrideCursor(cursor)


COMPNAME = "door"  #the DC name identifier string that this handler looks for
Beispiel #17
0
def get_right(entity):
    v = Vec(1.0, 0.0, 0.0)
    return quat_mult_vec(entity.placeable.Orientation, v)
Beispiel #18
0
    
if 0: #camera entity - it is an entity nowadays, and there is EC cam even
    try:
        cament = naali.getCamera()
        print "CAM:", cament.id
    except ValueError:
        print "no CAM"
    else:
        p = cament.placeable
        print p.position, p.orientation

        import PythonQt.QtGui
        from PythonQt.QtGui import QQuaternion as Quat
        from PythonQt.QtGui import QVector3D as Vec
        ort = p.orientation
        rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 10)
        #ort *= Quat(0, -.707, 0, .707)
        ort *= rot
        p.orientation = ort
        
        #ec cam stuff:
        print "FOV:", cament.camera.GetVerticalFov()
        
        

if 0: #calcing the camera angle around up axis for web ui
    import PythonQt.QtGui
    from PythonQt.QtGui import QQuaternion
    from PythonQt.QtGui import QVector3D
    import mathutils as mu
Beispiel #19
0
class Manipulator:
    NAME = "Manipulator"
    MANIPULATOR_MESH_NAME = "axes.mesh"
    USES_MANIPULATOR = True

    MANIPULATORORIENTATION = Quat(1, 0, 0, 0)
    MANIPULATORSCALE = Vec(0.2, 0.2, 0.2)

    MATERIALNAMES = None

    AXIS_RED = 0
    AXIS_GREEN = 1
    AXIS_BLUE = 2

    def __init__(self, creator):
        self.controller = creator
        self.manipulator = None
        self.grabbed_axis = None
        self.grabbed = False
        self.usesManipulator = self.USES_MANIPULATOR
        self.manipulator = None
        self.highlightedSubMesh = None

    def compareIds(self, id):
        if self.usesManipulator:
            if self.manipulator.id == id:
                return True
        return False

    def moveTo(self, ents):
        if self.manipulator:
            pos = self.getPivotPos(ents)
            #print "Showing at: ", pos
            self.manipulator.placeable.Position = pos

    def getManipulatorPosition(self):
        if self.manipulator:
            return self.manipulator.placeable.Position
        return None

    def createManipulator(self):
        if self.manipulator is None and self.usesManipulator:
            ent = r.createEntity(self.MANIPULATOR_MESH_NAME, 606847240)
            return ent

    def stopManipulating(self):
        self.grabbed_axis = None
        self.grabbed = False

    def initVisuals(self):
        #r.logInfo("initVisuals in manipulator " + str(self.NAME))
        if self.manipulator is None:
            self.manipulator = self.createManipulator()
            self.hideManipulator()

    def showManipulator(self, ents):
        #print "Showing arrows!"
        if self.usesManipulator:
            self.moveTo(ents)
            self.manipulator.placeable.Scale = self.MANIPULATORSCALE  #0.2, 0.2, 0.2
            self.manipulator.placeable.Orientation = self.MANIPULATORORIENTATION

    def getPivotPos(self, ents):
        xs = [e.placeable.Position.x() for e in ents]
        ys = [e.placeable.Position.y() for e in ents]
        zs = [e.placeable.Position.z() for e in ents]

        minpos = Vec(min(xs), min(ys), min(zs))
        maxpos = Vec(max(xs), max(ys), max(zs))
        #median = (minpos + maxpos) / 2
        #there is some type prob with pythonqt and operator overloads, so this workaround is needed:
        median = minpos.__add__(maxpos).__div__(2)
        #print "Min:", minpos
        #print "Max:", minpos
        #print "Median:", median

        return median

    def hideManipulator(self):
        #r.logInfo("hiding manipulator")
        if self.usesManipulator:
            try:  #XXX! without this try-except, if something is selected, the viewer will crash on exit
                #print "Hiding arrows!"
                if self.manipulator is not None:
                    self.manipulator.placeable.Scale = Vec(0.0, 0.0,
                                                           0.0)  #ugly hack
                    self.manipulator.placeable.Position = Vec(
                        0.0, 0.0, 0.0)  #another ugly hack

                self.grabbed_axis = None
                self.grabbed = False

            except RuntimeError, e:
                r.logDebug("hideManipulator failed")
Beispiel #20
0
 def onChanged(self):
     y = self.comp.GetAttribute('y')
     self.rot = Quat.fromAxisAndAngle(Vec(0, y, 0), 1)
Beispiel #21
0
if 0:  #camera entity - it is an entity nowadays, and there is EC cam even
    try:
        cament = naali.getCamera()
        print "CAM:", cament.id
    except ValueError:
        print "no CAM"
    else:
        p = cament.placeable
        print p.Position, p.Orientation

        import PythonQt.QtGui
        from PythonQt.QtGui import QQuaternion as Quat
        from PythonQt.QtGui import QVector3D as Vec
        ort = p.Orientation
        rot = Quat.fromAxisAndAngle(Vec(0, 1, 0), 10)
        #ort *= Quat(0, -.707, 0, .707)
        ort *= rot
        p.Orientation = ort

        #ec cam stuff:
        print "FOV:", cament.camera.GetVerticalFov()

if 0:  #calcing the camera angle around up axis for web ui
    import PythonQt.QtGui
    from PythonQt.QtGui import QQuaternion as Quat
    from PythonQt.QtGui import QVector3D as Vec

    from objectedit.conversions import quat_to_euler  #, euler_to_quat

    def toAngleAxis(quat):