Skip to content

Commit

Permalink
Add tentacles
Browse files Browse the repository at this point in the history
  • Loading branch information
milcktoast committed Nov 16, 2014
1 parent ede0526 commit 01d4981
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions static/js/items/Medusae.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function Medusae(opts) {

this.segments = 3 * 9;
this.ribsCount = 20;
this.tentacleSegments = 100;
this.tentacleSegmentLength = 1;
this.tailCount = 10;
this.tailSegments = 50;
this.size = 20;
Expand All @@ -40,6 +42,7 @@ function Medusae(opts) {
this.uvs = [];

this.ribs = [];
this.tentacles = [];
this.skins = [];

this.item = new THREE.Object3D();
Expand All @@ -53,6 +56,7 @@ Medusae.create = App.ctor(Medusae);

Medusae.prototype.createGeometry = function () {
var ribsCount = this.ribsCount;
var tentacleSegments = this.tentacleSegments;
var tailCount = this.tailCount;
var i, il;

Expand All @@ -65,6 +69,15 @@ Medusae.prototype.createGeometry = function () {
}
}

for (i = 0, il = tentacleSegments; i < il; i ++) {
this.createTentacleSegment(i, tentacleSegments);
if (i > 0) {
this.linkTentacle(i - 1, i);
} else {
this.attachTentacles();
}
}

for (i = 0, il = tailCount; i < il; i ++) {
this.createTail(i, tailCount);
}
Expand Down Expand Up @@ -209,6 +222,56 @@ Medusae.prototype.createSkin = function (r0, r1) {
});
};

function tentacleUvs(howMany, buffer) {
for (var i = 0, il = howMany; i < il; i ++) {
buffer.push(0, 0);
}
return buffer;
}

Medusae.prototype.createTentacleSegment = function (index, total) {
var segments = this.segments;
var verts = this.verts;
var uvs = this.uvs;

var radius = 10;
var yPos = - index * this.tentacleSegmentLength;
var start = verts.length / 3;

GEOM.circle(segments, radius, yPos, verts);
tentacleUvs(segments, uvs);

this.tentacles.push({
start : start
});
};

Medusae.prototype.attachTentacles = function () {
var segments = this.segments;
var rib = this.ribs[this.ribs.length - 1];
var tent = this.tentacles[0];
var dist = this.tentacleSegmentLength;

var tentacle = DistanceConstraint.create([dist * 0.5, dist],
LINKS.rings(rib.start, tent.start, segments, []));

this.queueConstraints(tentacle);
this.addLinks(tentacle.indices);
};

Medusae.prototype.linkTentacle = function (i0, i1) {
var segments = this.segments;
var tent0 = this.tentacles[i0];
var tent1 = this.tentacles[i1];
var dist = this.tentacleSegmentLength;

var tentacle = DistanceConstraint.create([dist * 0.5, dist],
LINKS.rings(tent0.start, tent1.start, segments, []));

this.queueConstraints(tentacle);
this.addLinks(tentacle.indices);
};

Medusae.prototype.createTail = function (index, total) {
var size = this.size;
var segments = this.tailSegments;
Expand Down

0 comments on commit 01d4981

Please sign in to comment.