Commit d9d110ec authored by amandaghassaei's avatar amandaghassaei

2.5d version

parent 2b381d61
......@@ -579,11 +579,11 @@ define(['underscore', 'appState', 'three'], function(_, appState, THREE){
};
DMAMaterial.prototype.getBendingK = function(){
return this.properties.bendingK;
return new THREE.Vector3(this.properties.bendingK.x, this.properties.bendingK.y, this.properties.bendingK.z);
};
DMAMaterial.prototype.getTorsionK = function(){
return this.properties.torsionK;
return new THREE.Vector3(this.properties.torsionK.x, this.properties.torsionK.y, this.properties.torsionK.z);
};
DMAMaterial.prototype.getMesh = function(){
......
......@@ -142,7 +142,28 @@ define([], function(){
torsionK:{x:10,y:10,z:10}
}
},
conductive:{
conductive: {
name: "Conductive",
color: "#b5a642",
altColor: "#857B64",
properties:{
conductive: true,
conductiveAxes: [
{x:0, y:0, z:1},
{x:0, y:0, z:-1},
{x:1, y:0, z:0},
{x:-1, y:0, z:0},
{x:0, y:1, z:0},
{x:0, y:-1, z:0}
],
density: 3500,//kg/m^3
longitudalK:{x:80,y:80,z:80},
shearK:{xy:80,xz:80,yx:80,yz:80,zx:80,zy:80},
bendingK:{x:80,y:80,z:80},
torsionK:{x:80,y:80,z:80}
}
},
conductiveStraight:{
name: "Electronic Routing (Straight)",
color: "#b5a642",
altColor: "#857B64",
......@@ -216,6 +237,28 @@ define([], function(){
torsionK:{x:80,y:80,z:80}
}
},
flexureConductiveAll: {
name: "Flex Conductive",
color: "#b4ac9c",
altColor: "#b4ac9c",
texture: "stripes",
properties:{
conductive: true,
conductiveAxes: [
{x:0, y:0, z:1},
{x:0, y:0, z:-1},
{x:1, y:0, z:0},
{x:-1, y:0, z:0},
{x:0, y:1, z:0},
{x:0, y:-1, z:0}
],
density: 3500,//kg/m^3
longitudalK:{x:30,y:30,z:30},
shearK:{xy:30,xz:30,yx:30,yz:30,zx:30,zy:30},
bendingK:{x:30,y:30,z:30},
torsionK:{x:30,y:30,z:30}
}
},
flexureCond: {
name: "Flex Electronic Routing (Straight)",
color: "#b4ac9c",
......
This diff is collapsed.
......@@ -196,29 +196,37 @@ void main(){
}
float mass = massData.x;
vec3 force = u_gravity*mass;
float I = massData.z;//moment of inerita
vec3 force = vec3(0.0,0.0,0.0);
float rForce = 0.0;
vec3 translation = texture2D(u_lastTranslation, scaledFragCoord).xyz;
vec3 velocity = texture2D(u_lastVelocity, scaledFragCoord).xyz;
vec4 quaternion = texture2D(u_lastQuaternion, scaledFragCoord);
vec4 _position = texture2D(u_lastTranslation, scaledFragCoord);
vec4 _velocity = texture2D(u_lastVelocity, scaledFragCoord);
vec3 translation = _position.xyz;
float rotation = _position[3];
vec3 velocity = _velocity.xyz;
float angVelocity = _velocity[3];
vec4 quaternion = vec4(0.0, 0.0, sin(rotation/2.0), cos(rotation/2.0));
vec4 wiring = texture2D(u_wires, scaledFragCoord);
int actuatorType = convertToInt(wiring[0]);//>-1 means no actuator
//simple collision
float zPosition = texture2D(u_originalPosition, scaledFragCoord).z + translation.z*u_multiplier - u_groundHeight;
float collisionK = 1.0;
if (zPosition < 0.0) {
float normalForce = -zPosition*collisionK-velocity.z*collisionK/10.0;
force.z += normalForce;
if (u_friction > 0.5){
float mu = 10.0;
if (velocity.x > 0.0) force.x -= mu * normalForce;
else if (velocity.x < 0.0) force.x += mu * normalForce;
if (velocity.y > 0.0) force.y -= mu * normalForce;
else if (velocity.y < 0.0) force.y += mu * normalForce;
}
}
// //simple collision
// float zPosition = texture2D(u_originalPosition, scaledFragCoord).z + translation.z*u_multiplier - u_groundHeight;
// float collisionK = 1.0;
// if (zPosition < 0.0) {
// float normalForce = -zPosition*collisionK-velocity.z*collisionK/10.0;
// force.z += normalForce;
// if (u_friction > 0.5){
// float mu = 10.0;
// if (velocity.x > 0.0) force.x -= mu * normalForce;
// else if (velocity.x < 0.0) force.x += mu * normalForce;
// if (velocity.y > 0.0) force.y -= mu * normalForce;
// else if (velocity.y < 0.0) force.y += mu * normalForce;
// }
// }
for (float i=0.0;i<2.0;i+=1.0){
......@@ -239,9 +247,13 @@ void main(){
neighborIndex.y += 0.5;
vec2 scaledNeighborIndex = neighborIndex/u_textureDim;
vec3 neighborTranslation = texture2D(u_lastTranslation, scaledNeighborIndex).xyz;
vec3 neighborVelocity = texture2D(u_lastVelocity, scaledNeighborIndex).xyz;
vec4 neighborQuaternion = texture2D(u_lastQuaternion, scaledNeighborIndex);
vec4 _neighborPosition = texture2D(u_lastTranslation, scaledNeighborIndex);
vec4 _neighborVelocity = texture2D(u_lastVelocity, scaledNeighborIndex);
vec3 neighborTranslation = _neighborPosition.xyz;
float neighborRotation = _neighborPosition[3];
vec3 neighborVelocity = _neighborVelocity.xyz;
float neighborAngVelocity = _neighborVelocity[3];
vec4 neighborQuaternion = vec4(0.0, 0.0, sin(neighborRotation/2.0), cos(neighborRotation/2.0));
vec3 nominalD = neighborOffset(i*3.0+float(j));
......@@ -271,14 +283,21 @@ void main(){
vec3 cellHalfNominalD = applyQuaternion(halfNominalD, quaternion);//halfNominalD in cell's reference frame
vec3 neighborHalfNominalD = applyQuaternion(halfNominalD, neighborQuaternion);//halfNominalD in neighbor's reference frame
vec2 kIndex = vec2(((fragCoord.x-0.5)*12.0 + 2.0*(i*3.0+float(j)) + 0.5)/(u_textureDim.x*12.0), scaledFragCoord.y);
// vec2 kIndex = vec2(((fragCoord.x-0.5)*12.0 + 2.0*(i*3.0+float(j)) + 0.5)/(u_textureDim.x*12.0), scaledFragCoord.y);
float kPosition = ((fragCoord.x-0.5)*12.0 + 2.0*(i*3.0+float(j)) + 0.5);
vec2 kIndex = vec2(kPosition/(u_textureDim.x*12.0), scaledFragCoord.y);
vec3 translationalK = texture2D(u_compositeKs, kIndex).xyz;
vec3 translationalD = texture2D(u_compositeDs, kIndex).xyz;
kIndex.x = (kPosition+1.0)/(u_textureDim.x*12.0);
vec3 rotationalK = texture2D(u_compositeKs, kIndex).xyz;
vec3 rotationalD = texture2D(u_compositeDs, kIndex).xyz;
vec4 averageQuaternion = averageQuaternions(quaternion, neighborQuaternion);
float averageRotation = (neighborRotation+rotation)/2.0;
vec4 averageQuaternion = vec4(0.0, 0.0, sin(averageRotation/2.0), cos(averageRotation/2.0));
vec4 averageQuaternionInverse = invertQuaternion(averageQuaternion);
vec3 rotatedActuatedNominalD = applyQuaternion(actuatedD, averageQuaternion);
vec3 translationalDelta = neighborTranslation - translation + nominalD - cellHalfNominalD - neighborHalfNominalD;
vec3 translationalDelta = neighborTranslation - translation + nominalD - rotatedActuatedNominalD;
vec3 translationalDeltaXYZ = applyQuaternion(translationalDelta, averageQuaternionInverse);
vec3 velocityDelta = neighborVelocity-velocity;
vec3 velocityDeltaXYZ = applyQuaternion(velocityDelta, averageQuaternionInverse);
......@@ -287,8 +306,20 @@ void main(){
//convert _force vector back into world reference frame
_force = applyQuaternion(_force, averageQuaternion);
force += _force;
//translational forces cause rotation in cell
vec3 torque = cross(cellHalfNominalD, _force);//cellHalfNominalD = lever arm
rForce += torque[2];
//bending and torsion
float rotationDelta = neighborRotation-rotation;
float actuatedRotationalDelta = rotationDelta;
if (_actuatorType == -2) actuatedRotationalDelta -= 2.0*actuation*neighborSign(i*3.0+float(j));//bending
float angVelocityDelta = neighborAngVelocity - angVelocity;
rForce += rotationalK[2]*actuatedRotationalDelta + rotationalD[2]*angVelocityDelta;
}
}
gl_FragColor = vec4(force/mass, 0);
gl_FragColor = vec4(force/mass, rForce/I);
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ precision highp float;
uniform vec2 u_textureDim;
uniform float u_dt;
uniform sampler2D u_translation;
uniform sampler2D u_velocity;
uniform sampler2D u_lastTranslation;
uniform sampler2D u_mass;
......@@ -17,10 +17,17 @@ void main(){
return;
}
vec3 lastTranslation = texture2D(u_lastTranslation, scaledFragCoord).xyz;
vec3 translation = texture2D(u_translation, scaledFragCoord).xyz;
vec4 _lastTranslation = texture2D(u_lastTranslation, scaledFragCoord);
vec4 _velocity = texture2D(u_velocity, scaledFragCoord);
vec3 velocity = (translation - lastTranslation)/u_dt;
vec3 lastTranslation = _lastTranslation.xyz;
vec3 velocity = _velocity.xyz;
gl_FragColor = vec4(velocity, 0);
float lastRotation = _lastTranslation[3];
float angVelocity = _velocity[3];
vec3 translation = velocity*u_dt + lastTranslation;
float rotation = angVelocity*u_dt + lastRotation;
gl_FragColor = vec4(translation, rotation);
}
\ No newline at end of file
#define M_PI 3.1415926535897932384626433832795
precision mediump float;
uniform vec2 u_textureDim;
uniform float u_dt;
uniform sampler2D u_angVelocity;
uniform sampler2D u_lastQuaternion;
uniform sampler2D u_mass;
vec4 quaternionFromEuler(vec3 euler) {
float c1 = cos(euler[0] / 2.0);
float c2 = cos(euler[1] / 2.0);
float c3 = cos(euler[2] / 2.0);
float s1 = sin(euler[0] / 2.0);
float s2 = sin(euler[1] / 2.0);
float s3 = sin(euler[2] / 2.0);
return vec4(s1 * c2 * c3 - c1 * s2 * s3, c1 * s2 * c3 + s1 * c2 * s3, c1 * c2 * s3 - s1 * s2 * c3, c1 * c2 * c3 + s1 * s2 * s3);//zyx
}
vec4 multiplyQuaternions(vec4 a, vec4 b){
float qax = a[0];
float qay = a[1];
float qaz = a[2];
float qaw = a[3];
float qbx = b[0];
float qby = b[1];
float qbz = b[2];
float qbw = b[3];
return vec4(qax * qbw + qaw * qbx + qay * qbz - qaz * qby, qay * qbw + qaw * qby + qaz * qbx - qax * qbz,
qaz * qbw + qaw * qbz + qax * qby - qay * qbx, qaw * qbw - qax * qbx - qay * qby - qaz * qbz);
}
void main(){
vec2 fragCoord = gl_FragCoord.xy;
vec2 scaledFragCoord = fragCoord/u_textureDim;
float isFixed = texture2D(u_mass, scaledFragCoord).y;
if (isFixed < 0.0 || isFixed == 1.0){//no cell or is fixed
gl_FragColor = vec4(0, 0, 0, 1);
return;
}
vec4 quaternion = texture2D(u_lastQuaternion, scaledFragCoord);
vec3 angVelocity = texture2D(u_angVelocity, scaledFragCoord).xyz;
vec4 quaternionDelta = quaternionFromEuler(angVelocity*u_dt);
gl_FragColor = multiplyQuaternions(quaternion, quaternionDelta);
}
\ No newline at end of file
precision mediump float;
uniform vec2 u_textureDim;
uniform vec3 u_gravity;
uniform float u_dt;
uniform sampler2D u_lastVelocity;
uniform sampler2D u_lastTranslation;
uniform sampler2D u_mass;
uniform sampler2D u_fixed;
uniform sampler2D u_neighborsXMapping;
uniform sampler2D u_neighborsYMapping;
uniform sampler2D u_compositeKs;
uniform sampler2D u_compositeDs;
void main(){
vec2 fragCoord = gl_FragCoord.xy;
vec2 scaledFragCoord = fragCoord/u_textureDim;
float isFixed = texture2D(u_fixed, scaledFragCoord).x;
if (isFixed < 0.0 || isFixed == 1.0){//no cell or is fixed
gl_FragColor = vec4(0, 0, 0, 0);
return;
}
float mass = texture2D(u_mass, scaledFragCoord).x;
vec3 lastTranslation = texture2D(u_lastTranslation, scaledFragCoord).xyz;
vec3 lastVelocity = texture2D(u_lastVelocity, scaledFragCoord).xyz;
vec3 force = u_gravity*mass;
for (float i=0.0;i<2.0;i+=1.0){
float xIndex = 2.0*(fragCoord.x-0.5) + 0.5;
if (i>0.0) xIndex += 1.0;
vec2 mappingIndex = vec2(xIndex/(u_textureDim.x*2.0), scaledFragCoord.y);
vec3 neighborsXMapping = texture2D(u_neighborsXMapping, mappingIndex).xyz;
vec3 neighborsYMapping = texture2D(u_neighborsYMapping, mappingIndex).xyz;
vec3 compositeKs = texture2D(u_compositeKs, mappingIndex).xyz;
vec3 compositeDs = texture2D(u_compositeDs, mappingIndex).xyz;
for (int j=0;j<3;j++){
if (neighborsXMapping[j] < 0.0) continue;//no neighbor
vec2 neighborIndex = vec2(neighborsXMapping[j], neighborsYMapping[j]);
neighborIndex.x += 0.5;
neighborIndex.y += 0.5;
vec2 scaledNeighborIndex = neighborIndex/u_textureDim;
vec3 neighborTranslation = texture2D(u_lastTranslation, scaledNeighborIndex).xyz;
vec3 neighborVelocity = texture2D(u_lastVelocity, scaledNeighborIndex).xyz;
float k = compositeKs[j];
float d = 0.01;//compositeDs[j];
force += k*(neighborTranslation-lastTranslation) + d*(neighborVelocity-lastVelocity);
}
}
vec3 acceleration = force/mass;
vec3 velocity = lastVelocity + acceleration*u_dt;
gl_FragColor = vec4(velocity, 0);
}
\ No newline at end of file
......@@ -4,8 +4,7 @@ uniform vec2 u_textureDim;
uniform float u_dt;
uniform sampler2D u_acceleration;
uniform sampler2D u_lastTranslation;
uniform sampler2D u_lastLastTranslation;
uniform sampler2D u_lastVelocity;
uniform sampler2D u_mass;
void main(){
......@@ -18,11 +17,17 @@ void main(){
return;
}
vec3 lastTranslation = texture2D(u_lastTranslation, scaledFragCoord).xyz;
vec3 lastLastTranslation = texture2D(u_lastLastTranslation, scaledFragCoord).xyz;
vec3 acceleration = texture2D(u_acceleration, scaledFragCoord).xyz;
vec4 _lastVelocity = texture2D(u_lastVelocity, scaledFragCoord);
vec4 _acceleration = texture2D(u_acceleration, scaledFragCoord);
vec3 translation = 2.0*lastTranslation - lastLastTranslation + acceleration*u_dt*u_dt;
vec3 lastVelocity = _lastVelocity.xyz;
vec3 acceleration = _acceleration.xyz;
gl_FragColor = vec4(translation, 0);
float lastAngVelocity = _lastVelocity[3];
float angAccleration = _acceleration[3];
vec3 velocity = acceleration*u_dt + lastVelocity;
float angVelocity = angAccleration*u_dt + lastAngVelocity;
gl_FragColor = vec4(velocity, angVelocity);
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment