Skip to content

Commit

Permalink
Improve constraints on top system
Browse files Browse the repository at this point in the history
  • Loading branch information
milcktoast committed Aug 31, 2015
1 parent 2f1973d commit d544dea
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions static/js/items/Medusae.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Medusae(opts) {
this.totalSegments = this.segmentsCount * 3 * 3;

this.ribsCount = 20;
this.ribRadius = 25;
this.ribRadius = 15;

this.tentacleGroupStart = 0;
this.tentacleGroupOffset = 3;
Expand Down Expand Up @@ -113,9 +113,8 @@ Medusae.prototype.createCore = function () {
var verts = this.verts;
var uvs = this.uvs;
var segments = this.totalSegments;
// var ribsCount = this.ribsCount;
var size = this.size;
// var radius = this.ribRadius;
var yOffset = this.yOffset;
var offsets = [size, 0, -size * 2, size * 1.5, -size * 0.5, -size];

var topStart = this.topStart = offsets.length;
Expand All @@ -129,7 +128,7 @@ Medusae.prototype.createCore = function () {

var rangeTop = [0, size * 0.5];
var rangeMid = [size * 0.5, size * 0.7];
var rangeTopBottom = [size * 1.5, size * 2];
var rangeTopBottom = [size, size * 2];
var rangeBottom = [0, size * 0.5];

var spineA = DistanceConstraint.create(rangeTop, [pinTop, indexTop]);
Expand All @@ -143,6 +142,10 @@ Medusae.prototype.createCore = function () {
uvs.push(0, 0);
}

this.posTop = size + yOffset;
this.posMid = yOffset;
this.posBottom = -size + yOffset;

this.queueConstraints(spineA, spineB, spineC, spineD, axis);
FACES.radial(indexTop, topStart, segments, this.bulbFaces);
};
Expand All @@ -165,7 +168,7 @@ Medusae.prototype.createBulb = function () {
};

function ribRadius(t) {
return sin(PI - PI * 0.55 * t * 1.8) + log(t * 100 + 2) / 3 + 1;
return sin(PI - PI * 0.55 * t * 1.8) + log(t * 100 + 2) / 3;
}

function innerRibIndices(offset, start, segments, buffer) {
Expand Down Expand Up @@ -215,7 +218,7 @@ Medusae.prototype.createRib = function (index, total) {

var start = index * segments + this.topStart;
var radiusT = ribRadius(yParam);
var radius = radiusT * 10 + 0.5;
var radius = radiusT * this.ribRadius;

GEOM.circle(segments, radius, yPos, verts);
ribUvs(yParam, segments, uvs);
Expand All @@ -236,7 +239,7 @@ Medusae.prototype.createRib = function (index, total) {
if (isTop || isBottom) {
spineCenter = index === 0 ? this.indexTop : this.indexBottom;
radiusSpine = index === 0 ? radius * 1.25 : radius;
spine = DistanceConstraint.create([radius * 0.8, radiusSpine],
spine = DistanceConstraint.create([radius * 0.5, radiusSpine],
LINKS.radial(spineCenter, start, segments, []));

this.queueConstraints(spine);
Expand Down Expand Up @@ -619,8 +622,6 @@ Medusae.prototype.createSystem = function () {
var queuedConstraints = this.queuedConstraints;
var queuedWeights = this.weights;
var system = this.system = PTCL.ParticleSystem.create(this.verts, 2);
var size = this.size;
var yOffset = this.yOffset;

for (var i = 0, il = queuedConstraints.length; i < il; i ++) {
system.addConstraint(queuedConstraints[i]);
Expand All @@ -634,9 +635,9 @@ Medusae.prototype.createSystem = function () {
system.setWeight(1, 0);
system.setWeight(2, 0);

system.addPinConstraint(PointConstraint.create([0, size + yOffset, 0], 0));
system.addPinConstraint(PointConstraint.create([0, yOffset, 0], 1));
system.addPinConstraint(PointConstraint.create([0, -size + yOffset, 0], 2));
system.addPinConstraint(PointConstraint.create([0, this.posTop, 0], this.pinTop));
system.addPinConstraint(PointConstraint.create([0, this.posMid, 0], this.pinMid));
system.addPinConstraint(PointConstraint.create([0, this.posBottom, 0], this.pinBottom));
};

Medusae.prototype.relax = function (iterations) {
Expand Down

0 comments on commit d544dea

Please sign in to comment.