Skip to content

Commit 83f9676

Browse files
author
Avaer Kazmer
committed
Hook in new Unity local engine API
1 parent 8bb1ad3 commit 83f9676

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

vrarmik/AvatarVRTrackingReferences.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import StaticOffsetTransform from './StaticOffsetTransform.js';
55

66
class AvatarVRTrackingReferences extends MonoBehavior
77
{
8-
constructor(...args) {
9-
super(...args);
8+
constructor(transform, components, unity) {
9+
super(transform, components, unity);
1010

1111
this.head = null;
1212
// this.hmd = null;
1313
this.leftHand = null;
1414
this.rightHand = null;
15+
16+
this.unity = unity;
1517
}
1618

1719
Awake()
@@ -42,7 +44,7 @@ import StaticOffsetTransform from './StaticOffsetTransform.js';
4244
let t = this[k];
4345
if (t === null)
4446
{
45-
t = new GameObject(name).AddComponent(StaticOffsetTransform);
47+
t = this.unity.makeGameObject(name).AddComponent(StaticOffsetTransform);
4648
this.transform.AddChild(t.transform);
4749
this.setStaticOffsetSettings(t);
4850
this[k] = t;
@@ -53,7 +55,7 @@ import StaticOffsetTransform from './StaticOffsetTransform.js';
5355
{
5456
if (t === null)
5557
{
56-
t = new GameObject(name).transform;
58+
t = this.unity.makeGameObject(name).transform;
5759
t.transform.localPosition = Vector3.zero;
5860
this.transform.AddChild(t.transform);
5961
}

vrarmik/LegsManager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ class Leg extends MonoBehavior {
174174

175175
class LegsManager extends MonoBehavior
176176
{
177-
constructor(...args) {
178-
super(...args);
177+
constructor(transform, components, unity) {
178+
super(transform, components, unity);
179179

180180
const shoulderTransforms = this.GetOrAddComponent(ShoulderTransforms);
181181
this.hips = shoulderTransforms.hips;
182-
this.leftLeg = new GameObject().AddComponent(Leg);
182+
this.leftLeg = unity.makeGameObject().AddComponent(Leg);
183183
this.hips.AddChild(this.leftLeg.transform);
184-
this.rightLeg = new GameObject().AddComponent(Leg);
184+
this.rightLeg = unity.makeGameObject().AddComponent(Leg);
185185
this.hips.AddChild(this.rightLeg.transform);
186186

187187
this.rightLeg.foot.stickTransform.position = this.rightLeg.foot.position;

vrarmik/PoseManager.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {GameObject, MonoBehavior, XRSettings} from './Unity.js';
44

55
class PoseManager extends MonoBehavior
66
{
7-
constructor(...args) {
8-
super(...args);
7+
constructor(transform, components, unity) {
8+
super(transform, components, unity);
99

10-
this.vrTransforms = new GameObject().AddComponent(VRTrackingReferences);
11-
this.avatarVrTransforms = new GameObject().AddComponent(AvatarVRTrackingReferences);
10+
this.vrTransforms = unity.makeGameObject().AddComponent(VRTrackingReferences);
11+
this.avatarVrTransforms = unity.makeGameObject().AddComponent(AvatarVRTrackingReferences);
12+
this.avatarVrTransforms.poseManager = this;
1213
// this.OnCalibrateListener = null;
1314

1415
// Oculus uses a different reference position -> 0 is the reference head position if the user is standing in the middle of the room.

vrarmik/Rig.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Vector3, Quaternion, GameObject} from './Unity.js';
1+
import {Vector3, Quaternion, Unity} from './Unity.js';
22
import {fixSkeletonZForward} from '../proto/three-ik/modified.AxisUtils.js';
33
import PoseManager from './PoseManager.js';
44
import ShoulderTransforms from './ShoulderTransforms.js';
@@ -47,7 +47,8 @@ class Rig {
4747
this.model = model;
4848
this.options = options;
4949

50-
GameObject.clearAll();
50+
const unity = new Unity();
51+
this.unity = unity;
5152

5253
model.updateMatrixWorld(true);
5354
const skinnedMeshes = [];
@@ -564,7 +565,7 @@ class Rig {
564565
rightFoot: _getOffset(modelBones.Left_ankle),
565566
};
566567

567-
const rigObject = new GameObject('rig');
568+
const rigObject = this.unity.makeGameObject('rig');
568569
this.poseManager = rigObject.AddComponent(PoseManager);
569570
this.poseManager.flipY = flipY;
570571
this.shoulderTransforms = rigObject.AddComponent(ShoulderTransforms);
@@ -667,11 +668,11 @@ class Rig {
667668

668669
this.lastTimestamp = Date.now();
669670

670-
GameObject.startAll();
671+
unity.startAll();
671672
}
672673
update() {
673674
// return;
674-
GameObject.updateAll();
675+
this.unity.updateAll();
675676

676677
for (const k in this.modelBones) {
677678
const modelBone = this.modelBones[k];

vrarmik/ShoulderTransforms.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import PoseManager from './PoseManager.js';
77

88
class ShoulderTransforms extends MonoBehavior
99
{
10-
constructor(...args) {
11-
super(...args);
10+
constructor(transform, components, unity) {
11+
super(transform, components, unity);
1212

1313
this.hips = new Transform();
1414
this.spine = new Transform();
@@ -34,8 +34,8 @@ class ShoulderTransforms extends MonoBehavior
3434
this.rightShoulderAnchor = new Transform();
3535
this.transform.AddChild(this.rightShoulderAnchor);
3636

37-
this.leftArm = new GameObject().AddComponent(ArmTransforms);
38-
this.rightArm = new GameObject().AddComponent(ArmTransforms);
37+
this.leftArm = unity.makeGameObject().AddComponent(ArmTransforms);
38+
this.rightArm = unity.makeGameObject().AddComponent(ArmTransforms);
3939

4040
this.leftShoulderAnchor.AddChild(this.leftArm.transform);
4141
this.rightShoulderAnchor.AddChild(this.rightArm.transform);

0 commit comments

Comments
 (0)