Skip to content

Commit e5bf014

Browse files
committed
Initial commit.
0 parents  commit e5bf014

236 files changed

Lines changed: 25881 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGES

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--------------------------
2+
PlayCanvas Runtime Changes
3+
--------------------------
4+
5+
------
6+
v0.7.0
7+
------
8+
9+
* Added first pass at an animation component. Just loads/runs a single animation for now.
10+
* Added new render state management API, introducing the idea of global and local state.
11+
* Use the alpha channel in a specular map as the per-pixel shininess value.
12+
* Fix for Phong GLSL when no lights are activated.
13+
* Reworked parallax mapping. Effect now activates if an alpha channel is found in the normal map (containing a height map).
14+
* Updated parallax effect in shadowmap sample.
15+
* Updated skybox component to work with any camera clip planes. Also now just maintains a geometry instead of a mesh.
16+
* Fixed transparency for Maya FBX exports.
17+
* Added Visualizer launcher script for Maya (written in Python rather than MEL).
18+
* Added runtime support for emissive maps.
19+
20+
------
21+
v0.6.0
22+
------
23+
24+
* Added CHANGES file
25+
* [FIX] gizmo and pick components no longer deleted when components are updated, should be done manually for now
26+
* Added pc.dom namespace for DOM related code
27+
* Updated artwork to all use the correct system units (inches).
28+
* Stop deserializing entities from message as they are transferred as normal javascript object now
29+
* Changed reference from _id to resource_id in entity loader to support new Corazon format
30+
* Add resource_id to Entity to support new Corazon format
31+
* [FIX] Light component correctly disables light node when it is deleted
32+
* Added skeleton docs to pc.gfx.Texture.
33+
* Updated pc.gfx.Texture to be a little cleaner and more versatile (now handles canvas, video and image elements as well as byte pixel arrays).
34+
* Fleshed out docs for pc.gfx.Texture.
35+
36+
37+
------
38+
v0.5.0
39+
------
40+
41+
* ScriptLoader replaces ResourceLoader object
42+
* Added toolsRender and toolsUpdate methods to Components
43+
* Better rendering for directional lights in the Designer.
44+
* Enable backface culling in the engine by default.
45+
* Model and Camera components to be deleted correctly.
46+
* Added support for scale in animation keyframes.
47+
* All artwork is now generated as 1 unit equalling 1 meter.
48+
* Tweaks to Ferrari demo assets.
49+
* Changed pc.graph.Cameras default clip planes to work better for worlds scaled to meters.
50+
* Stop FACT from physically loading texture images.
51+
* Handle relative paths which are actually absolute paths on other drives.
52+
* Integrated ImageMagick into FACT.
53+
* Upgraded some deprecated FBX functions in FACT.
54+
* Added backface culling option and a stats panel to Visualizer.
55+
* Frame loaded model with the default camera in Visualizer.
56+
* Update Visualizer launcher to only call FACT (Python commands stripped).
57+
* Fix initial camera offset in Visualizer.
58+
* Write PNGs instead of JPG if non-web format textures have an alpha channel.
59+
* Updated JSON format to split out opacity into new uniform.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.10.0dev

src/anim/anim_anim.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @namespace Namespace for functionality related to keyframed skeletal animation.
3+
* @name pc.anim
4+
*/
5+
pc.anim = {};

src/anim/anim_animation.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
pc.anim.Key = function Key() {
2+
this._quat = pc.math.quat.create(0, 0, 0, 0);
3+
this._pos = pc.math.vec3.create(0, 0, 0);
4+
this._time = 0;
5+
}
6+
7+
pc.extend(pc.anim, function () {
8+
/**
9+
* @name pc.anim.Animation
10+
* @class An animation is a sequence of keyframe arrays which map to the nodes of a skeletal hierarchy.
11+
* It controls how the nodes of the hierarchy are transformed over time.
12+
* @description Returns a new pc.anim.Animation object.
13+
*/
14+
var Animation = function Animation() {
15+
this._name = "";
16+
this._duration = 0;
17+
this._nodes = [];
18+
};
19+
20+
/**
21+
* @function
22+
* @name pc.anim.Animation#getDuration
23+
* @description Returns the duration of the animation in seconds.
24+
* @returns {number} The duration of the animation in seconds.
25+
* @author Will Eastcott
26+
*/
27+
Animation.prototype.getDuration = function () {
28+
return this._duration;
29+
};
30+
31+
/**
32+
* @function
33+
* @name pc.anim.Animation#getName
34+
* @description Returns the human-readable name of the animation.
35+
* @returns {string} The name of the animation.
36+
* @author Will Eastcott
37+
*/
38+
Animation.prototype.getName = function () {
39+
return this._name;
40+
};
41+
42+
/**
43+
* @function
44+
* @name pc.anim.Animation#getNodes
45+
* @description
46+
* @returns {Array}
47+
* @author Will Eastcott
48+
*/
49+
Animation.prototype.getNodes = function () {
50+
return this._nodes;
51+
};
52+
53+
/**
54+
* @function
55+
* @name pc.anim.Animation#setDuration
56+
* @description Sets the duration of the specified animation in seconds.
57+
* @param {number} duration The duration of the animation in seconds.
58+
* @author Will Eastcott
59+
*/
60+
Animation.prototype.setDuration = function (duration) {
61+
this._duration = duration;
62+
};
63+
64+
/**
65+
* @function
66+
* @name pc.anim.Animation#setName
67+
* @description Sets the human-readable name of the specified animation.
68+
* @param {number} name The new name for the animation.
69+
* @author Will Eastcott
70+
*/
71+
Animation.prototype.setName = function (name) {
72+
this._name = name;
73+
};
74+
75+
/**
76+
* @function
77+
* @name pc.anim.Animation#setNodes
78+
* @description
79+
* @param {number} nodes
80+
* @author Will Eastcott
81+
*/
82+
Animation.prototype.setNodes = function (nodes) {
83+
this._nodes = nodes;
84+
};
85+
86+
return {
87+
Animation: Animation
88+
};
89+
}());

