コード例 #1
0
    def connect(self):
        if not self.paused:
            print "Already connected"
            return

        if not self.initialized:
            print "Init Leap"
            self.init_leap()

        print "Starting Leap"

        # Check if there are actually hands in the scene, and add hands if not
        # Only checks for hand root, not each bone
        if vrScenegraph.findNode("Hands").isValid():
            print "Hands found"
        else:
            print "Import hands structure"
            if vr_cam_name:
                cam_node = vrScenegraph.findNode(vr_cam_name)
            else:
                cam_node = vrCamera.getActiveCameraNode()
            vrFileIO.load(filenames=[os.path.join(plugin_path(), "Hands.osb")],
                          parent=cam_node,
                          newFile=False,
                          showImportOptions=False)

        self.build_hand_structure()
        self.paused = False
        self.leap_controller.set_paused(self.paused)
コード例 #2
0
 def __updateReferences(self):
     '''
     Update all references needed for streaming
     '''
     self.streamingTransform = vrScenegraph.findNode(
         'camera_backplate_node')
     self.streamingScreen = vrScenegraph.findNode('camera_backplate_sceen')
     self.streamingBackground = vrScenegraph.findNode(
         'camera_backplate_background')
     self.environments = vrScenegraph.findNode('Environments')
コード例 #3
0
 def build_bone_visual(self, start, end, hand):
     ''' Create visual bones '''
     node = vrScenegraph.findNode("bonevis_" + end)
     bone_ele = {
         'bone': node,
         'start': vrScenegraph.findNode(start),
         'end': vrScenegraph.findNode(end)
     }
     vrConstraints.createAimConstraint([end], ["leap_up"], "bonevis_" + end)
     return bone_ele
コード例 #4
0
    def importCamera(self):
        check = vrScenegraph.findNode("ADSK_Turntable_Offset")
        checkname = check.getName()
        print checkname
        node = vrScenegraph.getSelectedNode()
        center = vrNodeUtils.getBoundingBoxCenter(node, 1)

        if checkname == "ADSK_Turntable_Offset":
            print("Camera already exists in your Scene")
        else:
            print("Camera is loaded into your Sceen")
            vrFileIO.load("C:/temp/SG_ADSK_Turntable_Offset.osb")

        vrScenegraph.findNode("ADSK_Turntable_Offset").setTranslation(
            center.x(), center.y(), center.z())
        print "Camera was moved to", center
        vrCamera.jumpViewPoint("ICV")
コード例 #5
0
 def renderTurntable(self):
     rotateZ = vrScenegraph.findNode("Rotate_Z")
     amount = 10
     for i in range(0, amount):
         if i != 0:
             imageNum = 360 / amount
         else:
             imageNum = 0
         rotateVal = imageNum * i
         rotateZ.setRotation(0, 0, rotateVal)
         filename = "c:/temp/turntable/turntable" + str(i) + ".png"
         width = 720
         height = 432
         vrMovieExport.createSnapshotFastInit(width, height, 0)
         vrMovieExport.createSnapshotFast(filename)
コード例 #6
0
    def destroy(self):
        '''
        Remove all geometry and materials that were added to the scene
        '''
        print('Destroy streaming control...', self)

        geometry = vrScenegraph.findNode('camera_backplate_node')
        mat = vrMaterialPtr.findMaterial('camera_backplate_material')

        if geometry.isValid():
            geometry.sub()

        if mat.isValid():
            mat.sub(True)

        if self.videoGrab != None:
            del self.videoGrab
