Clean up.

This commit is contained in:
NathanSweet 2016-04-03 18:16:17 +02:00
parent f2f9572ae3
commit cc40f1be93
7 changed files with 149 additions and 396 deletions

2
.gitignore vendored
View File

@ -96,3 +96,5 @@ spine-starling/spine-starling-example/bin
spine-starling/spine-starling-example/lib/.spine-starling.swc.stamp
spine-turbulenz/spine-js/spine.js
spine-threejs/spine-js/spine.js

View File

@ -1,223 +0,0 @@
skeleton.png
size: 512,128
format: RGBA8888
filter: Linear,Linear
repeat: none
hair
rotate: false
xy: 2, 48
size: 44, 69
orig: 44, 69
offset: 0, 0
index: -1
hat
rotate: false
xy: 192, 89
size: 54, 28
orig: 54, 28
offset: 0, 0
index: -1
head
rotate: false
xy: 142, 67
size: 48, 50
orig: 48, 50
offset: 0, 0
index: -1
left-arm-bottom
rotate: false
xy: 41, 8
size: 17, 32
orig: 17, 32
offset: 0, 0
index: -1
left-arm-top
rotate: false
xy: 23, 7
size: 16, 39
orig: 16, 39
offset: 0, 0
index: -1
left-foot
rotate: false
xy: 198, 2
size: 30, 20
orig: 30, 20
offset: 0, 0
index: -1
left-foot-boots
rotate: false
xy: 248, 95
size: 30, 22
orig: 30, 22
offset: 0, 0
index: -1
left-hand
rotate: false
xy: 230, 5
size: 14, 17
orig: 14, 17
offset: 0, 0
index: -1
left-leg-bottom
rotate: false
xy: 276, 35
size: 17, 58
orig: 17, 58
offset: 0, 0
index: -1
left-leg-top
rotate: false
xy: 142, 2
size: 26, 63
orig: 26, 63
offset: 0, 0
index: -1
left-lower-arm-shirt
rotate: false
xy: 60, 10
size: 18, 30
orig: 18, 30
offset: 0, 0
index: -1
left-lower-leg-boots
rotate: false
xy: 80, 10
size: 13, 22
orig: 13, 22
offset: 0, 0
index: -1
left-lower-leg-pants
rotate: false
xy: 254, 32
size: 20, 61
orig: 20, 61
offset: 0, 0
index: -1
right-lower-leg-pants
rotate: false
xy: 254, 32
size: 20, 61
orig: 20, 61
offset: 0, 0
index: -1
left-upper-arm-shirt
rotate: false
xy: 2, 6
size: 19, 40
orig: 19, 40
offset: 0, 0
index: -1
right-upper-arm-shirt
rotate: false
xy: 2, 6
size: 19, 40
orig: 19, 40
offset: 0, 0
index: -1
left-upper-leg-pants
rotate: false
xy: 170, 2
size: 26, 63
orig: 26, 63
offset: 0, 0
index: -1
right-arm-middle
rotate: false
xy: 392, 85
size: 17, 32
orig: 17, 32
offset: 0, 0
index: -1
right-arm-top
rotate: false
xy: 314, 56
size: 16, 39
orig: 16, 39
offset: 0, 0
index: -1
right-foot
rotate: false
xy: 312, 97
size: 30, 20
orig: 30, 20
offset: 0, 0
index: -1
right-foot-boots
rotate: false
xy: 280, 95
size: 30, 22
orig: 30, 22
offset: 0, 0
index: -1
right-hand
rotate: false
xy: 314, 37
size: 14, 17
orig: 14, 17
offset: 0, 0
index: -1
right-leg-bottom
rotate: false
xy: 295, 35
size: 17, 58
orig: 17, 58
offset: 0, 0
index: -1
right-leg-top
rotate: false
xy: 198, 24
size: 26, 63
orig: 26, 63
offset: 0, 0
index: -1
right-lower-arm-shirt
rotate: false
xy: 372, 87
size: 18, 30
orig: 18, 30
offset: 0, 0
index: -1
right-lower-leg-boots
rotate: false
xy: 411, 95
size: 13, 22
orig: 13, 22
offset: 0, 0
index: -1
right-upper-leg-pants
rotate: false
xy: 226, 24
size: 26, 63
orig: 26, 63
offset: 0, 0
index: -1
shirt
rotate: false
xy: 48, 42
size: 30, 75
orig: 30, 75
offset: 0, 0
index: -1
torso
rotate: false
xy: 112, 34
size: 28, 83
orig: 28, 83
offset: 0, 0
index: -1
torso-clothed
rotate: false
xy: 80, 34
size: 30, 83
orig: 30, 83
offset: 0, 0
index: -1
torso-pants
rotate: false
xy: 344, 93
size: 26, 24
orig: 26, 24
offset: 0, 0
index: -1

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -31,7 +31,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>spine-js</title>
<title>spine-threejs</title>
<script src="../spine-js/spine.js"></script>
<script src="../three.min.js"></script>
@ -39,15 +39,7 @@
</head>
<body>
<input type="button" value="Spineboy" onclick="load('spineboy', 0.6)">
<input type="button" value="Hero" onclick="load('hero', 1)">
<input type="button" value="Goblins" onclick="load('goblins', 1)">
<input type="button" value="Gipsy" onclick="load('skeleton', 1)">
&nbsp; &nbsp; Click to change the animation or skin.
<br>
<script>
(function () {
var loadText = function (url, callback) {
@ -70,11 +62,11 @@
return image;
};
SpineAnimation = function (animation, path, scale) {
SpineAnimation = function (name, path, scale) {
THREE.Object3D.call(this);
this.name = animation;
this.name = name;
path = path ? (path +
((path.substr(-1) != '/') ? '/' : '')
@ -82,7 +74,7 @@
var self = this;
loadText (path + animation + '.atlas', function (atlasText) {
loadText(path + name + '.atlas', function (atlasText) {
self.atlas = new spine.Atlas(atlasText, {
load: function (page, image, atlas) {
loadImage(path + image, function (image) {
@ -125,9 +117,7 @@
if (material.meshes) {
for (var name in material.meshes) {
var mesh = material.meshes[name];
if (mesh.parent) {
mesh.parent.remove (mesh);
}
if (mesh.parent) mesh.parent.remove(mesh);
mesh.geometry.dispose();
}
}
@ -139,7 +129,7 @@
}
});
loadText (path + animation + '.json', function (skeletonText) {
loadText(path + name + '.json', function (skeletonText) {
var json = new spine.SkeletonJson(new spine.AtlasAttachmentLoader(self.atlas));
json.scale = scale || 1;
@ -180,10 +170,8 @@
if (!(attachment instanceof spine.RegionAttachment)) continue;
var materials = attachment.rendererObject.page.rendererObject;
if (!materials) {
// texture was not loaded yet
continue;
}
if (!materials) continue;
if (slot.data.additiveBlending && (materials.length == 1)) {
// create separate material for additive blending
@ -213,15 +201,12 @@
attachment.regionOriginalWidth,
attachment.regionOriginalHeight
);
geometry.dynamic = true;
mesh = new THREE.Mesh(geometry, material);
material.meshes[slot.data.name] = mesh;
mesh.matrixAutoUpdate = false;
material.meshes[slot.data.name] = mesh;
this.add(mesh);
}
@ -287,88 +272,74 @@
}) ();
var scene, camera, renderer;
var geometry, material, mesh;
var anim;
var test;
function load (name, scale) {
if (anim) anim.dispose();
function load(animation, scale) {
if (test) {
test.dispose ();
}
anim = new SpineAnimation(name, 'data/', scale);
test = new SpineAnimation (animation, 'data/', scale);
test.addEventListener( SpineAnimation.SKELETON_DATA_LOADED, function () {
anim.addEventListener(SpineAnimation.SKELETON_DATA_LOADED, function () {
var canvas = renderer.domElement;
switch (test.name) {
switch (anim.name) {
case 'spineboy':
test.stateData.setMixByName('walk', 'jump', 0.2);
test.stateData.setMixByName('run', 'jump', 0.2);
test.stateData.setMixByName('jump', 'run', 0.2);
test.state.setAnimationByName(0, 'walk', true);
anim.stateData.setMixByName('walk', 'jump', 0.2);
anim.stateData.setMixByName('run', 'jump', 0.2);
anim.stateData.setMixByName('jump', 'run', 0.2);
anim.state.setAnimationByName(0, 'walk', true);
canvas.onmousedown = function () {
test.state.setAnimationByName(0, 'jump', false);
test.state.addAnimationByName(0, 'run', true, 0);
anim.state.setAnimationByName(0, 'jump', false);
anim.state.addAnimationByName(0, 'run', true, 0);
}
break;
case 'hero':
test.stateData.defaultMix = 0.2;
test.stateData.setMixByName('Walk', 'Attack', 0);
test.stateData.setMixByName('Attack', 'Run', 0);
test.stateData.setMixByName('Run', 'Attack', 0);
test.state.setAnimationByName(0, 'Idle', true);
anim.stateData.defaultMix = 0.2;
anim.stateData.setMixByName('Walk', 'Attack', 0);
anim.stateData.setMixByName('Attack', 'Run', 0);
anim.stateData.setMixByName('Run', 'Attack', 0);
anim.state.setAnimationByName(0, 'Idle', true);
canvas.onmousedown = function () {
var name = test.state.getCurrent(0).animation.name;
if (name == 'Idle') {
test.state.setAnimationByName(0, 'Crouch', true);
} else if (name == 'Crouch') {
test.state.setAnimationByName(0, 'Walk', true);
} else {
test.state.setAnimationByName(0, 'Attack', false);
test.state.addAnimationByName(0, 'Run', true, 0);
var name = anim.state.getCurrent(0).animation.name;
if (name == 'Idle')
anim.state.setAnimationByName(0, 'Crouch', true);
else if (name == 'Crouch')
anim.state.setAnimationByName(0, 'Walk', true);
else {
anim.state.setAnimationByName(0, 'Attack', false);
anim.state.addAnimationByName(0, 'Run', true, 0);
}
}
break;
case 'goblins':
test.skeleton.setSkinByName('goblingirl'); // TODO find why spine.Skeleton.prototype.setSkin does not work
test.skeleton.setSlotsToSetupPose();
test.state.setAnimationByName(0, 'walk', true);
anim.skeleton.setSkinByName('goblingirl'); // TODO - spine.Skeleton.prototype.setSkin doesn't work?
anim.skeleton.setSlotsToSetupPose();
anim.state.setAnimationByName(0, 'walk', true);
canvas.onmousedown = function () {
test.skeleton.setSkinByName(test.skeleton.skin.name == 'goblin' ? 'goblingirl' : 'goblin');
test.skeleton.setSlotsToSetupPose();
anim.skeleton.setSkinByName(anim.skeleton.skin.name == 'goblin' ? 'goblingirl' : 'goblin');
anim.skeleton.setSlotsToSetupPose();
}
break;
case 'skeleton':
test.state.setAnimationByName(0, 'walk test', true);
anim.state.setAnimationByName(0, 'walk test', true);
canvas.onmousedown = function () {
var name = test.state.getCurrent(0).animation.name;
if (name == 'walk test') {
test.state.setAnimationByName(0, 'idle test', true);
} else {
test.state.setAnimationByName(0, 'walk test', true);
}
var name = anim.state.getCurrent(0).animation.name;
if (name == 'walk test')
anim.state.setAnimationByName(0, 'idle test', true);
else
anim.state.setAnimationByName(0, 'walk test', true);
}
break;
}
//test.skeleton.y = -200;
//anim.skeleton.y = -200;
});
mesh.add( test );
mesh.add(anim);
}
init();
animate();
function init() {
spine.Bone.yDown = false;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 3000);
@ -386,11 +357,9 @@
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
}
function animate() {
requestAnimationFrame(animate);
var t = Date.now();
@ -400,14 +369,21 @@
mesh.rotation.x = a * Math.PI * 0.2;
mesh.rotation.y = b * Math.PI * 0.4;
test.update();
anim.update();
renderer.render(scene, camera);
}
init();
animate();
</script>
<br>
<input type="button" value="Spineboy" onclick="load('spineboy', 0.6)">
<input type="button" value="Hero" onclick="load('hero', 1)">
<input type="button" value="Goblins" onclick="load('goblins', 1)">
<input type="button" value="Gypsy" onclick="load('gypsy', 1)">
&nbsp; &nbsp; Click to change the animation or skin.
</body>
</html>

View File

@ -1 +0,0 @@
../../spine-js/spine.js