-
Notifications
You must be signed in to change notification settings - Fork 6
/
BaseVRActorClass.ds
361 lines (303 loc) · 11.6 KB
/
BaseVRActorClass.ds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
* MIT License
*
* Copyright (C) 2024, DragonDreams GmbH (info@dragondreams.ch)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Dragengine.Scenery
pin Dragengine.Gui
pin Dragengine.LoadSave
pin Dragengine.Preloading
pin Dragengine.Utils
/**
* \brief VR Actor element class.
* \version 1.6
*
* Extends BaseActorClass with VR behaviors.
*/
class BaseVRActorClass extends BaseActorClass
/**
* \brief Behavior ID used for right hand controller behaviors.
* \version 1.9
*
* Used for behaviors:
* - ECBehaviorVRHand
* - ECBehaviorVRHandPointAt
* - ECBehaviorVRHandLaserPointer
*
* Value is "right".
*/
public static fixed var String idVRRightHand = "right"
/**
* \brief Behavior ID used for left hand controller behaviors.
* \version 1.9
*
* Used for behaviors:
* - ECBehaviorVRHand
* - ECBehaviorVRHandPointAt
* - ECBehaviorVRHandLaserPointer
*
* Value is "left".
*/
public static fixed var String idVRLeftHand = "left"
/**
* \brief Behavior ID used for non-VR based behaviors for right hand controller behaviors.
* \version 1.9
*
* Used for behaviors:
* - ECBehaviorAttachSlot
* - ECBehaviorGrabber
*
* Value is "vrHandRight".
*/
public static fixed var String idNonVRRightHand = "vrHandRight"
/**
* \brief Behavior ID used for non-VR based behaviors for left hand controller behaviors.
* \version 1.9
*
* Used for behaviors:
* - ECBehaviorAttachSlot
* - ECBehaviorGrabber
*
* Value is "vrHandLeft".
*/
public static fixed var String idNonVRLeftHand = "vrHandLeft"
private var ECBehaviorVRPlayspace pVRPlayspace
private var ECBehaviorVRHMD pVRHMD
private var ECBehaviorVRHand pVRRightHand
private var ECBehaviorVRHand pVRLeftHand
private var ECBehaviorVRHandPointAt pVRRightHandPointAt
private var ECBehaviorVRHandPointAt pVRLeftHandPointAt
private var ECBehaviorVRHandLaserPointer pVRRightHandLaserPointer
private var ECBehaviorVRHandLaserPointer pVRLeftHandLaserPointer
private var ECBehaviorAttachSlot pVRRightHandAttachSlot
private var ECBehaviorAttachSlot pVRLeftHandAttachSlot
private var ECBehaviorGrabber pVRRightHandGrabber
private var ECBehaviorGrabber pVRLeftHandGrabber
private var ECBehaviorVRHandPose pVRRightHandPose
private var ECBehaviorVRHandPose pVRLeftHandPose
private var ECBehaviorActorAnimated pVRRightHandAnimated
private var ECBehaviorActorAnimated pVRLeftHandAnimated
private var ECBehaviorVRHandAction pVRRightHandAction
private var ECBehaviorVRHandAction pVRLeftHandAction
/** \brief Create element class using loaders from BaseGameApp. */
public func new() this("VRActor", BaseGameApp.getApp().getLoaders(), \
BaseGameApp.getApp().getPlayerControlledActor())
end
/** \brief Create element class. */
public func new(Loaders loaders, ECBehaviorPlayerControllable.Tracker tracker) \
this("VRActor", loaders, tracker)
end
/** \brief Create element class using loaders from BaseGameApp. */
public func new(String className) this(className, BaseGameApp.getApp().getLoaders(), \
BaseGameApp.getApp().getPlayerControlledActor())
end
/** \brief Create element class. */
public func new(String className, Loaders loaders, ECBehaviorPlayerControllable.Tracker tracker) \
super(className, loaders, tracker)
getAIAction().setActionFactory(BAAFirstPersonVR.Factory.new())
// change horizontal looking speed to 90 degrees per second
getPlayerInputLook().getSpeedLookHorizontal().setValue(90)
// add VR Playspace. this is the base for all VR related behaviors
pVRPlayspace = ECBehaviorVRPlayspace.new(this)
// add HMD behavior allowing to track player head
pVRHMD = ECBehaviorVRHMD.new(this, pVRPlayspace)
// add right and left hand controllers
pVRRightHand = ECBehaviorVRHand.new(this, pVRPlayspace, InputDeviceType.vrRightHand, idVRRightHand)
pVRLeftHand = ECBehaviorVRHand.new(this, pVRPlayspace, InputDeviceType.vrLeftHand, idVRLeftHand)
// add support to know what element hand controllers point at
pVRRightHandPointAt = ECBehaviorVRHandPointAt.new(this, pVRRightHand, idVRRightHand)
pVRLeftHandPointAt = ECBehaviorVRHandPointAt.new(this, pVRLeftHand, idVRLeftHand)
// ignore actor collider for point at behaviors. this avoids problems if the actor
// has a full body collider touching the hands
pVRRightHandPointAt.setIgnoreCollider(getCollider())
pVRLeftHandPointAt.setIgnoreCollider(getCollider())
// add support for laser pointers on hand controllers
pVRRightHandLaserPointer = ECBehaviorVRHandLaserPointer.new(this, pVRRightHandPointAt, idVRRightHand)
pVRLeftHandLaserPointer = ECBehaviorVRHandLaserPointer.new(this, pVRLeftHandPointAt, idVRLeftHand)
// add support for grabbing grab slots using hand controllers. the aim pose for
// controllers is located above and in front of the hand. move the grab position
// into the hand. this is a static offset. users can instead use a hand model
// bone to attach objects to which is better
//
// the grip center is usually located -11cm along grab orientation, which is 45 degrees
// upwards. this yields (0, -0.078, -0.078). this is though a bit lower on the palm
// and for this reason it is lifted slightly up to better line up with where the palm
// usually is located.
var Vector position = Vector.new(0, -0.058, -0.078)
var Vector rotation = Vector.new(0, 0, 0)
var ShapeList shape = ShapeList.new()
shape.addSphere(Vector.new(), 0.05)
pVRRightHandGrabber = ECBehaviorGrabber.new(this, pVRRightHand, idNonVRRightHand)
pVRRightHandGrabber.getShape().setShapeList(shape)
pVRRightHandGrabber.getAttach().getPosition().setVector(position + Vector.new(-0.02, 0, 0.02))
pVRRightHandGrabber.getAttach().getOrientation().setVector(rotation)
pVRLeftHandGrabber = ECBehaviorGrabber.new(this, pVRLeftHand, idNonVRLeftHand)
pVRLeftHandGrabber.getShape().setShapeList(shape)
pVRLeftHandGrabber.getAttach().getPosition().setVector(position + Vector.new(0.02, 0, 0.02))
pVRLeftHandGrabber.getAttach().getOrientation().setVector(rotation)
// add attach slot for attaching objects to the hands
pVRRightHandAttachSlot = ECBehaviorAttachSlot.new(this, null, pVRRightHand,\
idNonVRRightHand, "attachSlot(" + idNonVRRightHand + ").")
pVRRightHandAttachSlot.getPosition().setVector(position)
pVRRightHandAttachSlot.getOrientation().setVector(rotation)
pVRLeftHandAttachSlot = ECBehaviorAttachSlot.new(this, null, pVRLeftHand,\
idNonVRLeftHand, "attachSlot(" + idNonVRLeftHand + ").")
pVRLeftHandAttachSlot.getPosition().setVector(position)
pVRLeftHandAttachSlot.getOrientation().setVector(rotation)
// add hand pose support
pVRRightHandPose = ECBehaviorVRHandPose.new(this, pVRRightHand, idNonVRRightHand,\
"vrHandPose(" + idNonVRRightHand + ").")
pVRLeftHandPose = ECBehaviorVRHandPose.new(this, pVRLeftHand, idNonVRLeftHand,\
"vrHandPose(" + idNonVRLeftHand + ").")
// add animation support to hands
pVRRightHandAnimated = ECBehaviorActorAnimated.new(this, pVRRightHand.getComponent(),\
getLocomotion(), idNonVRRightHand, "actorAnimated(" + idNonVRRightHand + ").")
pVRRightHandAnimated.getControllerMapping().setAt("idle", LocomotionAttribute.elapsedTime)
pVRRightHandAnimated.getControllerMapping().setAt("interaction", LocomotionAttribute.elapsedTime)
pVRLeftHandAnimated = ECBehaviorActorAnimated.new(this, pVRLeftHand.getComponent(),\
getLocomotion(), idNonVRLeftHand, "actorAnimated(" + idNonVRLeftHand + ").")
pVRLeftHandAnimated.getControllerMapping().setAt("idle", LocomotionAttribute.elapsedTime)
pVRLeftHandAnimated.getControllerMapping().setAt("interaction", LocomotionAttribute.elapsedTime)
// add action support to both hands
pVRRightHandAction = ECBehaviorVRHandAction.new(this, pVRRightHand,\
getConversationActor(), idVRRightHand)
pVRLeftHandAction = ECBehaviorVRHandAction.new(this, pVRLeftHand,\
getConversationActor(), idVRLeftHand)
end
/** \brief VR Playspace behavior. */
public func ECBehaviorVRPlayspace getVRPlayspace()
return pVRPlayspace
end
/** \brief VR HMD. */
public func ECBehaviorVRHMD getVRHMD()
return pVRHMD
end
/** \brief VR Right Hand Controller. */
public func ECBehaviorVRHand getVRRightHand()
return pVRRightHand
end
/** \brief VR Left Hand Controller. */
public func ECBehaviorVRHand getVRLeftHand()
return pVRLeftHand
end
/**
* \brief VR Right Hand Controller Point-At.
* \version 1.7
*/
public func ECBehaviorVRHandPointAt getVRRightHandPointAt()
return pVRRightHandPointAt
end
/**
* \brief VR Left Hand Controller Point-At.
* \version 1.7
*/
public func ECBehaviorVRHandPointAt getVRLeftHandPointAt()
return pVRLeftHandPointAt
end
/**
* \brief VR Right Hand Controller Laser Pointer.
* \version 1.7
*/
public func ECBehaviorVRHandLaserPointer getVRRightHandLaserPointer()
return pVRRightHandLaserPointer
end
/**
* \brief VR Left Hand Controller Laser Pointer.
* \version 1.7
*/
public func ECBehaviorVRHandLaserPointer getVRLeftHandLaserPointer()
return pVRLeftHandLaserPointer
end
/**
* \brief VR Right Hand Controller Attach Slot.
* \version 1.9
*/
public func ECBehaviorAttachSlot getVRRightHandAttachSlot()
return pVRRightHandAttachSlot
end
/**
* \brief VR Left Hand Controller Attach Slot.
* \version 1.9
*/
public func ECBehaviorAttachSlot getVRLeftHandAttachSlot()
return pVRLeftHandAttachSlot
end
/**
* \brief VR Right Hand Controller Grabber.
* \version 1.9
*/
public func ECBehaviorGrabber getVRRightHandGrabber()
return pVRRightHandGrabber
end
/**
* \brief VR Left Hand Controller Grabber.
* \version 1.9
*/
public func ECBehaviorGrabber getVRLeftHandGrabber()
return pVRLeftHandGrabber
end
/**
* \brief VR Right Hand Pose.
* \version 1.10
*/
public func ECBehaviorVRHandPose getVRRightHandPose()
return pVRRightHandPose
end
/**
* \brief VR Left Hand Pose.
* \version 1.10
*/
public func ECBehaviorVRHandPose getVRLeftHandPose()
return pVRLeftHandPose
end
/**
* \brief VR Right Hand Animated.
* \version 1.10
*/
public func ECBehaviorActorAnimated getVRRightHandAnimated()
return pVRRightHandAnimated
end
/**
* \brief VR Left Hand Animated.
* \version 1.10
*/
public func ECBehaviorActorAnimated getVRLeftHandAnimated()
return pVRLeftHandAnimated
end
/**
* \brief VR Right Hand Action.
* \version 1.10
*/
public func ECBehaviorVRHandAction getVRRightHandAction()
return pVRRightHandAction
end
/**
* \brief VR Left Hand Action.
* \version 1.10
*/
public func ECBehaviorVRHandAction getVRLeftHandAction()
return pVRLeftHandAction
end
/** \brief Create element instance. */
protected func Element createElement()
return BaseVRActor.new(this)
end
end