Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AMOEBA
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amanda Ghassaei
AMOEBA
Commits
4ee28157
Commit
4ee28157
authored
Jul 11, 2016
by
amandaghassaei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
actuators in chader
parent
42b70174
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
156 additions
and
138 deletions
+156
-138
js/simulation/function/EM/emSimLattice.js
js/simulation/function/EM/emSimLattice.js
+71
-71
js/simulation/function/EM/shaders/accelerationCalcShader.js
js/simulation/function/EM/shaders/accelerationCalcShader.js
+42
-33
js/simulation/function/EM/shaders/angVelocityCalcShader.js
js/simulation/function/EM/shaders/angVelocityCalcShader.js
+43
-34
No files found.
js/simulation/function/EM/emSimLattice.js
View file @
4ee28157
...
...
@@ -602,77 +602,77 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G
iter
:
function
(
time
,
runConstants
,
shouldRender
){
//
gpuMath.step("accelerationCalc", ["u_lastVelocity", "u_lastTranslation", "u_mass", "u_neighborsXMapping",
//
"u_neighborsYMapping", "u_compositeKs", "u_compositeDs", "u_originalPosition", "u_lastQuaternion", "u_wires",
//
"u_wiresMeta"], "u_acceleration", time);
//
gpuMath.step("positionCalc", ["u_acceleration", "u_lastTranslation", "u_lastLastTranslation", "u_mass"],
//
"u_translation");
//
gpuMath.step("velocityCalc", ["u_translation", "u_lastTranslation"], "u_velocity");
//
//
gpuMath.step("angVelocityCalc", ["u_lastAngVelocity", "u_lastVelocity", "u_lastTranslation", "u_mass", "u_neighborsXMapping",
//
"u_neighborsYMapping", "u_compositeKs", "u_compositeDs", "u_lastQuaternion", "u_wires",
//
"u_wiresMeta"], "u_angVelocity", time);
//
gpuMath.step("quaternionCalc", ["u_angVelocity", "u_lastQuaternion", "u_mass"], "u_quaternion");
//
//
if (shouldRender) {
//
var textureSize = this.textureSize[0]*this.textureSize[1];
//
//
//get position
//
var vectorLength = 3;
//
gpuMath.setProgram("packToBytes");
//
gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
//
gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]);
//
gpuMath.step("packToBytes", ["u_translation"], "outputPositionBytes");
//
var pixels = new Uint8Array(textureSize * 4*vectorLength);
//
if (gpuMath.readyToRead()) {
//
gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels);
//
var parsedPixels = new Float32Array(pixels.buffer);
//
var cells = lattice.getCells();
//
var multiplier = 1 / (plist.allUnitTypes[lattice.getUnits()].multiplier);
//
for (var i = 0; i < textureSize; i++) {
//
var rgbaIndex = 4 * i;
//
if (this.mass[rgbaIndex+1] < 0) continue;//no more cells
//
var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]];
//
var parsePixelsIndex = vectorLength * i;
//
var translation = [parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2]];
//
var position = [this.originalPosition[rgbaIndex], this.originalPosition[rgbaIndex + 1], this.originalPosition[rgbaIndex + 2]];
//
position[0] += multiplier * translation[0];
//
position[1] += multiplier * translation[1];
//
position[2] += multiplier * translation[2];
//
cells[index[0]][index[1]][index[2]].object3D.position.set(position[0], position[1], position[2]);
//
}
//
}
//
//
vectorLength = 4;
//
gpuMath.setUniformForProgram("packToBytes", "u_vectorLength", vectorLength, "1f");
//
gpuMath.setSize(this.textureSize[0]*vectorLength, this.textureSize[1]);
//
gpuMath.step("packToBytes", ["u_quaternion"], "outputQuaternionBytes");
//
pixels = new Uint8Array(textureSize * 4*vectorLength);
//
if (gpuMath.readyToRead()) {
//
gpuMath.readPixels(0, 0, this.textureSize[0] * vectorLength, this.textureSize[1], pixels);
//
parsedPixels = new Float32Array(pixels.buffer);
//
for (var i = 0; i < textureSize; i++) {
//
var rgbaIndex = 4 * i;
//
if (this.mass[rgbaIndex+1] < 0) break;//no more cells
//
var index = [this.cellsArrayMapping[rgbaIndex], this.cellsArrayMapping[rgbaIndex + 1], this.cellsArrayMapping[rgbaIndex + 2]];
//
var parsePixelsIndex = vectorLength * i;
//
//
var quaternion = this._multiplyQuaternions([parsedPixels[parsePixelsIndex], parsedPixels[parsePixelsIndex + 1], parsedPixels[parsePixelsIndex + 2], parsedPixels[parsePixelsIndex + 3]],
//
[this.originalQuaternion[rgbaIndex], this.originalQuaternion[rgbaIndex+1], this.originalQuaternion[rgbaIndex+2], this.originalQuaternion[rgbaIndex+3]]);
//
var rotation = this._eulerFromQuaternion(quaternion);
//
//
cells[index[0]][index[1]][index[2]].object3D.rotation.set(rotation[0], rotation[1], rotation[2]);
//
}
//
}
//
//
gpuMath.setSize(this.textureSize[0], this.textureSize[1]);
//
}
//
//
gpuMath.swapTextures("u_velocity", "u_lastVelocity");
//
gpuMath.swap3Textures("u_translation", "u_lastTranslation", "u_lastLastTranslation");
//
gpuMath.swapTextures("u_angVelocity", "u_lastAngVelocity");
//
gpuMath.swapTextures("u_quaternion", "u_lastQuaternion");
//
return;
gpuMath
.
step
(
"
accelerationCalc
"
,
[
"
u_lastVelocity
"
,
"
u_lastTranslation
"
,
"
u_mass
"
,
"
u_neighborsXMapping
"
,
"
u_neighborsYMapping
"
,
"
u_compositeKs
"
,
"
u_compositeDs
"
,
"
u_originalPosition
"
,
"
u_lastQuaternion
"
,
"
u_wires
"
,
"
u_wiresMeta
"
],
"
u_acceleration
"
,
time
);
gpuMath
.
step
(
"
positionCalc
"
,
[
"
u_acceleration
"
,
"
u_lastTranslation
"
,
"
u_lastLastTranslation
"
,
"
u_mass
"
],
"
u_translation
"
);
gpuMath
.
step
(
"
velocityCalc
"
,
[
"
u_translation
"
,
"
u_lastTranslation
"
],
"
u_velocity
"
);
gpuMath
.
step
(
"
angVelocityCalc
"
,
[
"
u_lastAngVelocity
"
,
"
u_lastVelocity
"
,
"
u_lastTranslation
"
,
"
u_mass
"
,
"
u_neighborsXMapping
"
,
"
u_neighborsYMapping
"
,
"
u_compositeKs
"
,
"
u_compositeDs
"
,
"
u_lastQuaternion
"
,
"
u_wires
"
,
"
u_wiresMeta
"
],
"
u_angVelocity
"
,
time
);
gpuMath
.
step
(
"
quaternionCalc
"
,
[
"
u_angVelocity
"
,
"
u_lastQuaternion
"
,
"
u_mass
"
],
"
u_quaternion
"
);
if
(
shouldRender
)
{
var
textureSize
=
this
.
textureSize
[
0
]
*
this
.
textureSize
[
1
];
//get position
var
vectorLength
=
3
;
gpuMath
.
setProgram
(
"
packToBytes
"
);
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_vectorLength
"
,
vectorLength
,
"
1f
"
);
gpuMath
.
setSize
(
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
]);
gpuMath
.
step
(
"
packToBytes
"
,
[
"
u_translation
"
],
"
outputPositionBytes
"
);
var
pixels
=
new
Uint8Array
(
textureSize
*
4
*
vectorLength
);
if
(
gpuMath
.
readyToRead
())
{
gpuMath
.
readPixels
(
0
,
0
,
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
],
pixels
);
var
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
var
cells
=
lattice
.
getCells
();
var
multiplier
=
1
/
(
plist
.
allUnitTypes
[
lattice
.
getUnits
()].
multiplier
);
for
(
var
i
=
0
;
i
<
textureSize
;
i
++
)
{
var
rgbaIndex
=
4
*
i
;
if
(
this
.
mass
[
rgbaIndex
+
1
]
<
0
)
continue
;
//no more cells
var
index
=
[
this
.
cellsArrayMapping
[
rgbaIndex
],
this
.
cellsArrayMapping
[
rgbaIndex
+
1
],
this
.
cellsArrayMapping
[
rgbaIndex
+
2
]];
var
parsePixelsIndex
=
vectorLength
*
i
;
var
translation
=
[
parsedPixels
[
parsePixelsIndex
],
parsedPixels
[
parsePixelsIndex
+
1
],
parsedPixels
[
parsePixelsIndex
+
2
]];
var
position
=
[
this
.
originalPosition
[
rgbaIndex
],
this
.
originalPosition
[
rgbaIndex
+
1
],
this
.
originalPosition
[
rgbaIndex
+
2
]];
position
[
0
]
+=
multiplier
*
translation
[
0
];
position
[
1
]
+=
multiplier
*
translation
[
1
];
position
[
2
]
+=
multiplier
*
translation
[
2
];
cells
[
index
[
0
]][
index
[
1
]][
index
[
2
]].
object3D
.
position
.
set
(
position
[
0
],
position
[
1
],
position
[
2
]);
}
}
vectorLength
=
4
;
gpuMath
.
setUniformForProgram
(
"
packToBytes
"
,
"
u_vectorLength
"
,
vectorLength
,
"
1f
"
);
gpuMath
.
setSize
(
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
]);
gpuMath
.
step
(
"
packToBytes
"
,
[
"
u_quaternion
"
],
"
outputQuaternionBytes
"
);
pixels
=
new
Uint8Array
(
textureSize
*
4
*
vectorLength
);
if
(
gpuMath
.
readyToRead
())
{
gpuMath
.
readPixels
(
0
,
0
,
this
.
textureSize
[
0
]
*
vectorLength
,
this
.
textureSize
[
1
],
pixels
);
parsedPixels
=
new
Float32Array
(
pixels
.
buffer
);
for
(
var
i
=
0
;
i
<
textureSize
;
i
++
)
{
var
rgbaIndex
=
4
*
i
;
if
(
this
.
mass
[
rgbaIndex
+
1
]
<
0
)
break
;
//no more cells
var
index
=
[
this
.
cellsArrayMapping
[
rgbaIndex
],
this
.
cellsArrayMapping
[
rgbaIndex
+
1
],
this
.
cellsArrayMapping
[
rgbaIndex
+
2
]];
var
parsePixelsIndex
=
vectorLength
*
i
;
var
quaternion
=
this
.
_multiplyQuaternions
([
parsedPixels
[
parsePixelsIndex
],
parsedPixels
[
parsePixelsIndex
+
1
],
parsedPixels
[
parsePixelsIndex
+
2
],
parsedPixels
[
parsePixelsIndex
+
3
]],
[
this
.
originalQuaternion
[
rgbaIndex
],
this
.
originalQuaternion
[
rgbaIndex
+
1
],
this
.
originalQuaternion
[
rgbaIndex
+
2
],
this
.
originalQuaternion
[
rgbaIndex
+
3
]]);
var
rotation
=
this
.
_eulerFromQuaternion
(
quaternion
);
cells
[
index
[
0
]][
index
[
1
]][
index
[
2
]].
object3D
.
rotation
.
set
(
rotation
[
0
],
rotation
[
1
],
rotation
[
2
]);
}
}
gpuMath
.
setSize
(
this
.
textureSize
[
0
],
this
.
textureSize
[
1
]);
}
gpuMath
.
swapTextures
(
"
u_velocity
"
,
"
u_lastVelocity
"
);
gpuMath
.
swap3Textures
(
"
u_translation
"
,
"
u_lastTranslation
"
,
"
u_lastLastTranslation
"
);
gpuMath
.
swapTextures
(
"
u_angVelocity
"
,
"
u_lastAngVelocity
"
);
gpuMath
.
swapTextures
(
"
u_quaternion
"
,
"
u_lastQuaternion
"
);
return
;
var
gravity
=
runConstants
.
gravity
;
var
groundHeight
=
runConstants
.
groundHeight
;
...
...
js/simulation/function/EM/shaders/accelerationCalcShader.js
View file @
4ee28157
...
...
@@ -70,6 +70,7 @@ int convertToInt(float num){
}
float
getActuatorVoltage
(
float
wireIndex
){
vec2
wireCoord
=
vec2
(
0.5
,
(
floor
(
wireIndex
+
0.001
)
+
0.5
)
/
u_wiresMetaLength
);
vec4
wireMeta
=
texture2D
(
u_wiresMeta
,
wireCoord
);
int
type
=
convertToInt
(
wireMeta
[
0
]);
...
...
@@ -77,25 +78,34 @@ float getActuatorVoltage(float wireIndex){
//no signal connected
return
0.0
;
}
int
polarity
=
type
/
4
;
type
=
convertToInt
(
mod
(
float
(
type
),
4.0
));
float
frequency
=
wireMeta
[
1
];
float
period
=
1.0
/
frequency
;
float
phase
=
wireMeta
[
2
];
float
currentPhase
=
mod
(
u_time
+
phase
*
period
,
period
)
/
period
;
float
invert
=
1.0
;
if
(
wireMeta
[
3
]
>
0.5
)
invert
=
-
1.0
;
if
(
polarity
>
0
)
invert
=
-
invert
;
if
(
type
==
0
){
return
0.5
*
sin
(
2.0
*
M_PI
*
currentPhase
);
return
invert
*
0.5
*
sin
(
2.0
*
M_PI
*
currentPhase
);
}
if
(
type
==
1
){
float
pwm
=
wireMeta
[
3
];
if
(
currentPhase
<
pwm
)
return
0.5
;
return
-
0.5
;
if
(
currentPhase
<
pwm
)
return
invert
*
0.5
;
return
-
0.5
*
invert
;
}
if
(
type
==
2
){
if
(
wireMeta
[
3
]
>
0.5
)
return
0.5
-
currentPhase
;
return
currentPhase
-
0.5
;
if
(
wireMeta
[
3
]
>
0.5
)
return
invert
*
(
0.5
-
currentPhase
)
;
return
invert
*
(
currentPhase
-
0.5
)
;
}
if
(
type
==
3
){
if
(
currentPhase
<
0.5
)
return
currentPhase
*
2.0
-
0.5
;
return
0.5
-
(
currentPhase
-
0.5
)
*
2.0
;
if
(
currentPhase
<
0.5
)
return
invert
*
(
currentPhase
*
2.0
-
0.5
)
;
return
invert
*
(
0.5
-
(
currentPhase
-
0.5
)
*
2.0
)
;
}
return
0.0
;
}
...
...
@@ -193,7 +203,7 @@ void main(){
vec4
quaternion
=
texture2D
(
u_lastQuaternion
,
scaledFragCoord
);
vec4
wiring
=
texture2D
(
u_wires
,
scaledFragCoord
);
bool
isActuator
=
wiring
[
0
]
<
-
0.5
;
//-1
int
actuatorType
=
convertToInt
(
wiring
[
0
]);
//>-1 means no actuator
//simple collision
float
zPosition
=
texture2D
(
u_originalPosition
,
scaledFragCoord
).
z
+
translation
.
z
*
u_multiplier
-
u_groundHeight
;
...
...
@@ -234,33 +244,32 @@ void main(){
vec4
neighborQuaternion
=
texture2D
(
u_lastQuaternion
,
scaledNeighborIndex
);
vec3
nominalD
=
neighborOffset
(
i
*
3.0
+
float
(
j
));
vec3
halfNominalD
=
nominalD
/
2.0
;
float
actuation
=
0.0
;
int
_actuatorType
=
-
1
;
if
(
actuatorType
<
0
&&
convertToInt
(
wiring
[
3
])
==
neighborAxis
)
{
_actuatorType
=
actuatorType
;
actuation
+=
0.3
*
(
getActuatorVoltage
(
wiring
[
1
])
-
getActuatorVoltage
(
wiring
[
2
]));
}
else
{
vec4
neighborWiring
=
texture2D
(
u_wires
,
scaledNeighborIndex
);
int
neighborActuatorType
=
convertToInt
(
neighborWiring
[
0
]);
//properly wired actuator has type < 0
_actuatorType
=
neighborActuatorType
;
if
(
neighborActuatorType
<
0
&&
convertToInt
(
neighborWiring
[
3
])
==
neighborAxis
){
actuation
+=
0.3
*
(
getActuatorVoltage
(
neighborWiring
[
1
])
-
getActuatorVoltage
(
neighborWiring
[
2
]));
}
}
vec3
actuatedD
=
vec3
(
nominalD
[
0
],
nominalD
[
1
],
nominalD
[
2
]);
for
(
int
_i
=
0
;
_i
<
3
;
_i
++
){
if
(
_i
!=
neighborAxis
)
continue
;
if
(
_actuatorType
==
-
1
)
actuatedD
[
_i
]
*=
1.0
+
actuation
;
//linear actuator
else
if
(
_actuatorType
==
-
4
)
actuatedD
[
0
]
+=
actuatedD
[
_i
]
*
actuation
;
//shear x
else
if
(
_actuatorType
==
-
5
)
actuatedD
[
1
]
+=
actuatedD
[
_i
]
*
actuation
;
//shear y
else
if
(
_actuatorType
==
-
6
)
actuatedD
[
2
]
+=
actuatedD
[
_i
]
*
actuation
;
//shear z
}
vec3
halfNominalD
=
actuatedD
/
2.0
;
vec3
cellHalfNominalD
=
applyQuaternion
(
halfNominalD
,
quaternion
);
//halfNominalD in cell's reference frame
vec3
neighborHalfNominalD
=
applyQuaternion
(
halfNominalD
,
neighborQuaternion
);
//halfNominalD in neighbor's reference frame
//vec3 actuatedD = vec3(nominalD[0], nominalD[1], nominalD[2]);
//float actuation = 0.0;
//if (isActuator){
// if (neighborAxis == 0 && wiring[1]>0.1){//>0
// actuation += 0.3*getActuatorVoltage(wiring[1]-1.0);
// } else if (neighborAxis == 1 && wiring[2]>0.1){
// actuation += 0.3*getActuatorVoltage(wiring[2]-1.0);
// } else if (neighborAxis == 2 && wiring[3]>0.1){
// actuation += 0.3*getActuatorVoltage(wiring[3]-1.0);
// }
//}
//vec4 neighborWiring = texture2D(u_wires, scaledNeighborIndex);
//if (neighborWiring[0] < -0.5){
// if (neighborAxis == 0 && neighborWiring[1]>0.1){
// actuation += 0.3*getActuatorVoltage(neighborWiring[1]-1.0);
// } else if (neighborAxis == 1 && neighborWiring[2]>0.1){
// actuation += 0.3*getActuatorVoltage(neighborWiring[2]-1.0);
// } else if (neighborAxis == 2 && neighborWiring[3]>0.1){
// actuation += 0.3*getActuatorVoltage(neighborWiring[3]-1.0);
// }
//}
//if (neighborAxis == 0) actuatedD[0] *= 1.0+actuation;
//else if (neighborAxis == 1) actuatedD[1] *= 1.0+actuation;
//else if (neighborAxis == 2) actuatedD[2] *= 1.0+actuation;
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
);
vec3
translationalK
=
texture2D
(
u_compositeKs
,
kIndex
).
xyz
;
...
...
js/simulation/function/EM/shaders/angVelocityCalcShader.js
View file @
4ee28157
...
...
@@ -162,6 +162,7 @@ int convertToInt(float num){
}
float
getActuatorVoltage
(
float
wireIndex
){
vec2
wireCoord
=
vec2
(
0.5
,
(
floor
(
wireIndex
+
0.001
)
+
0.5
)
/
u_wiresMetaLength
);
vec4
wireMeta
=
texture2D
(
u_wiresMeta
,
wireCoord
);
int
type
=
convertToInt
(
wireMeta
[
0
]);
...
...
@@ -169,25 +170,34 @@ float getActuatorVoltage(float wireIndex){
//no signal connected
return
0.0
;
}
int
polarity
=
type
/
4
;
type
=
convertToInt
(
mod
(
float
(
type
),
4.0
));
float
frequency
=
wireMeta
[
1
];
float
period
=
1.0
/
frequency
;
float
phase
=
wireMeta
[
2
];
float
currentPhase
=
mod
(
u_time
+
phase
*
period
,
period
)
/
period
;
float
currentPhase
=
mod
(
u_time
+
phase
*
period
,
period
)
/
period
;
float
invert
=
1.0
;
if
(
wireMeta
[
3
]
>
0.5
)
invert
=
-
1.0
;
if
(
polarity
>
0
)
invert
=
-
invert
;
if
(
type
==
0
){
return
0.5
*
sin
(
2.0
*
M_PI
*
currentPhase
);
return
invert
*
0.5
*
sin
(
2.0
*
M_PI
*
currentPhase
);
}
if
(
type
==
1
){
float
pwm
=
wireMeta
[
3
];
if
(
currentPhase
<
pwm
)
return
0.5
;
return
-
0.5
;
if
(
currentPhase
<
pwm
)
return
invert
*
0.5
;
return
-
0.5
*
invert
;
}
if
(
type
==
2
){
if
(
wireMeta
[
3
]
>
0.5
)
return
0.5
-
currentPhase
;
return
currentPhase
-
0.5
;
if
(
wireMeta
[
3
]
>
0.5
)
return
invert
*
(
0.5
-
currentPhase
)
;
return
invert
*
(
currentPhase
-
0.5
)
;
}
if
(
type
==
3
){
if
(
currentPhase
<
0.5
)
return
currentPhase
*
2.0
-
0.5
;
return
0.5
-
(
currentPhase
-
0.5
)
*
2.0
;
if
(
currentPhase
<
0.5
)
return
invert
*
(
currentPhase
*
2.0
-
0.5
)
;
return
invert
*
(
0.5
-
(
currentPhase
-
0.5
)
*
2.0
)
;
}
return
0.0
;
}
...
...
@@ -287,7 +297,7 @@ void main(){
vec3
angVelocity
=
texture2D
(
u_lastAngVelocity
,
scaledFragCoord
).
xyz
;
vec4
wiring
=
texture2D
(
u_wires
,
scaledFragCoord
);
bool
isActuator
=
wiring
[
0
]
<
-
0.5
;
//-1
int
actuatorType
=
convertToInt
(
wiring
[
0
]);
//>-1 means no actuator
for
(
float
i
=
0.0
;
i
<
2.0
;
i
+=
1.0
){
...
...
@@ -313,33 +323,32 @@ void main(){
vec4
neighborQuaternion
=
texture2D
(
u_lastQuaternion
,
scaledNeighborIndex
);
vec3
nominalD
=
neighborOffset
(
i
*
3.0
+
float
(
j
));
vec3
halfNominalD
=
nominalD
/
2.0
;
float
actuation
=
0.0
;
int
_actuatorType
=
-
1
;
if
(
actuatorType
<
0
&&
convertToInt
(
wiring
[
3
])
==
neighborAxis
)
{
_actuatorType
=
actuatorType
;
actuation
+=
0.3
*
(
getActuatorVoltage
(
wiring
[
1
])
-
getActuatorVoltage
(
wiring
[
2
]));
}
else
{
vec4
neighborWiring
=
texture2D
(
u_wires
,
scaledNeighborIndex
);
int
neighborActuatorType
=
convertToInt
(
neighborWiring
[
0
]);
//properly wired actuator has type < 0
_actuatorType
=
neighborActuatorType
;
if
(
neighborActuatorType
<
0
&&
convertToInt
(
neighborWiring
[
3
])
==
neighborAxis
){
actuation
+=
0.3
*
(
getActuatorVoltage
(
neighborWiring
[
1
])
-
getActuatorVoltage
(
neighborWiring
[
2
]));
}
}
vec3
actuatedD
=
vec3
(
nominalD
[
0
],
nominalD
[
1
],
nominalD
[
2
]);
for
(
int
_i
=
0
;
_i
<
3
;
_i
++
){
if
(
_i
!=
neighborAxis
)
continue
;
if
(
_actuatorType
==
-
1
)
actuatedD
[
_i
]
*=
1.0
+
actuation
;
//linear actuator
else
if
(
_actuatorType
==
-
4
)
actuatedD
[
0
]
+=
actuatedD
[
_i
]
*
actuation
;
//shear x
else
if
(
_actuatorType
==
-
5
)
actuatedD
[
1
]
+=
actuatedD
[
_i
]
*
actuation
;
//shear y
else
if
(
_actuatorType
==
-
6
)
actuatedD
[
2
]
+=
actuatedD
[
_i
]
*
actuation
;
//shear z
}
vec3
halfNominalD
=
actuatedD
/
2.0
;
vec3
cellHalfNominalD
=
applyQuaternion
(
halfNominalD
,
quaternion
);
//halfNominalD in cell's reference frame
vec3
neighborHalfNominalD
=
applyQuaternion
(
halfNominalD
,
neighborQuaternion
);
//halfNominalD in neighbor's reference frame
//vec3 actuatedD = vec3(nominalD[0], nominalD[1], nominalD[2]);
//float actuation = 0.0;
//if (isActuator){
// if (neighborAxis == 0 && wiring[1]>0.1){//>0
// actuation += 0.3*getActuatorVoltage(wiring[1]-1.0);
// } else if (neighborAxis == 1 && wiring[2]>0.1){
// actuation += 0.3*getActuatorVoltage(wiring[2]-1.0);
// } else if (neighborAxis == 2 && wiring[3]>0.1){
// actuation += 0.3*getActuatorVoltage(wiring[3]-1.0);
// }
//}
//vec4 neighborWiring = texture2D(u_wires, scaledNeighborIndex);
//if (neighborWiring[0] < -0.5){
// if (neighborAxis == 0 && neighborWiring[1]>0.1){
// actuation += 0.3*getActuatorVoltage(neighborWiring[1]-1.0);
// } else if (neighborAxis == 1 && neighborWiring[2]>0.1){
// actuation += 0.3*getActuatorVoltage(neighborWiring[2]-1.0);
// } else if (neighborAxis == 2 && neighborWiring[3]>0.1){
// actuation += 0.3*getActuatorVoltage(neighborWiring[3]-1.0);
// }
//}
//if (neighborAxis == 0) actuatedD[0] *= 1.0+actuation;
//else if (neighborAxis == 1) actuatedD[1] *= 1.0+actuation;
//else if (neighborAxis == 2) actuatedD[2] *= 1.0+actuation;
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment