Skip to content

Commit

Permalink
attempting to update NPC with new UI
Browse files Browse the repository at this point in the history
-doesn't crash with error
-added Position(), Rotation(), and Scale() where relevant
  • Loading branch information
johnchoi313 committed Sep 19, 2023
1 parent bf73520 commit 587212d
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 275 deletions.
3 changes: 2 additions & 1 deletion examples/MyCobotPi/MyCobotPi320.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
myCobot.set_gripper_value(99, 80)

#------MAKE CONNECT TO ARENA------#
scene = Scene(host="mqtt.arenaxr.org", namespace = "johnchoi", scene="MyCobotPi320")
#scene = Scene(host="mqtt.arenaxr.org", namespace = "johnchoi", scene="MyCobotPi320")
scene = Scene(host="arenaxr.org", namespace = "public", scene="arena")

#------MAKE ROBOT ARM------#
MyCobotPi_Base = Box(
Expand Down
26 changes: 14 additions & 12 deletions examples/NPCs/ArenaDialogueBubbleGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def __init__(self, scene, npc, gltf, image, video, dialogue):
self.videoUsedThisLine = False
self.soundUsedThisLine = False

self.lastImageSize = (0,0,0)
self.lastVideoSize = (0,0,0)
self.lastImageSize = Scale(0,0,0)
self.lastVideoSize = Scale(0,0,0)

self.lastTransform = TRANSFORM_RESET

Expand Down Expand Up @@ -262,10 +262,10 @@ def PlayVideo(self, video):
self.scene.update_object(self.video)

def HideVideo(self):
self.ScaleAnimation(self.video, self.lastVideoSize, (0,0,random.uniform(0, 0.01)))
#self.ScaleAnimation(self.video, self.lastVideoSize, Scale(0,0,random.uniform(0, 0.01)))
self.lastVideoSize = (0,0,0)
def ShowVideo(self, scale):
self.ScaleAnimation(self.video, (0,0,random.uniform(0, 0.01)), scale)
#self.ScaleAnimation(self.video, Scale(0,0,random.uniform(0, 0.01)), scale)
self.lastVideoSize = scale

#Images
Expand All @@ -290,20 +290,22 @@ def PlayImage(self, img):
self.ShowImage(self.getNewScale(img.w, img.h, img.size))
self.scene.update_object(self.image, url = img.url)
def HideImage(self):
self.ScaleAnimation(self.image, self.lastImageSize, (0,0,random.uniform(0, 0.01)))
#self.ScaleAnimation(self.image, self.lastImageSize, Scale(0,0,random.uniform(0, 0.01)))
self.lastImageSize = (0,0,0)
def ShowImage(self, scale):
self.ScaleAnimation(self.image, (0,0,random.uniform(0, 0.01)), scale)
#self.ScaleAnimation(self.image, Scale(0,0,random.uniform(0, 0.01)), scale)
self.lastImageSize = scale

if(USE_DEFAULT_SOUNDS and not self.soundUsedThisLine):
self.PlaySound(SOUND_IMAGE)

#Scaling helper functions.
def ScaleAnimation(self, plane, startScale, endScale):
animation = Animation(property="scale", start=startScale, end=endScale, easing="easeInOutQuad", dur=PLANE_SCALE_DURATION)
plane.dispatch_animation(animation)
self.scene.run_animations(plane)
#animation = Animation(property="scale", start=startScale, end=endScale, easing="easeInOutQuad", dur=PLANE_SCALE_DURATION)
#plane.dispatch_animation(animation)
#self.scene.run_animations(plane)
plane.update_attributes(scale = endScale)

def getNewScale(self, w, h, size):
aspect = ( w * 1.0 ) / ( h * 1.0 )
scale = 1
Expand Down Expand Up @@ -333,7 +335,7 @@ def SetVisible(self, key, visible):
def ClearCommandProperties(self):
#scale the link button out because delete won't work
if(self.linkButton != None and self.checkIfArenaObjectExists(self.linkButton.box)):
self.ScaleAnimation(self.linkButton.box, LINK_BUBBLE_SCALE, (0,0,random.uniform(0, 0.01)))
#self.ScaleAnimation(self.linkButton.box, LINK_BUBBLE_SCALE, Scale(0,0,random.uniform(0, 0.01)))
self.scene.delete_object(self.linkButton.text)
self.scene.delete_object(self.linkButton.box)

Expand Down Expand Up @@ -468,15 +470,15 @@ def createButtons(self, line):
printMagenta(" [["+str(c)+"]] choiceText: " + choices[c].text)
printMagenta( " choiceNode: " + choices[c].node)

choiceButton = Button(self.scene, self.npc, self.npc.object_id + "_choiceButton_" + self.randomUUID(UUID_LEN)+"_"+str(c), choices[c].text, self.onClickChoiceButton,
choiceButton = NPCButton(self.scene, self.npc, self.npc.object_id + "_choiceButton_" + self.randomUUID(UUID_LEN)+"_"+str(c), choices[c].text, self.onClickChoiceButton,
#choiceButton = Button(self.scene, self.npc, self.npc.object_id + "_choiceButton_" + "_"+str(c), choices[c].text, self.onClickChoiceButton,
position = (CHOICE_BUBBLE_POSITION[0], CHOICE_BUBBLE_POSITION[1] + (len(choices) - c - 1) * CHOICE_BUBBLE_OFFSET_Y, CHOICE_BUBBLE_POSITION[2]),
rotation = CHOICE_BUBBLE_ROTATION, buttonScale = CHOICE_BUBBLE_SCALE, textScale = CHOICE_TEXT_SCALE, color = CHOICE_BUBBLE_COLOR, textColor = CHOICE_TEXT_COLOR,
persist=False)

self.buttons.append(choiceButton)
else:
nextButton = Button(self.scene, self.npc, self.npc.object_id + "_nextButton_" + self.randomUUID(UUID_LEN), "[Next]", self.onClickNextButton,
nextButton = NPCButton(self.scene, self.npc, self.npc.object_id + "_nextButton_" + self.randomUUID(UUID_LEN), "[Next]", self.onClickNextButton,
#nextButton = Button(self.scene, self.npc, self.npc.object_id + "_nextButton", "[Next]", self.onClickNextButton,
position = CHOICE_BUBBLE_POSITION, rotation = CHOICE_BUBBLE_ROTATION, buttonScale = CHOICE_BUBBLE_SCALE,
textScale = CHOICE_TEXT_SCALE, color = CHOICE_BUBBLE_COLOR, textColor = CHOICE_TEXT_COLOR,
Expand Down
26 changes: 19 additions & 7 deletions examples/NPCs/Button.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@

from asyncio import create_subprocess_exec

class Button():
class NPCButton():
def __init__(self, scene, npc, name, text, eventHandler, position, rotation, buttonScale, textScale, color, textColor, persist):
self.scene = scene
self.npc = npc

self.box = self.makeButtonBox(name, text, eventHandler, color, position, rotation, buttonTextColor=textColor, buttonScale = buttonScale, persist=persist)
self.text = self.makeButtonText(self.box, name, text, buttonColor=textColor, buttonScale = textScale, persist=persist)

def makeButtonText(self, button, buttonID, buttonText, buttonColor = (255,255,255), buttonPos = (0, 0, 0.6), buttonRot = (0,0,0), buttonScale = (0.5, 2, 1), persist=False):
def makeButtonText(self, button, buttonID, buttonText,
buttonColor = Color(255,255,255),
buttonPos = Position(0, 0, 0.6),
buttonRot = Rotation(0,0,0),
buttonScale = Scale(0.5, 2, 1),
persist=False):
#Create Button Text Object
buttonText = Text(
object_id=buttonID+"_text",
Expand All @@ -39,14 +44,21 @@ def makeButtonText(self, button, buttonID, buttonText, buttonColor = (255,255,25
#Return created object
return buttonText

def makeButtonBox(self, buttonID, buttonText, buttonHandler, buttonColor = (128,128,128), buttonPos = (0,0,0), buttonRot = (0,0,0), buttonScale = (0.4, 0.08, 0.04), buttonTextColor = (255,255,255), persist=False):
def makeButtonBox(self, buttonID, buttonText, buttonHandler,
buttonColor = Color(128,128,128),
buttonPos = Position(0,0,0),
buttonRot = Rotation(0,0,0),
buttonScale = Scale(0.4, 0.08, 0.04),
buttonTextColor = Color(255,255,255),
persist=False):
#Create Button Object
button = Box(
object_id=buttonID,

position=buttonPos,
rotation=buttonRot,
scale=(0,0,0),
#scale=Scale(0,0,0),
scale=buttonScale,

material = Material(color = buttonColor, transparent = True, opacity=CHOICE_BUBBLE_OPACITY),

Expand All @@ -57,8 +69,8 @@ def makeButtonBox(self, buttonID, buttonText, buttonHandler, buttonColor = (128,
)
self.scene.add_object(button)
#Button Appearance Animation
animation = Animation(property="scale", start=(0,0,0), end=buttonScale, easing="easeInOutQuad", dur=CHOICE_SCALE_DURATION)
button.dispatch_animation(animation)
self.scene.run_animations(button)
#animation = Animation(property="scale", start=Position(0,0,0), end=buttonScale, easing="easeInOutQuad", dur=CHOICE_SCALE_DURATION)
#button.dispatch_animation(animation)
#self.scene.run_animations(button)
#Return created object
return button
206 changes: 0 additions & 206 deletions examples/NPCs/NPC-Copy.py

This file was deleted.

Loading

0 comments on commit 587212d

Please sign in to comment.