예제 #1
0
    def build_world(self):
        # Scan sidecar file for targets and distractors
        for object_name in space.hgt_object_names:
            if object_name.startswith('TargetEmpty'):
                # Create pushButton for target
                self.build_target(object_name)

        # Exit buttons
        pushButton = PushButton(
            transformNode=space.nodes["Transform_ExitButton"].h3dNode,
            geometry=space.nodes["Mesh_ExitButton"].h3dNode,
            displacement=Vec3f(0, 0, TARGET_PRESS_Z_DISPLACEMENT
                               ),  # push down 5 mm in negative z dir
            onRelease=self.press_done,
            hitForce=1.0,
            pressSound=self.click_sound,
        )

        pushButton = PushButton(
            transformNode=space.nodes["Transform_ExitButton2"].h3dNode,
            geometry=space.nodes["Mesh_ExitButton2"].h3dNode,
            displacement=Vec3f(0, 0, TARGET_PRESS_Z_DISPLACEMENT
                               ),  # push down 5 mm in negative z dir
            onRelease=self.press_done,
            hitForce=1.0,
            pressSound=self.click_sound,
        )
예제 #2
0
    def build_buttons(self):
        self.buttons = []

        for i in range(6):
            d = Doer(self.button_push, i)
            b = PushButton(
                transformNode=space.nodes["Transform_button%d" % i].h3dNode,
                geometry=space.nodes["Mesh_button%d" % i].h3dNode,
                pressSound=self.downSound,
                releaseSound=self.upSound,
                onPress=d.do,
                displacement=Vec3f(0, 0, -0.005),
            )
            b.colorId = i
            self.buttons.append(b)

            material = space.nodes["Material_button%d" % i]

            # Make buttons "springier" haptically
            space.nodes["FrictionalSurface_button%d" % i].stiffness = 1.0
            space.nodes["FrictionalSurface_button%d" % i].damping = 0.1

            self.colors.append(material.diffuseColor)
예제 #3
0
    def build_target(self, name):
        target_id = name[-3:]  # last three characters in name, "000"

        transform = space.nodes["Transform_%s" % name]
        mesh = space.nodes["Mesh_TargetMesh.%s" % target_id]
        appearance = space.nodes["Appearance_Cylinder.%s" % target_id]
        label = space.nodes["Text_TargetLabel.%s" % target_id]

        #material = space.nodes["Material_%s" % name]

        if label.string == ['1']:
            self.total_number_of_targets += 1
            targetType = 'target'
        else:
            self.total_number_of_distractors += 1
            targetType = 'distractor'

        if transform.translation.x > 0.0:
            side = 'right'
        elif transform.translation.x < 0.0:
            side = 'left'
        else:
            side = 'middle'

        original_position = Vec3f(transform.translation.x,
                                  transform.translation.y,
                                  transform.translation.z)

        e = Event()
        e.targetInfo = {
            'type': targetType,  # target or distractor
            'appearance': appearance,
            #'material': material,
            'press_count': 0,
            'side': side,
            'original_position': original_position,
            'target_id': int(target_id),
        }
        if targetType == 'target':
            self.target_infos.append(e.targetInfo)

        pushButton = PushButton(
            transformNode=transform.h3dNode,
            geometry=mesh.h3dNode,
            displacement=Vec3f(0, 0, TARGET_PRESS_Z_DISPLACEMENT),
            event=e,
            onPress=self.press_target,
            hitForce=1.0,
        )
예제 #4
0
    def build_world(self):
        # Invisible answer buttons
        self.answer_pads = []
        for i in range(self.number_of_answers):
            prefix = "%s." % ['a', 'b', 'c', 'd'][i]
            space.nodes["ToggleGroup_AnswerPad%d" % i].graphicsOn = False
            material = space.nodes["Material_Answer%d" % i]
            info = {
                'id':
                i,
                'answer':
                None,
                'answered':
                False,
                'material':
                material,
                'prefix':
                '',  #prefix,
                'feedback_pos':
                space.nodes["Transform_AnswerPad%d" % i].translation +
                Vec3f(0, -0.02, 0.02)
            }
            self.answer_pads.append(info)

            e = Event()
            e.info = info

            pushButton = PushButton(
                transformNode=space.nodes["Transform_AnswerPad%d" % i].h3dNode,
                geometry=space.nodes["Mesh_AnswerPad%d" % i].h3dNode,
                displacement=Vec3f(0, 0, 0),
                event=e,
                onPress=self.press_answer_pad,
            )

        # Chalk tap sounds when touching blackboard
        bl = MFBoolListener(onTrue=self.touch_chalkboard, )
        space.nodes["Mesh_Chalkboard"].h3dNode.isTouched.routeNoEvent(bl)

        self.build_feedback_label()
예제 #5
0
    def build_world(self):
        self.scoreText = space.nodes["Text_SCORE"]
        self.movesText = space.nodes["Text_MOVES"]
        self.movesText.string = [_("MOVES")]
        space.nodes["Text_LevelLabel"].string = [_('LEVEL')]
        space.nodes["Text_Level"].string = [[
            _('Easy'), _('Medium'), _('Hard')
        ][self.level - 1]]

        self.cardTurnSound = Sound(url="sounds/flip.wav",
                                   copies=2,
                                   intensity=0.5)
        self.noTurnSound = Sound(url="sounds/click.wav",
                                 copies=2,
                                 intensity=1.0)
        self.wrongPairSound = Sound(url="sounds/click.wav",
                                    copies=1,
                                    intensity=1.0)
        self.correctPairSound = Sound(url="sounds/ding.wav",
                                      copies=1,
                                      intensity=1.0)
        self.finishedSound = Sound(url="sounds/cheer.wav",
                                   copies=1,
                                   intensity=0.5)

        self.cards = []

        for i in range(MAX_CARDS):
            cardMesh = space.nodes["Mesh_C%d" % (i)]
            cardT = space.nodes["Transform_C%d" % (i)]
            cardAppearance = space.nodes["Appearance_C%d" % (i)]
            toggle = space.nodes["ToggleGroup_C%d" % (i)]

            if i not in self.cardsUsed:
                # Hide unused cards
                toggle.graphicsOn = False
                toggle.hapticsOn = False
            else:
                imageTexture = hgn.ImageTexture(url="textures/cardback.jpg")

                card = Card(backTexture=imageTexture,
                            appearance=cardAppearance,
                            toggle=toggle)
                self.cards.append(card)

                event = Event()
                event.card = card

                button = PushButton(
                    transformNode=cardT.h3dNode,
                    geometry=cardMesh.h3dNode,
                    onPress=self.press_card,
                    displacement=Vec3f(0, 0, -0.005),
                    event=event,
                )

        cardfronts = []
        for fn in os.listdir('cardimages'):
            if fn.endswith('.jpg'):
                cardfronts.append('cardimages/' + fn)

        random.shuffle(cardfronts)
        random.shuffle(self.cards)

        for i in range(len(self.cardsUsed) / 2):
            index = i * 2
            cardfront = hgn.ImageTexture(url=cardfronts.pop())
            c1 = self.cards[index]
            c2 = self.cards[index + 1]

            c1.frontTexture = cardfront
            c2.frontTexture = cardfront

            c1.pairId = i
            c2.pairId = i
예제 #6
0
    def build_world(self):
        # Slot machine buttons
        self.button_infos = {
            'spin_reels': {
                'name': 'SpinButton',
                'title': _('SPIN'),
                'id': 'spin_reels',
                'label': space.nodes["Text_SpinButtonLabel"],
                'material': space.nodes["Material_SpinButton"],
            },
            'bet_one': {
                'name': 'BetButton',
                'title': _('BET'),
                'id': 'bet_one',
                'label': space.nodes["Text_BetButtonLabel"],
                'material': space.nodes["Material_BetButton"],
            },
            'exit': {
                'name': 'ExitButton',
                'title': _('EXIT'),
                'id': 'exit',
                'label': space.nodes["Text_ExitButtonLabel"],
                'material': space.nodes["Material_ExitButton"],
            },
        }

        for i in range(3):
            bid = "hold%d" % i
            self.button_infos[bid] = {
                'name': 'HoldButton.%03d' % i,
                'title': _('HOLD'),
                'id': 'hold0',
                'label': space.nodes["Text_HoldButtonLabel.%03d" % i],
                'material': space.nodes["Material_HoldButton.%03d" % i],
            }

        for bi in self.button_infos.values():
            # Set label
            bi['label'].string = [bi['title']]

            e = Event()
            e.info = bi
            pushButton = PushButton(
                transformNode=space.nodes["Transform_%s" % bi['name']].h3dNode,
                geometry=space.nodes["Mesh_%s" % bi['name']].h3dNode,
                displacement=Vec3f(0, 0.005,
                                   0),  # push down 5 mm in negative z dir
                onPress=self.press_button,
                pressSound=self.button_up_sound,
                releaseSound=self.button_down_sound,
                event=e,
            )

            self.disable_button(bi)

        # Coin
        transform = space.nodes["Transform_TopCoin"]
        grabObject = self.grabber.register(
            transform=transform,
            toggle=space.nodes["ToggleGroup_TopCoin"],
        )
        evt = Event()
        evt.info = {
            'transform': transform,
            'grabObject': grabObject,
            'originalTranslation': transform.translation,
            'originalRotation': transform.rotation,
        }
        bl = MFBoolListener(
            onTrue=self.touch_coin,
            callbackObject=evt,
        )
        space.nodes["Mesh_TopCoin"].h3dNode.isTouched.routeNoEvent(bl)

        # Coin slot
        bl = MFBoolListener(onTrue=self.touch_coin_slot, )
        space.nodes["Mesh_CoinSlot"].h3dNode.isTouched.routeNoEvent(bl)
예제 #7
0
    def build_world(self):
        # Labels
        # FIXME: blender exporter bug requires fixing before the label names can
        # be changed to something more appropriate.
        space.nodes["Text_LengthLabel.001"].string = [_("Listen")]
        space.nodes["Text_LengthLabel.002"].string = [_("Repeat")]

        # Hide all buttons
        for i in range(TOTAL_NUMBER_OF_BUTTONS):
            t = space.nodes["ToggleGroup_Button.%03d" % (i + 1)]
            t.hapticsOn = False
            t.graphicsOn = False

        self.buttons = []
        for id in self.level_button_ids:
            # Make button visible again
            t = space.nodes["ToggleGroup_Button.%03d" % (id)]
            t.hapticsOn = True
            t.graphicsOn = True

            button = {
                "mesh":
                space.nodes["Mesh_Button.%03d" % (id)],
                "transformInfo":
                space.nodes["TransformInfo_Button.%03d" % (id)],
                "transform":
                space.nodes["Transform_Button.%03d" % (id)],
                "material":
                space.nodes["Material_Button.%03d" % (id)],
                "sound":
                Sound(url="sounds/instrument/%s.wav" %
                      self.level_sounds.pop(0),
                      copies=3,
                      intensity=0.5),
            }
            self.buttons.append(button)

            e = Event()
            e.button = button

            pushButton = PushButton(
                transformNode=button["transform"].h3dNode,
                geometry=button["mesh"].h3dNode,
                onPress=self.press_button,
                onRelease=self.release_button,
                displacement=Vec3f(0, 0.01, 0),
                hitForce=1.5,
                event=e,
            )

        # The reward
        self.cup_toggle = space.nodes["ToggleGroup_Cup"]
        self.cup_transform = space.nodes["Transform_Cup"]
        self.cup_dynamic_transform = space.nodes["DynamicTransform_Cup"]
        #self.cup_dynamic_transform.angularMomentum = Vec3f(0, 0, 0.5)
        self.cup_toggle.graphicsOn = False
        self.cup_toggle.hapticsOn = False

        # Build sounds
        self.click_sound = Sound(url="sounds/click.wav",
                                 copies=2,
                                 intensity=0.2)
        self.switch_sound = Sound(url="sounds/switch.wav",
                                  copies=2,
                                  intensity=0.2)
        self.error_sound = Sound(url="sounds/error.wav",
                                 copies=2,
                                 intensity=0.2)
        self.fanfare_sound = Sound(url="sounds/fanfare.wav",
                                   copies=2,
                                   intensity=0.2)
        self.ping_sound = Sound(url="sounds/ping.wav", copies=2, intensity=0.2)
        self.fairy_sound = Sound(url="sounds/fairy.wav",
                                 copies=2,
                                 intensity=0.2)

        # Lights
        self.button_glow_lamp = space.nodes["PointLight_ButtonGlow"]

        # Texts
        self.sequence_length_text = space.nodes["Text_LengthLabel"]
        self.sequence_length_text.string = []
        self.large_text = space.nodes["Text_LargeLabel"]
        self.large_text.string = []
        self.medium_text = space.nodes["Text_MediumLabel"]
        self.medium_text.string = []

        # Leds
        self.led_materials = []
        for i in range(2):
            m = space.nodes["Material_LED%d" % (i + 1)]
            self.led_materials.append(m)
        self.leds_off()
