implemented rubedoll direction flip and added meshIndex (z) swapping capability. #151

This commit is contained in:
logsol 2015-04-29 00:04:17 +02:00
parent 0da744f5fd
commit a5f45ffef6
12 changed files with 483 additions and 389 deletions

View file

@ -5,6 +5,57 @@
"body" : "body" :
[ [
{
"angle" : 0,
"angularVelocity" : 0,
"awake" : true,
"fixture" :
[
{
"density" : 1,
"filter-groupIndex" : -55,
"friction" : 0.2,
"name" : "fixture2",
"polygon" :
{
"vertices" :
{
"x" :
[
0.1570904254913330,
0.1570904254913330,
-0.1156365871429443,
-0.1156365871429443
],
"y" :
[
-0.3584164977073669,
0.4034895300865173,
0.4034895300865173,
-0.3584164977073669
]
}
}
}
],
"linearVelocity" : 0,
"massData-I" : 0.01153474207967520,
"massData-center" :
{
"x" : 0.02072691917419434,
"y" : 0.02253651618957520
},
"massData-mass" : 0.2077923566102982,
"name" : "chest",
"position" :
{
"x" : -0.04104747623205185,
"y" : 0.7829875946044922
},
"type" : 2
},
{ {
"angle" : 0, "angle" : 0,
"angularVelocity" : 0, "angularVelocity" : 0,
@ -67,86 +118,42 @@
"density" : 1, "density" : 1,
"filter-groupIndex" : -55, "filter-groupIndex" : -55,
"friction" : 0.2, "friction" : 0.2,
"name" : "fixture0", "name" : "fixture3",
"polygon" : "polygon" :
{ {
"vertices" : "vertices" :
{ {
"x" : "x" :
[ [
0.1402979493141174, 0.07039496302604675,
0.1375417709350586, 0.07039496302604675,
0.001378186047077179, -0.07039486616849899,
-0.1402979493141174, -0.07039486616849899
-0.1402979493141174,
0.001192390918731689
], ],
"y" : "y" :
[ [
-0.3207050263881683, -0.09294389933347702,
0.4018019437789917, 0.1276105940341949,
0.4018019437789917, 0.1276105940341949,
0.3136067390441895, -0.09294389933347702
-0.3432337343692780,
-0.3689299821853638
] ]
} }
} }
} }
], ],
"linearVelocity" : 0, "linearVelocity" : 0,
"massData-I" : 0.01047351956367493, "massData-I" : 0.0001864957448560745,
"massData-center" : "massData-center" :
{ {
"x" : 0.001456731930375099, "x" : 4.842877032729120e-08,
"y" : 0.01425695233047009 "y" : 0.01733334921300411
}, },
"massData-mass" : 0.2038488984107971, "massData-mass" : 0.03105182945728302,
"name" : "chest", "name" : "lowerRightLeg",
"position" : "position" :
{ {
"x" : -0.04104747623205185, "x" : 0.02818956598639488,
"y" : 0.7829875946044922 "y" : 0.1036150008440018
},
"type" : 2
},
{
"angle" : 0,
"angularVelocity" : 0,
"awake" : true,
"fixture" :
[
{
"circle" :
{
"center" :
{
"x" : -0.002679032273590565,
"y" : 0.004700660705566406
},
"radius" : 0.2268356680870056
},
"density" : 0.2204959988594055,
"filter-groupIndex" : -55,
"friction" : 0.2,
"name" : "fixture1"
}
],
"linearVelocity" : 0,
"massData-I" : 0.0009180362685583532,
"massData-center" :
{
"x" : -0.002679032273590565,
"y" : 0.004700660705566406
},
"massData-mass" : 0.03564291819930077,
"name" : "head",
"position" :
{
"x" : 0.009572610259056091,
"y" : 1.462979435920715
}, },
"type" : 2 "type" : 2
}, },
@ -169,35 +176,35 @@
{ {
"x" : "x" :
[ [
0.04693000018596649, 0.07039505988359451,
0.04693000018596649, 0.07039505988359451,
-0.04693005979061127, -0.07039495557546616,
-0.04693005979061127 -0.07039495557546616
], ],
"y" : "y" :
[ [
-0.1159216761589050, -0.1890522241592407,
0.1159217953681946, 0.1890524625778198,
0.1159217953681946, 0.1890524625778198,
-0.1159216761589050 -0.1890522241592407
] ]
} }
} }
} }
], ],
"linearVelocity" : 0, "linearVelocity" : 0,
"massData-I" : 0.0001134485355578363, "massData-I" : 0.000722132739610970,
"massData-center" : "massData-center" :
{ {
"x" : -2.980232238769531e-08, "x" : 5.215406417846680e-08,
"y" : 5.960464477539062e-08 "y" : 1.192092824453539e-07
}, },
"massData-mass" : 0.02176084183156490, "massData-mass" : 0.05323336645960808,
"name" : "lowerRightArm", "name" : "upperLeftLeg",
"position" : "position" :
{ {
"x" : 0.09864036738872528, "x" : -0.06537666171789169,
"y" : 0.6898344159126282 "y" : 0.3381301760673523
}, },
"type" : 2 "type" : 2
}, },
@ -304,57 +311,6 @@
"type" : 2 "type" : 2
}, },
{
"angle" : 0,
"angularVelocity" : 0,
"awake" : true,
"fixture" :
[
{
"density" : 1,
"filter-groupIndex" : -55,
"friction" : 0.2,
"name" : "fixture3",
"polygon" :
{
"vertices" :
{
"x" :
[
0.04693000018596649,
0.04693000018596649,
-0.04693005979061127,
-0.04693005979061127
],
"y" :
[
-0.1895973682403564,
0.1895966529846191,
0.1895966529846191,
-0.1895973682403564
]
}
}
}
],
"linearVelocity" : 0,
"massData-I" : 0.0004525946278590709,
"massData-center" :
{
"x" : -2.980232238769531e-08,
"y" : -3.576278686523438e-07
},
"massData-mass" : 0.03559117391705513,
"name" : "upperRightArm",
"position" :
{
"x" : 0.09864036738872528,
"y" : 0.9068759679794312
},
"type" : 2
},
{ {
"angle" : 0, "angle" : 0,
"angularVelocity" : 0, "angularVelocity" : 0,
@ -424,35 +380,35 @@
{ {
"x" : "x" :
[ [
0.07039505988359451, 0.04693000018596649,
0.07039505988359451, 0.04693000018596649,
-0.07039495557546616, -0.04693005979061127,
-0.07039495557546616 -0.04693005979061127
], ],
"y" : "y" :
[ [
-0.1890522241592407, -0.1895973682403564,
0.1890524625778198, 0.1895966529846191,
0.1890524625778198, 0.1895966529846191,
-0.1890522241592407 -0.1895973682403564
] ]
} }
} }
} }
], ],
"linearVelocity" : 0, "linearVelocity" : 0,
"massData-I" : 0.000722132739610970, "massData-I" : 0.0004525946278590709,
"massData-center" : "massData-center" :
{ {
"x" : 5.215406417846680e-08, "x" : -2.980232238769531e-08,
"y" : 1.192092824453539e-07 "y" : -3.576278686523438e-07
}, },
"massData-mass" : 0.05323336645960808, "massData-mass" : 0.03559117391705513,
"name" : "upperLeftLeg", "name" : "upperRightArm",
"position" : "position" :
{ {
"x" : -0.06537666171789169, "x" : 0.09864036738872528,
"y" : 0.3381301760673523 "y" : 0.9068759679794312
}, },
"type" : 2 "type" : 2
}, },
@ -475,35 +431,75 @@
{ {
"x" : "x" :
[ [
0.07039496302604675, 0.04693000018596649,
0.07039496302604675, 0.04693000018596649,
-0.07039486616849899, -0.04693005979061127,
-0.07039486616849899 -0.04693005979061127
], ],
"y" : "y" :
[ [
-0.09294389933347702, -0.1159216761589050,
0.1276105940341949, 0.1159217953681946,
0.1276105940341949, 0.1159217953681946,
-0.09294389933347702 -0.1159216761589050
] ]
} }
} }
} }
], ],
"linearVelocity" : 0, "linearVelocity" : 0,
"massData-I" : 0.0001864957448560745, "massData-I" : 0.0001134485355578363,
"massData-center" : "massData-center" :
{ {
"x" : 4.842877032729120e-08, "x" : -2.980232238769531e-08,
"y" : 0.01733334921300411 "y" : 5.960464477539062e-08
}, },
"massData-mass" : 0.03105182945728302, "massData-mass" : 0.02176084183156490,
"name" : "lowerRightLeg", "name" : "lowerRightArm",
"position" : "position" :
{ {
"x" : 0.02818956598639488, "x" : 0.09864036738872528,
"y" : 0.1036150008440018 "y" : 0.6898344159126282
},
"type" : 2
},
{
"angle" : 0,
"angularVelocity" : 0,
"awake" : true,
"fixture" :
[
{
"circle" :
{
"center" :
{
"x" : -0.01561669446527958,
"y" : 0.004700659774243832
},
"radius" : 0.2268356680870056
},
"density" : 0.2204959988594055,
"filter-groupIndex" : -55,
"friction" : 0.2,
"name" : "fixture1"
}
],
"linearVelocity" : 0,
"massData-I" : 0.0009264730615541339,
"massData-center" :
{
"x" : -0.01561669446527958,
"y" : 0.004700659774243832
},
"massData-mass" : 0.03564291819930077,
"name" : "head",
"position" :
{
"x" : 0.009572610259056091,
"y" : 1.462979435920715
}, },
"type" : 2 "type" : 2
} }
@ -555,181 +551,6 @@
"joint" : "joint" :
[ [
{
"anchorA" :
{
"x" : 0.06392270326614380,
"y" : 0.4330990314483643
},
"anchorB" :
{
"x" : 0.01330260001122952,
"y" : -0.2468919754028320
},
"bodyA" : 1,
"bodyB" : 2,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -0.6981316804885864,
"maxMotorTorque" : 0,
"motorSpeed" : 0,
"name" : "joint9",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 1.221730470657349
},
{
"anchorA" :
{
"x" : 0.0008554458618164062,
"y" : -0.1461489200592041
},
"anchorB" :
{
"x" : 0.0008557140827178955,
"y" : 0.07089227437973022
},
"bodyA" : 0,
"bodyB" : 5,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -1.919862151145935,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint4",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 0.01745329238474369
},
{
"anchorA" :
{
"x" : 0.0003538504242897034,
"y" : 0.07107692956924438
},
"anchorB" :
{
"x" : 0.0003536641597747803,
"y" : -0.1459646224975586
},
"bodyA" : 3,
"bodyB" : 6,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -1.919862151145935,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint1",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 0.01745329238474369
},
{
"anchorA" :
{
"x" : 0.001979876309633255,
"y" : -0.1506856828927994
},
"anchorB" :
{
"x" : 0.001979988068342209,
"y" : 0.08382888138294220
},
"bodyA" : 7,
"bodyB" : 9,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : 0.01745329238474369,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint8",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 2.268928050994873
},
{
"anchorA" :
{
"x" : -0.0007802918553352356,
"y" : -0.1484908312559128
},
"anchorB" :
{
"x" : -0.0007800981402397156,
"y" : 0.08614097535610199
},
"bodyA" : 8,
"bodyB" : 4,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : 0.01745329238474369,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint7",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 2.268928050994873
},
{
"anchorA" :
{
"x" : -0.09517393261194229,
"y" : 0.2718780040740967
},
"anchorB" :
{
"x" : -1.741945743560791e-05,
"y" : 0.1479903459548950
},
"bodyA" : 1,
"bodyB" : 0,
"enableLimit" : false,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -2.268928050994873,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint3",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 3.141592741012573
},
{
"anchorA" :
{
"x" : 0.1396137326955795,
"y" : 0.2701327800750732
},
"anchorB" :
{
"x" : -7.455050945281982e-05,
"y" : 0.1462446451187134
},
"bodyA" : 1,
"bodyB" : 6,
"enableLimit" : false,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -2.268928050994873,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint2",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 3.141592741012573
},
{ {
"anchorA" : "anchorA" :
{ {
@ -741,8 +562,8 @@
"x" : -0.04493143409490585, "x" : -0.04493143409490585,
"y" : 0.1559127867221832 "y" : 0.1559127867221832
}, },
"bodyA" : 1, "bodyA" : 0,
"bodyB" : 8, "bodyB" : 3,
"enableLimit" : true, "enableLimit" : true,
"enableMotor" : false, "enableMotor" : false,
"jointSpeed" : 0, "jointSpeed" : 0,
@ -766,8 +587,8 @@
"x" : 0.04127830639481544, "x" : 0.04127830639481544,
"y" : 0.1504460573196411 "y" : 0.1504460573196411
}, },
"bodyA" : 1, "bodyA" : 0,
"bodyB" : 7, "bodyB" : 6,
"enableLimit" : true, "enableLimit" : true,
"enableMotor" : false, "enableMotor" : false,
"jointSpeed" : 0, "jointSpeed" : 0,
@ -778,6 +599,181 @@
"refAngle" : 0, "refAngle" : 0,
"type" : "revolute", "type" : "revolute",
"upperLimit" : 1.919862151145935 "upperLimit" : 1.919862151145935
},
{
"anchorA" :
{
"x" : -0.0007802918553352356,
"y" : -0.1484908312559128
},
"anchorB" :
{
"x" : -0.0007800981402397156,
"y" : 0.08614097535610199
},
"bodyA" : 3,
"bodyB" : 4,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : 0.01745329238474369,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint7",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 2.268928050994873
},
{
"anchorA" :
{
"x" : 0.001979876309633255,
"y" : -0.1506856828927994
},
"anchorB" :
{
"x" : 0.001979988068342209,
"y" : 0.08382888138294220
},
"bodyA" : 6,
"bodyB" : 2,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : 0.01745329238474369,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint8",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 2.268928050994873
},
{
"anchorA" :
{
"x" : 0.0003538504242897034,
"y" : 0.07107692956924438
},
"anchorB" :
{
"x" : 0.0003536641597747803,
"y" : -0.1459646224975586
},
"bodyA" : 8,
"bodyB" : 7,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -1.919862151145935,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint1",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 0
},
{
"anchorA" :
{
"x" : 0.06392270326614380,
"y" : 0.4330990314483643
},
"anchorB" :
{
"x" : 0.01330260001122952,
"y" : -0.2468919754028320
},
"bodyA" : 0,
"bodyB" : 9,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -0.6981316804885864,
"maxMotorTorque" : 0,
"motorSpeed" : 0,
"name" : "joint9",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 1.221730470657349
},
{
"anchorA" :
{
"x" : 0.1396137326955795,
"y" : 0.2701327800750732
},
"anchorB" :
{
"x" : -7.455050945281982e-05,
"y" : 0.1462446451187134
},
"bodyA" : 0,
"bodyB" : 7,
"enableLimit" : false,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -2.268928050994873,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint2",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 3.141592741012573
},
{
"anchorA" :
{
"x" : -0.09517393261194229,
"y" : 0.2718780040740967
},
"anchorB" :
{
"x" : -1.741945743560791e-05,
"y" : 0.1479903459548950
},
"bodyA" : 0,
"bodyB" : 1,
"enableLimit" : false,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -2.268928050994873,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint3",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 3.141592741012573
},
{
"anchorA" :
{
"x" : 0.0008554458618164062,
"y" : -0.1461489200592041
},
"anchorB" :
{
"x" : 0.0008557140827178955,
"y" : 0.07089227437973022
},
"bodyA" : 1,
"bodyB" : 5,
"enableLimit" : true,
"enableMotor" : false,
"jointSpeed" : 0,
"lowerLimit" : -1.919862151145935,
"maxMotorTorque" : 1,
"motorSpeed" : 0,
"name" : "joint4",
"refAngle" : 0,
"type" : "revolute",
"upperLimit" : 0.01745329238474369
} }
], ],
"positionIterations" : 3, "positionIterations" : 3,

