-
Notifications
You must be signed in to change notification settings - Fork 502
/
Copy pathanimatedModelExample.js
134 lines (111 loc) · 3.21 KB
/
animatedModelExample.js
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
//
// animatedModelExample.js
// examples
//
// Created by Brad Hefta-Gaub on 12/31/13.
// Copyright 2014 High Fidelity, Inc.
//
// This is an example script that demonstrates creating and editing a model
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var count = 0;
var moveUntil = 1000;
var stopAfter = moveUntil + 100;
var pitch = 0.0;
var yaw = 0.0;
var roll = 0.0;
var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);
var originalProperties = {
type: "Model",
position: { x: MyAvatar.position.x,
y: MyAvatar.position.y,
z: MyAvatar.position.z },
dimensions: {
x: 1.62,
y: 0.41,
z: 1.13
},
color: { red: 0,
green: 255,
blue: 0 },
modelURL: "http://public.highfidelity.io/cozza13/club/dragon/dragon.fbx",
rotation: rotation,
animation: {
url: "http://public.highfidelity.io/cozza13/club/dragon/flying.fbx",
running: true,
fps: 30,
firstFrame: 10,
lastFrame: 20,
loop: true
}
};
var modelID = Entities.addEntity(originalProperties);
var isPlaying = true;
var playPauseEveryWhile = 360;
var animationFPS = 30;
var adjustFPSEveryWhile = 120;
var resetFrameEveryWhile = 600;
function moveModel(deltaTime) {
var somethingChanged = false;
print("count= " + count);
if (count % playPauseEveryWhile == 0) {
isPlaying = !isPlaying;
print("isPlaying=" + isPlaying);
somethingChanged = true;
}
if (count % adjustFPSEveryWhile == 0) {
if (animationFPS == 30) {
animationFPS = 10;
} else if (animationFPS == 10) {
animationFPS = 60;
} else if (animationFPS == 60) {
animationFPS = 30;
}
print("animationFPS=" + animationFPS);
isPlaying = true;
print("always start playing if we change the FPS -- isPlaying=" + isPlaying);
somethingChanged = true;
}
if (count % resetFrameEveryWhile == 0) {
resetFrame = true;
somethingChanged = true;
}
if (count >= moveUntil) {
// delete it...
if (count == moveUntil) {
print("calling Models.deleteModel()");
Entities.deleteEntity(modelID);
}
// stop it...
if (count >= stopAfter) {
print("calling Script.stop()");
Script.stop();
}
count++;
return; // break early
}
count++;
if (somethingChanged) {
var newProperties = {
animation: {
running: isPlaying,
fps: animationFPS
}
};
if (resetFrame) {
print("resetting the frame!");
newProperties.animation.currentFrame = 0;
resetFrame = false;
}
Entities.editEntity(modelID, newProperties);
}
}
// register the call back so it fires before each data send
Script.update.connect(moveModel);
Script.scriptEnding.connect(function () {
print("cleaning up...");
print("modelID=" + modelID);
Models.deleteModel(modelID);
});