예제 #8
0
    def build_environment(self):
        # Spinning earth
        self.earthSpinner = hgn.DynamicTransform(
            angularMomentum = Vec3f(0, 0, 0)
        )
        space.nodes["Transform_EarthSea"].reparent_children_to(self.earthSpinner)

        bl = MFBoolListener(
            onTrue = self.touch_earth,
            onFalse = self.untouch_earth,
        )
        space.nodes["Mesh_EarthSea"].h3dNode.isTouched.routeNoEvent(bl)

        self.touchingEarth = False

        # Touchable fruit plate bottom, coupled to release of grabbed objects
        bl = MFBoolListener(
            onTrue = self.grabManager.release,
        )
        space.nodes["Mesh_GrabReleaseSensor"].h3dNode.isTouched.routeNoEvent(bl)

        # Bobbing guide arrow
        self.guideArrow = hgn.Transform()
        self.guideToggle = hgn.ToggleGroup(graphicsOn = False)
        self.guideArrowPos = space.nodes["Transform_GuideArrow"]
        self.guideArrowPos.reparent_children_to(self.guideArrow)
        self.guideArrowPos.reparent_children_to(self.guideToggle)

        # A light that follows the stylus
        """
        self.stylusLight = hgn.PointLight(
            intensity = 0.1,
            attenuation = Vec3f(0, 10, 50),
        )
        self.add_child(self.stylusLight)
        """

        # An unreachable fish swimming in the aquarium
        self.fishTransform = hgn.DynamicTransform(
            position = Vec3f(0, 0.24, 0),
            angularMomentum = Vec3f(0, 0, 0.075),
        )
        fish = X3DFileNode("fish.x3d")
        self.fishTransform.add(fish)
        self.add_child(self.fishTransform)

        # A button that toggles the "aquarium light" on/off. Really controls
        # the aquarium glass transparency.
        button = space.nodes["Transform_LightButton"]
        buttonMesh = space.nodes["Mesh_LightButton"]
        b = PushButton(
            transformNode = button.h3dNode,
            geometry = buttonMesh.h3dNode,
            onPress = self.press_aquarium_button,
            displacement = Vec3f(0, 0.0025, 0),
            hitForce = 1.0,
        )
        space.nodes["ToggleGroup_AquariumGlassEmpty"].graphicsOn = False
        self.aquariumLightOn = False

        self.aquariumLamp = space.nodes["PointLight_AquariumLamp"]
        self.exitLamp = space.nodes["PointLight_ExitLamp"]

        # Tapping on aquarium glass
        bl = MFBoolListener(
            callbackObject = None,
            onTrue = self.tap_glass,
        )
        space.nodes["Mesh_AquariumGlass"].h3dNode.isTouched.routeNoEvent(bl)

        # Something that when touched initiates the exit procedure
        bl = MFBoolListener(
            callbackObject = None,
            onTrue = self.initiate_exit,
        )
        space.nodes["Mesh_ExitSign"].h3dNode.isTouched.routeNoEvent(bl)
        self.exitSignMaterial = space.nodes["Material_ExitSign"]
        self.exiting = False
        self.readyToQuit = False

        # Particle systems

        # Device trail
        p = X3DFileNode("trail_particles.x3d")
        self.trailParticleEmitter = p.find("EMITTER")
        self.add_child(p)