View file

@ -9,10 +9,10 @@ define([
"Game/Channel/Player", "Game/Channel/Player",
"Game/Channel/GameObjects/GameObject", "Game/Channel/GameObjects/GameObject",
"Game/Channel/GameObjects/Doll", "Game/Channel/GameObjects/Doll",
"Game/Channel/GameObjects/Items/RagDoll" "Game/Channel/GameObjects/Items/RubeDoll"
], ],
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RagDoll) { function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, Nc, Box2D, Player, GameObject, Doll, RubeDoll) {
"use strict"; "use strict";
@ -172,7 +172,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
var objects = []; var objects = [];
for (var i = 0; i < this.gameObjects.animated.length; i++) { for (var i = 0; i < this.gameObjects.animated.length; i++) {
if(this.gameObjects.animated[i] instanceof RagDoll) { if(this.gameObjects.animated[i] instanceof RubeDoll) {
var object = this.gameObjects.animated[i]; var object = this.gameObjects.animated[i];
var options = object.options; var options = object.options;
options.x = object.getPosition().x; options.x = object.getPosition().x;

View file

@ -9,11 +9,21 @@ function (Parent, Settings, Nc) {
"use strict"; "use strict";
function RubeDoll(physicsEngine, uid, options) { function RubeDoll(physicsEngine, uid, options) {
this.scheduledForDestruction = false;
this.destructionTimeout = null;
Parent.call(this, physicsEngine, uid, options); Parent.call(this, physicsEngine, uid, options);
} }
RubeDoll.prototype = Object.create(Parent.prototype); RubeDoll.prototype = Object.create(Parent.prototype);
RubeDoll.prototype.beingGrabbed = function(player) {
Parent.prototype.beingGrabbed.call(this, player);
if(this.scheduledForDestruction) {
clearTimeout(this.destructionTimeout);
}
};
RubeDoll.prototype.beingReleased = function(player) { RubeDoll.prototype.beingReleased = function(player) {
Parent.prototype.beingReleased.call(this, player); Parent.prototype.beingReleased.call(this, player);
if(this.scheduledForDestruction) { if(this.scheduledForDestruction) {

View file

@ -93,6 +93,7 @@ function (Parent, Layer, Settings, Nc) {
this.limbMeshes = {}; this.limbMeshes = {};
this.baseMeshName = "chest"; this.baseMeshName = "chest";
this.characterName = "Chuck"; this.characterName = "Chuck";
this.lastFlipDirection = 1;
Parent.call(this, physicsEngine, uid, options); Parent.call(this, physicsEngine, uid, options);
} }
@ -101,10 +102,8 @@ function (Parent, Layer, Settings, Nc) {
RubeDoll.prototype.createMesh = function() { RubeDoll.prototype.createMesh = function() {
this.createLimbMesh("lowerRightLeg"); this.createLimbMesh("lowerRightLeg");
this.createLimbMesh("upperRightLeg"); this.createLimbMesh("upperRightLeg");
this.createLimbMesh("lowerRightArm"); this.createLimbMesh("lowerRightArm");
this.createLimbMesh("upperRightArm"); this.createLimbMesh("upperRightArm");
@ -113,7 +112,6 @@ function (Parent, Layer, Settings, Nc) {
this.createLimbMesh("lowerLeftLeg"); this.createLimbMesh("lowerLeftLeg");
this.createLimbMesh("upperLeftLeg"); this.createLimbMesh("upperLeftLeg");
this.createLimbMesh("lowerLeftArm"); this.createLimbMesh("lowerLeftArm");
this.createLimbMesh("upperLeftArm"); this.createLimbMesh("upperLeftArm");
@ -187,6 +185,48 @@ function (Parent, Layer, Settings, Nc) {
}; };
RubeDoll.prototype.flip = function(direction) { RubeDoll.prototype.flip = function(direction) {
Parent.prototype.flip.call(this, direction);
if(this.limbs) {
for(var name in this.limbMeshes) {
if(this.limbs[name]) {
Nc.trigger(Nc.ns.client.view.mesh.update,
this.layerId,
this.limbMeshes[name],
{
xScale: direction,
}
);
}
}
}
// flipping depth of right body side arm/leg images with left
if (this.lastFlipDirection != direction) {
this.lastFlipDirection = direction;
Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes,
this.layerId,
this.limbMeshes["lowerRightLeg"],
this.limbMeshes["lowerLeftLeg"]
);
Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes,
this.layerId,
this.limbMeshes["upperRightLeg"],
this.limbMeshes["upperLeftLeg"]
);
Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes,
this.layerId,
this.limbMeshes["lowerRightArm"],
this.limbMeshes["lowerLeftArm"]
);
Nc.trigger(Nc.ns.client.view.mesh.swapMeshIndexes,
this.layerId,
this.limbMeshes["upperRightArm"],
this.limbMeshes["upperLeftArm"]
);
}
}; };
return RubeDoll; return RubeDoll;

View file

@ -20,7 +20,8 @@ function (Nc, Exception, Layer) {
Nc.on(Nc.ns.client.view.mesh.remove, this.removeMesh, this), Nc.on(Nc.ns.client.view.mesh.remove, this.removeMesh, this),
Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this), Nc.on(Nc.ns.client.view.mesh.update, this.updateMesh, this),
Nc.on(Nc.ns.client.view.mesh.addFilter, this.addFilter, this), Nc.on(Nc.ns.client.view.mesh.addFilter, this.addFilter, this),
Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this) Nc.on(Nc.ns.client.view.mesh.removeFilter, this.removeFilter, this),
Nc.on(Nc.ns.client.view.mesh.swapMeshIndexes, this.swapMeshIndexes, this)
]; ];
} }
@ -157,6 +158,11 @@ function (Nc, Exception, Layer) {
this.delegate.apply(this, arguments); this.delegate.apply(this, arguments);
}; };
LayerManager.prototype.swapMeshIndexes = function() {
Array.prototype.splice.call(arguments, 0, 0, 'swapMeshIndexes')
this.delegate.apply(this, arguments);
};
LayerManager.prototype.destroy = function() { LayerManager.prototype.destroy = function() {
for (var i = 0; i < this.ncTokens.length; i++) { for (var i = 0; i < this.ncTokens.length; i++) {
Nc.off(this.ncTokens[i]); Nc.off(this.ncTokens[i]);

View file

@ -95,6 +95,14 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter, Nc) {
this.container.removeChild(mesh); this.container.removeChild(mesh);
}; };
Layer.prototype.swapMeshIndexes = function(meshA, meshB) {
var indexA = this.container.getChildIndex(meshA);
var indexB = this.container.getChildIndex(meshB);
this.container.setChildIndex(meshA, indexB);
this.container.setChildIndex(meshB, indexA);
};
Layer.prototype.createMesh = function (texturePath, callback, options) { Layer.prototype.createMesh = function (texturePath, callback, options) {
var texture = (options && options.fromFrame) var texture = (options && options.fromFrame)

View file

@ -40,7 +40,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc, Asser
this.holdingJoint = null; this.holdingJoint = null;
this.holdingItem = null; this.holdingItem = null;
this.ragDoll = {head: null, body: null}; this.ragDoll = {head: null, body: null}; // FIXME: wtf is this? can we remove it?
this.createFixtures(); this.createFixtures();
this.body.SetActive(false); this.body.SetActive(false);

View file

@ -18,10 +18,27 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
this.rubeLoader = null; this.rubeLoader = null;
this.body = null; this.body = null;
this.limbs = {}; this.limbs = {};
this.joints = null;
this.limits = [];
var chest = null; var chest = null;
var world = physicsEngine.getWorld(); var world = physicsEngine.getWorld();
this.rubeLoader = new RubeLoader(RubeDollJson, world); this.rubeLoader = new RubeLoader(RubeDollJson, world);
this.loadRubeDollFromScene(options);
Parent.call(this, physicsEngine, uid, options);
world.DestroyBody(this.body);
this.body = this.limbs.chest;
this.body.SetUserData(this);
this.flip(options.direction);
}
RubeDoll.prototype = Object.create(Parent.prototype);
RubeDoll.prototype.loadRubeDollFromScene = function(options) {
var scene = this.rubeLoader.getScene(); var scene = this.rubeLoader.getScene();
for (var i in scene.bodies) { for (var i in scene.bodies) {
@ -35,19 +52,17 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
this.limbs[body.name] = body; this.limbs[body.name] = body;
} }
Parent.call(this, physicsEngine, uid, options); this.joints = scene.joints;
world.DestroyBody(this.body);
this.body = this.limbs.chest;
var def = this.body.GetDefinition(); for (var i in this.joints) {
def.userData = this; this.limits[i] = {
this.body.SetUserData(this); lower: this.joints[i].GetLowerLimit(),
} upper: this.joints[i].GetUpperLimit(),
};
RubeDoll.prototype = Object.create(Parent.prototype); }
};
RubeDoll.prototype.getFixtureDef = function() { RubeDoll.prototype.getFixtureDef = function() {
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape(); fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape();
return fixtureDef; return fixtureDef;
@ -55,7 +70,28 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
RubeDoll.prototype.flip = function(direction) { RubeDoll.prototype.flip = function(direction) {
Parent.prototype.flip.call(this, direction); Parent.prototype.flip.call(this, direction);
// Extend
for (var i in this.joints) {
var joint = this.joints[i];
var limits = this.limits[i];
if (joint instanceof Box2D.Dynamics.Joints.b2RevoluteJoint) {
if (direction > 0) {
joint.SetLimits(limits.lower, limits.upper);
continue;
}
var a1 = limits.lower * -1;
var a2 = limits.upper * -1;
if (a2 > a1) {
joint.SetLimits(a1, a2);
} else {
joint.SetLimits(a2, a1);
}
}
}
}; };
RubeDoll.prototype.reposition = function(handPosition, direction) { RubeDoll.prototype.reposition = function(handPosition, direction) {

View file

@ -129,22 +129,23 @@ function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll
image: "chest.png", image: "chest.png",
name: "RagDoll", name: "RagDoll",
rotation: 0, rotation: 0,
type: "ragdoll", type: "rubedoll",
weight: 3, weight: 3,
width: 5, width: 5,
height: 12, height: 12,
primaryColor: primaryColor primaryColor: primaryColor,
direction: this.doll.lookDirection
}; };
var ragDoll = new RubeDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options); var rubeDoll = new RubeDoll(this.physicsEngine, "rubeDoll-" + this.id + "-" + ragDollId, options);
ragDoll.setVelocities(this.doll.getVelocities()); rubeDoll.setVelocities(this.doll.getVelocities());
this.spawned = false; this.spawned = false;
this.doll.destroy(); this.doll.destroy();
this.doll = null; this.doll = null;
this.ragDoll = ragDoll; this.ragDoll = rubeDoll;
}; };
Player.prototype.update = function () { Player.prototype.update = function () {

View file

@ -41,7 +41,8 @@ function (Exception) {
remove: null, remove: null,
update: null, update: null,
addFilter: null, addFilter: null,
removeFilter: null removeFilter: null,
swapMeshIndexes: null
}, },
animatedMesh: { animatedMesh: {
create: null create: null

View file

@ -426,7 +426,7 @@ function (Box2D) {
var scene = { var scene = {
bodies: loadedBodies, bodies: loadedBodies,
// joints: loadedJoints joints: loadedJoints
}; };
return scene; return scene;

View file

@ -482,18 +482,18 @@
], ],
"vertices" : "vertices" :
{ {
"x" : [ -0.002679032273590565 ], "x" : [ -0.01561669446527958 ],
"y" : [ 0.004700660705566406 ] "y" : [ 0.004700659774243832 ]
} }
} }
], ],
"id" : 8, "id" : 8,
"linearVelocity" : 0, "linearVelocity" : 0,
"massData-I" : 0.0009180362685583532, "massData-I" : 0.0009264730615541339,
"massData-center" : "massData-center" :
{ {
"x" : -0.002679032273590565, "x" : -0.01561669446527958,
"y" : 0.004700660705566406 "y" : 0.004700659774243832
}, },
"massData-mass" : 0.03564291819930077, "massData-mass" : 0.03564291819930077,
"name" : "head", "name" : "head",
@ -516,8 +516,8 @@
"density" : 1, "density" : 1,
"filter-groupIndex" : -55, "filter-groupIndex" : -55,
"friction" : 0.2, "friction" : 0.2,
"id" : 13, "id" : 11,
"name" : "fixture0", "name" : "fixture2",
"shapes" : "shapes" :
[ [
@ -529,34 +529,30 @@
{ {
"x" : "x" :
[ [
0.1402979493141174, -0.1156365871429443,
0.1375417709350586, 0.1570904254913330,
0.001378186047077179, 0.1570904254913330,
-0.1402979493141174, -0.1156365871429443
-0.1402979493141174,
0.001192390918731689
], ],
"y" : "y" :
[ [
-0.3207050263881683, -0.3584164977073669,
0.4018019437789917, -0.3584164977073669,
0.4018019437789917, 0.4034895300865173,
0.3136067390441895, 0.4034895300865173
-0.3432337343692780,
-0.3689299821853638
] ]
} }
} }
], ],
"id" : 9, "id" : 9,
"linearVelocity" : 0, "linearVelocity" : 0,
"massData-I" : 0.01047351956367493, "massData-I" : 0.01153474207967520,
"massData-center" : "massData-center" :
{ {
"x" : 0.001456731930375099, "x" : 0.02072691917419434,
"y" : 0.01425695233047009 "y" : 0.02253651618957520
}, },
"massData-mass" : 0.2038488984107971, "massData-mass" : 0.2077923566102982,
"name" : "chest", "name" : "chest",
"position" : "position" :
{ {
@ -701,7 +697,7 @@
"name" : "joint1", "name" : "joint1",
"referenceAngle" : 0, "referenceAngle" : 0,
"type" : "revolute", "type" : "revolute",
"upperLimit" : 0.01745329238474369 "upperLimit" : 0
}, },
{ {
@ -747,13 +743,13 @@
"enableLimit" : true, "enableLimit" : true,
"enableMotor" : false, "enableMotor" : false,
"id" : 5, "id" : 5,
"lowerLimit" : -0.6981316804885864, "lowerLimit" : -0.7853981852531433,
"maxMotorTorque" : 1, "maxMotorTorque" : 1,
"motorSpeed" : 0, "motorSpeed" : 0,
"name" : "joint6", "name" : "joint6",
"referenceAngle" : 0, "referenceAngle" : 0,
"type" : "revolute", "type" : "revolute",
"upperLimit" : 1.919862151145935 "upperLimit" : 1.570796370506287
}, },
{ {
@ -773,13 +769,13 @@
"enableLimit" : true, "enableLimit" : true,
"enableMotor" : false, "enableMotor" : false,
"id" : 6, "id" : 6,
"lowerLimit" : -0.6981316804885864, "lowerLimit" : -0.7853981852531433,
"maxMotorTorque" : 1, "maxMotorTorque" : 1,
"motorSpeed" : 0, "motorSpeed" : 0,
"name" : "joint5", "name" : "joint5",
"referenceAngle" : 0, "referenceAngle" : 0,
"type" : "revolute", "type" : "revolute",
"upperLimit" : 1.919862151145935 "upperLimit" : 1.570796370506287
}, },
{ {