src/anim/anim_skeleton.js

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
pc.anim.InterpolatedKey = function InterpolatedKey() {
2+
this._keyFrames = [];
3+
4+
// Result of interpolation
5+
this._quat = pc.math.quat.create(0, 0, 0, 0);
6+
this._pos = pc.math.vec3.create(0, 0, 0);
7+
this._scale = pc.math.vec3.create(0, 0, 0);
8+
9+
// Optional destination for interpolated keyframe
10+
this._targetNode = null;
11+
}
12+
13+
pc.anim.InterpolatedKey.prototype.getTarget = function () {
14+
return this._targetNode;
15+
}
16+
17+
pc.anim.InterpolatedKey.prototype.setTarget = function (node) {
18+
this._targetNode = node;
19+
}
20+
21+
pc.extend(pc.anim, function () {
22+
/**
23+
* @name pc.anim.Skeleton
24+
* @class A skeleton.
25+
*/
26+
var Skeleton = function Skeleton(numNodes) {
27+
this._animation = null;
28+
this._time = 0;
29+
this._interpolatedKeys = [];
30+
for (var i = 0; i < numNodes; i++) {
31+
this._interpolatedKeys[i] = new pc.anim.InterpolatedKey();
32+
}
33+
this.looping = true;
34+
};
35+
36+
/**
37+
* @function
38+
* @name pc.anim.Skeleton#addTime
39+
* @description
40+
* @param {number} delta
41+
* @author Will Eastcott
42+
*/
43+
Skeleton.prototype.addTime = function (delta) {
44+
if (this._animation !== null) {
45+
this._time += delta;
46+
var duration = this._animation.getDuration();
47+
if (this._time > duration) {
48+
this._time = this.looping ? 0.0 : duration;
49+
}
50+
51+
var nodes = this._animation.getNodes();
52+
for (var i = 0; i < nodes.length; i++) {
53+
var keys = nodes[i];
54+
55+
// Find keyframe pair
56+
for (var currKeyIndex = 0; currKeyIndex < keys.length-1; currKeyIndex++) {
57+
var k1 = keys[currKeyIndex];
58+
var k2 = keys[currKeyIndex + 1];
59+
60+
if ((k1._time <= this._time) && (k2._time >= this._time)) {
61+
var alpha = (this._time - k1._time) / (k2._time - k1._time);
62+
63+
pc.math.quat.slerp(k1._quat, k2._quat, alpha, this._interpolatedKeys[i]._quat);
64+
pc.math.vec3.lerp(k1._pos, k2._pos, alpha, this._interpolatedKeys[i]._pos);
65+
pc.math.vec3.lerp(k1._scale, k2._scale, alpha, this._interpolatedKeys[i]._scale);
66+
}
67+
}
68+
}
69+
}
70+
};
71+
72+
/**
73+
* @function
74+
* @name pc.anim.Skeleton#blend
75+
* @description Blends two skeletons together.
76+
* @param {pc.anim.Skeleton} a Skeleton holding the first pose to be blended.
77+
* @param {pc.anim.Skeleton} b Skeleton holding the second pose to be blended.
78+
* @author Will Eastcott
79+
*/
80+
Skeleton.prototype.blend = function (a, b, alpha) {
81+
var numNodes = this._interpolatedKeys.length;
82+
for (var i = 0; i < numNodes; i++) {
83+
pc.math.quat.slerp(a._interpolatedKeys[i]._quat, b._interpolatedKeys[i]._quat, alpha, this._interpolatedKeys[i]._quat);
84+
pc.math.vec3.lerp(a._interpolatedKeys[i]._pos, b._interpolatedKeys[i]._pos, alpha, this._interpolatedKeys[i]._pos);
85+
pc.math.vec3.lerp(a._interpolatedKeys[i]._scale, b._interpolatedKeys[i]._scale, alpha, this._interpolatedKeys[i]._scale);
86+
}
87+
};
88+
89+
/**
90+
* @function
91+
* @name pc.anim.Skeleton#getAnimation
92+
* @description
93+
* @returns {pc.anim.Animation}
94+
* @author Will Eastcott
95+
*/
96+
Skeleton.prototype.getAnimation = function () {
97+
return this._animation;
98+
};
99+
100+
/**
101+
* @function
102+
* @name pc.anim.Skeleton#getCurrentTime
103+
* @description Returns the current time of the currently active animation as set on
104+
* the specified skeleton. This value will be between zero and the duration of the
105+
* animation.
106+
* @returns {number} The current time of the animation set on the skeleton.
107+
* @author Will Eastcott
108+
*/
109+
Skeleton.prototype.getCurrentTime = function () {
110+
return this._time;
111+
}
112+
113+
/**
114+
* @function
115+
* @name pc.anim.Skeleton#setCurrentTime
116+
* @description Sets the current time of the currently active animation as set on
117+
* the specified skeleton. This value must be between zero and the duration of the
118+
* animation.
119+
* @param {number} The current time of the animation set on the skeleton.
120+
* @author Will Eastcott
121+
*/
122+
Skeleton.prototype.setCurrentTime = function (time) {
123+
this._time = time;
124+
}
125+
126+
/**
127+
* @function
128+
* @name pc.anim.Skeleton#getNumNodes
129+
* @description Returns the number of nodes held by the specified skeleton.
130+
* @returns {number} The number of nodes held by the specified skeleton.
131+
* @author Will Eastcott
132+
*/
133+
Skeleton.prototype.getNumNodes = function () {
134+
return this._interpolatedKeys.length;
135+
}
136+
137+
/**
138+
* @function
139+
* @name pc.anim.Skeleton#setAnimation
140+
* @description
141+
* @param {pc.anim.Animation} animation
142+
* @author Will Eastcott
143+
*/
144+
Skeleton.prototype.setAnimation = function (animation) {
145+
this._animation = animation;
146+
this._time = 0;
147+
};
148+
149+
/**
150+
* @function
151+
* @name pc.anim.Skeleton#setGraph
152+
* @description
153+
* @param {pc.scene.GraphNode} graph
154+
* @author Will Eastcott
155+
*/
156+
Skeleton.prototype.setGraph = function (graph) {
157+
var nodeIndex = 0;
158+
var setGraph = function(skeleton, node) {
159+
skeleton._interpolatedKeys[nodeIndex++].setTarget(node);
160+
var children = node.getChildren();
161+
for (var i = 0; i < children.length; i++) {
162+
setGraph(skeleton, children[i]);
163+
}
164+
}
165+
setGraph(this, graph);
166+
};
167+
168+
/**
169+
* @function
170+
* @name pc.anim.Skeleton#updateGraph
171+
* @description
172+
* @author Will Eastcott
173+
*/
174+
Skeleton.prototype.updateGraph = function () {
175+
logASSERT((this._animation !== null), "Skeleton requires an animation in order to update a scene graph");
176+
177+
var nodes = this._animation.getNodes();
178+
for (var i = 0; i < nodes.length; i++) {
179+
if (nodes[i].length > 0) {
180+
var interpKey = this._interpolatedKeys[i];
181+
182+
var ltm = interpKey.getTarget().getLocalTransform();
183+
pc.math.quat.toMat4(interpKey._quat, ltm);
184+
ltm[0] *= interpKey._scale[0];
185+
ltm[4] *= interpKey._scale[0];
186+
ltm[8] *= interpKey._scale[0];
187+
ltm[1] *= interpKey._scale[1];
188+
ltm[5] *= interpKey._scale[1];
189+
ltm[9] *= interpKey._scale[1];
190+
ltm[2] *= interpKey._scale[2];
191+
ltm[6] *= interpKey._scale[2];
192+
ltm[10] *= interpKey._scale[2];
193+
ltm[12] = interpKey._pos[0];
194+
ltm[13] = interpKey._pos[1];
195+
ltm[14] = interpKey._pos[2];
196+
}
197+
}
198+
};
199+
200+
/**
201+
* @function
202+
* @name pc.anim.Skeleton#setLooping
203+
* @param looping {boolean}
204+
* @description
205+
* @author Will Eastcott
206+
*/
207+
Skeleton.prototype.setLooping = function (looping) {
208+
this.looping = looping;
209+
};
210+
211+
/**
212+
* @function
213+
* @name pc.anim.Skeleton#getLooping
214+
* @return {boolean}
215+
* @description
216+
* @author Will Eastcott
217+
*/
218+
Skeleton.prototype.getLooping = function () {
219+
return this.looping;
220+
};
221+
222+
return {
223+
Skeleton: Skeleton
224+
};
225+
}());

0 commit comments

Comments
 (0)