Tidied up per Brad's request

This commit is contained in:
Bing Shearer 2015-07-27 10:19:42 -07:00
parent 3cac781cdc
commit d54543e83c

View file

@ -14,14 +14,22 @@ var leafSquall = function (properties) {
squallOrigin,
squallRadius,
leavesPerMinute = 60,
leafSize = { x: 0.1, y: 0.1, z: 0.1 },
leafSize = {
x: 0.1,
y: 0.1,
z: 0.1
},
leafFallSpeed = 1, // m/s
leafLifetime = 60, // Seconds
leafSpinMax = 0, // Maximum angular velocity per axis; deg/s
debug = false, // Display origin circle; don't use running on Stack Manager
// Other
squallCircle,
SQUALL_CIRCLE_COLOR = { red: 255, green: 0, blue: 0 },
SQUALL_CIRCLE_COLOR = {
red: 255,
green: 0,
blue: 0
},
SQUALL_CIRCLE_ALPHA = 0.5,
SQUALL_CIRCLE_ROTATION = Quat.fromPitchYawRollDegrees(90, 0, 0),
leafProperties,
@ -92,8 +100,7 @@ var leafSquall = function (properties) {
}
if (properties.hasOwnProperty("windFactor")) {
windFactor = properties.windFactor;
}
else {
} else {
print("ERROR: Wind Factor must be defined for complex movement")
}
@ -103,7 +110,11 @@ var leafSquall = function (properties) {
modelURL: leaf_MODEL_URL,
lifetime: leafLifetime,
dimensions: leafSize,
velocity: { x: 0, y: -leafFallSpeed, z: 0 },
velocity: {
x: 0,
y: -leafFallSpeed,
z: 0
},
damping: 0,
angularDamping: 0,
ignoreForCollisions: true
@ -116,17 +127,25 @@ var leafSquall = function (properties) {
radius,
offset,
leaf,
spin = { x: 0, y: 0, z: 0 },
spin = {
x: 0,
y: 0,
z: 0
},
i;
// HACK: Work around leaves not always getting velocities set at creation
for (i = 0; i < leaves.length; i += 1) {
for (i = 0; i < leaves.length; i++) {
Entities.editEntity(leaves[i], leafVelocities[i]);
}
angle = Math.random() * 10;
angle = Math.random() * leafSpinMax;
radius = Math.random() * squallRadius;
offset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, angle, 0), { x: 0, y: -0.1, z: radius });
offset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, angle, 0), {
x: 0,
y: -0.1,
z: radius
});
leafProperties.position = Vec3.sum(squallOrigin, offset);
if (properties.leafSpinMax > 0 && !complexMovement) {
spin = {
@ -135,9 +154,12 @@ var leafSquall = function (properties) {
z: Math.random() * maxSpinRadians
};
leafProperties.angularVelocity = spin;
}
else if (complexMovement) {
spin = { x: 0, y: 0, z: 0 };
} else if (complexMovement) {
spin = {
x: 0,
y: 0,
z: 0
};
leafProperties.angularVelocity = spin
}
leaf = Entities.addEntity(leafProperties);
@ -157,7 +179,10 @@ var leafSquall = function (properties) {
function setUp() {
if (debug) {
squallCircle = Overlays.addOverlay("circle3d", {
size: { x: 2 * squallRadius, y: 2 * squallRadius },
size: {
x: 2 * squallRadius,
y: 2 * squallRadius
},
color: SQUALL_CIRCLE_COLOR,
alpha: SQUALL_CIRCLE_ALPHA,
solid: true,
@ -195,7 +220,11 @@ var leafSquall = function (properties) {
if (complexMovement && leafHeight > floorHeight || complexMovement && floorHeight == null) { //actual new movement code;
var leafCurrentVel = entityProperties.velocity,
leafCurrentRot = entityProperties.rotation,
yVec = { x: 0, y: 1, z: 0 },
yVec = {
x: 0,
y: 1,
z: 0
},
leafYinWFVec = Vec3.multiplyQbyV(leafCurrentRot, yVec),
leafLocalHorVec = Vec3.cross(leafYinWFVec, yVec),
leafMostDownVec = Vec3.cross(leafYinWFVec, leafLocalHorVec),
@ -206,16 +235,22 @@ var leafSquall = function (properties) {
angularVelocity: randomRotationSpeed,
velocity: leafNewVel
})
}
else if (leafHeight <= floorHeight) {
} else if (leafHeight <= floorHeight) {
if (!leafDeleteOnGround) {
Entities.editEntity(nearbyEntities[i], {
locked: false,
velocity: { x: 0, y: 0, z: 0 },
angularVelocity: { x: 0, y: 0, z: 0 }
})
velocity: {
x: 0,
y: 0,
z: 0
},
angularVelocity: {
x: 0,
y: 0,
z: 0
}
else {
})
} else {
Entity.deleteEntity(currentLeaf);
}
}
@ -264,15 +299,22 @@ var leafSquall = function (properties) {
setUp();
Script.scriptEnding.connect(tearDown);
return {
};
return {};
};
var leafSquall1 = new leafSquall({
origin: { x: 3071.5, y: 2170, z: 6765.3 },
origin: {
x: 3071.5,
y: 2170,
z: 6765.3
},
radius: 100,
leavesPerMinute: 30,
leafSize: { x: 0.3, y: 0.00, z: 0.3},
leafSize: {
x: 0.3,
y: 0.00,
z: 0.3
},
leafFallSpeed: 0.4,
leafLifetime: 100,
leafSpinMax: 30,