コード例 #7
0
    def __setup(self):
        # Remove old nodes and material
        self.destroy()

        # inject streaming geometry into the scene
        camera = vrScenegraph.findNode('Perspective')
        self.streamingTransform = vrScenegraph.createNode(
            'Transform', 'camera_backplate_node', camera)
        self.streamingTransform.setLocalTranslation(0, 0, -self.distance)

        self.streamingScreen = vrNodeUtils.createPlane(
            self.streamingPlaneHeight, self.streamingPlaneHeight, 1, 1, 0, 0,
            0)
        self.streamingScreen.setName('camera_backplate_sceen')

        self.streamingBackground = vrNodeUtils.createPlane(
            self.streamingPlaneHeight, self.streamingPlaneHeight, 1, 1, 0, 0,
            0)
        self.streamingBackground.setName('camera_backplate_background')
        self.streamingBackground.setTranslation(0, 0, -self.distance * 0.05)

        self.streamingTransform.addChild(self.streamingScreen)
        self.streamingTransform.addChild(self.streamingBackground)

        self.streamingMaterial = vrMaterialPtr.findMaterial(
            'camera_backplate_material')
        if self.streamingMaterial.isValid():
            vrMaterialEditor.deleteMaterials([self.streamingMaterial])

        self.videoGrab = vrVideoGrab(self.streamingScreen,
                                     self.streamingSource,
                                     self.streamingSourceWidth,
                                     self.streamingSourceHeight)
        self.videoGrab.setActive(True)

        vrMaterialPtr.findMaterial('videograb').setName(
            'camera_backplate_material')
        self.streamingMaterial = vrMaterialPtr.findMaterial(
            'camera_backplate_material')
        self.streamingMaterial.fields().setVec3f('diffuseColor', 0.0, 0.0, 0.0)
        self.streamingMaterial.fields().setVec3f('specularColor', 0.0, 0.0,
                                                 0.0)
        self.streamingMaterialFields = self.streamingMaterial.fields()

        self.__updateReferences()
コード例 #8
0
    def build_hand_structure(self):

        # Build hand structure as a dictionary to match Leaps internal data structure
        self.hand_dict = Vividict()

        self.hands = ["Left", "Right"]
        self.fingers = {
            Finger.TYPE_THUMB: "Thumb",
            Finger.TYPE_INDEX: "Index",
            Finger.TYPE_MIDDLE: "Middle",
            Finger.TYPE_RING: "Ring",
            Finger.TYPE_PINKY: "Pinky"
        }
        self.bones = {
            Bone.TYPE_PROXIMAL: "Proximal",
            Bone.TYPE_INTERMEDIATE: "Intermediate",
            Bone.TYPE_DISTAL: "Distal",
            Bone.TYPE_METACARPAL: "Metacarpal"
        }

        # Visualisation
        self.connections = {
            "Intermediate": "Proximal",
            "Distal": "Intermediate",
            "Proximal": "Metacarpal"
        }
        self.contour_connections = {
            "PinkyBase": "ThumbMetacarpal",
            "ThumbMetacarpal": "IndexMetacarpal",
            "IndexMetacarpal": "MiddleMetacarpal",
            "MiddleMetacarpal": "RingMetacarpal",
            "RingMetacarpal": "PinkyMetacarpal",
            "PinkyMetacarpal": "PinkyBase"
        }

        self.left_hand_root = vrScenegraph.findNode("LeftHand")
        self.right_hand_root = vrScenegraph.findNode("RightHand")

        self.left_hand_palm = vrScenegraph.findNode("LeftHandPalm")
        self.right_hand_palm = vrScenegraph.findNode("RightHandPalm")

        #self.wrist = vrScenegraph.findNode("leap_wrist")

        # Big invisible collider
        self.left_hand_collider = vrScenegraph.findNode("LeftHandCollider")
        vrConstraints.createAimConstraint(["LeftIndexDistal"], ["leap_up"],
                                          "LeftHandCollider")
        self.right_hand_collider = vrScenegraph.findNode("RightHandCollider")
        vrConstraints.createAimConstraint(["RightIndexDistal"], ["leap_up"],
                                          "RightHandCollider")

        for hand in self.hands:
            for finger in self.fingers.values():
                for bone in self.bones.values():
                    name = "{}{}{}".format(hand, finger, bone)
                    node = vrScenegraph.findNode(name)
                    bone_vis_dict = {}
                    if bone in self.connections.keys():
                        bone_vis_dict = self.build_bone_visual(
                            "{}{}{}".format(hand, finger,
                                            self.connections[bone]), name,
                            hand)
                    bone_vis_dict['joint'] = node

                    self.hand_dict[hand][finger][bone] = bone_vis_dict

        # Hand contours
        self.contours = []
        for hand in self.hands:
            # Use pinky metacarpal base as hand contour anchor
            self.hand_dict[hand]['pinky_base'] = vrScenegraph.findNode(
                "{}PinkyBase".format(hand))

            for joint in self.contour_connections.items():
                # create contour
                name = "{}{}{}{}".format(hand, joint[0], hand, joint[1])
                node = vrScenegraph.findNode(name)
                vrConstraints.createAimConstraint([hand + joint[1]],
                                                  ["leap_up"], name)
                self.contours.append({
                    'bone':
                    node,
                    'start':
                    vrScenegraph.findNode(hand + joint[0]),
                    'end':
                    vrScenegraph.findNode(hand + joint[1])
                })