Commit ba32867c authored by amandaghassaei's avatar amandaghassaei

debugging

parent 58564e71
This diff is collapsed.
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
deltaP -= normalize(deltaP)*beamMeta[2]; deltaP -= normalize(deltaP)*beamMeta[2];
vec3 deltaV = neighborLastVelocity-lastVelocity; vec3 deltaV = neighborLastVelocity-lastVelocity;
vec3 _force = deltaP*beamMeta[0];// + deltaV*beamMeta[1]; vec3 _force = deltaP*beamMeta[0] + deltaV*beamMeta[1];
force += _force; force += _force;
} }
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
float momentArm = creaseMeta2[1]; float momentArm = creaseMeta2[1];
vec3 _force = angForce/momentArm*normal; vec3 _force = angForce/momentArm*normal;
force += _force; //force += _force;
} }
vec3 velocity = force*u_dt/mass.x + lastVelocity; vec3 velocity = force*u_dt/mass.x + lastVelocity;
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
<script type="text/javascript" src="dependencies/jquery-3.1.1.min.js"></script> <script type="text/javascript" src="dependencies/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="dependencies/jquery-ui.min.js"></script> <script type="text/javascript" src="dependencies/jquery-ui.min.js"></script>
<script type="text/javascript" src="dependencies/flat-ui.min.js"></script> <script type="text/javascript" src="dependencies/flat-ui.min.js"></script>
<script type="text/javascript" src="dependencies/three.min.js"></script> <script type="text/javascript" src="dependencies/three.js"></script>
<script type="text/javascript" src="dependencies/binary_stl_writer.js"></script> <script type="text/javascript" src="dependencies/binary_stl_writer.js"></script>
<script type="text/javascript" src="dependencies/OrbitControls.js"></script> <script type="text/javascript" src="dependencies/OrbitControls.js"></script>
<script type="text/javascript" src="dependencies/underscore-min.js"></script> <script type="text/javascript" src="dependencies/underscore-min.js"></script>
......
...@@ -119,9 +119,9 @@ function initDynamicModel(globals){ ...@@ -119,9 +119,9 @@ function initDynamicModel(globals){
updateFixed(); updateFixed();
globals.fixedHasChanged = false; globals.fixedHasChanged = false;
} }
if (globals.materialHasChanged) { if (globals.nodePositionHasChanged) {
updateMaterials(); updateLastPosition();
globals.materialHasChanged = false; globals.nodePositionHasChanged = false;
} }
if (globals.creaseMaterialHasChanged) { if (globals.creaseMaterialHasChanged) {
updateCreasesMeta(); updateCreasesMeta();
...@@ -187,7 +187,6 @@ function initDynamicModel(globals){ ...@@ -187,7 +187,6 @@ function initDynamicModel(globals){
for (var i = 0; i < nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
var rgbaIndex = i * vectorLength; var rgbaIndex = i * vectorLength;
var nodePosition = new THREE.Vector3(parsedPixels[rgbaIndex], parsedPixels[rgbaIndex + 1], parsedPixels[rgbaIndex + 2]); var nodePosition = new THREE.Vector3(parsedPixels[rgbaIndex], parsedPixels[rgbaIndex + 1], parsedPixels[rgbaIndex + 2]);
// console.log(nodePosition);
nodes[i].render(nodePosition); nodes[i].render(nodePosition);
} }
for (var i=0;i<edges.length;i++){ for (var i=0;i<edges.length;i++){
...@@ -204,7 +203,7 @@ function initDynamicModel(globals){ ...@@ -204,7 +203,7 @@ function initDynamicModel(globals){
} }
function setSolveParams(){ function setSolveParams(){
var dt = calcDt(); var dt = calcDt()/10;//todo this is weird
var numSteps = 0.5/dt; var numSteps = 0.5/dt;
globals.gpuMath.setProgram("velocityCalc"); globals.gpuMath.setProgram("velocityCalc");
globals.gpuMath.setUniformForProgram("velocityCalc", "u_dt", dt, "1f"); globals.gpuMath.setUniformForProgram("velocityCalc", "u_dt", dt, "1f");
...@@ -379,7 +378,16 @@ function initDynamicModel(globals){ ...@@ -379,7 +378,16 @@ function initDynamicModel(globals){
if (initing) creaseMeta[i*4+2] = crease.getTargetTheta(); if (initing) creaseMeta[i*4+2] = crease.getTargetTheta();
} }
globals.gpuMath.initTextureFromData("u_creaseMeta", textureDimCreases, textureDimCreases, "FLOAT", creaseMeta, true); globals.gpuMath.initTextureFromData("u_creaseMeta", textureDimCreases, textureDimCreases, "FLOAT", creaseMeta, true);
}
function updateLastPosition(){
for (var i=0;i<nodes.length;i++){
var _position = nodes[i].getRelativePositon();
lastPosition[4*i] = _position.x;
lastPosition[4*i+1] = _position.y;
lastPosition[4*i+2] = _position.z;
}
globals.gpuMath.initTextureFromData("u_lastPosition", textureDim, textureDim, "FLOAT", lastPosition, true);
} }
function setCreasePercent(percent){ function setCreasePercent(percent){
...@@ -478,6 +486,7 @@ function initDynamicModel(globals){ ...@@ -478,6 +486,7 @@ function initDynamicModel(globals){
syncNodesAndEdges: syncNodesAndEdges, syncNodesAndEdges: syncNodesAndEdges,
pause: pause, pause: pause,
resume: resume, resume: resume,
setVisibility: setVisibility setVisibility: setVisibility,
updateFixed: updateFixed
} }
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ function initGlobals(){ ...@@ -15,6 +15,7 @@ function initGlobals(){
shouldResetDynamicSim: false, shouldResetDynamicSim: false,
shouldChangeCreasePercent: false, shouldChangeCreasePercent: false,
shouldSyncWithModel: false, shouldSyncWithModel: false,
nodePositionHasChanged: false,
//3d vis //3d vis
dynamicSimVisible: true, dynamicSimVisible: true,
......
...@@ -14,7 +14,10 @@ $(function() { ...@@ -14,7 +14,10 @@ $(function() {
var mouse = new THREE.Vector2(); var mouse = new THREE.Vector2();
var raycasterPlane = new THREE.Plane(new THREE.Vector3(0,0,1)); var raycasterPlane = new THREE.Plane(new THREE.Vector3(0,0,1));
var isDragging = false; var isDragging = false;
var draggingNode = null;
var draggingNodeFixed = false;
var mouseDown = false; var mouseDown = false;
var highlightedObj;
$(document).dblclick(function() { $(document).dblclick(function() {
...@@ -25,6 +28,12 @@ $(function() { ...@@ -25,6 +28,12 @@ $(function() {
}, false); }, false);
document.addEventListener('mouseup', function(e){ document.addEventListener('mouseup', function(e){
isDragging = false; isDragging = false;
if (draggingNode){
draggingNode.setFixed(draggingNodeFixed);
draggingNode = null;
globals.fixedHasChanged = true;
globals.threeView.enableControls(true);
}
mouseDown = false; mouseDown = false;
}, false); }, false);
document.addEventListener( 'mousemove', mouseMove, false ); document.addEventListener( 'mousemove', mouseMove, false );
...@@ -38,6 +47,82 @@ $(function() { ...@@ -38,6 +47,82 @@ $(function() {
mouse.x = (e.clientX/window.innerWidth)*2-1; mouse.x = (e.clientX/window.innerWidth)*2-1;
mouse.y = - (e.clientY/window.innerHeight)*2+1; mouse.y = - (e.clientY/window.innerHeight)*2+1;
raycaster.setFromCamera(mouse, globals.threeView.camera); raycaster.setFromCamera(mouse, globals.threeView.camera);
var _highlightedObj = null;
if (!isDragging) {
var objsToIntersect = [];
objsToIntersect = objsToIntersect.concat(globals.model.getObjectsToIntersect());
_highlightedObj = checkForIntersections(e, objsToIntersect);
setHighlightedObj(_highlightedObj);
} else if (isDragging && highlightedObj){
if (!draggingNode) {
draggingNode = highlightedObj;
draggingNodeFixed = draggingNode.isFixed();
draggingNode.setFixed(true);
globals.fixedHasChanged = true;
globals.threeView.enableControls(false);
}
var intersection = getIntersectionWithObjectPlane(highlightedObj.getPosition().clone());
intersection.sub(globals.threeView.getModelOffset());
highlightedObj.moveManually(intersection);
globals.nodePositionHasChanged = true;
}
}
function getIntersectionWithObjectPlane(position){
var cameraOrientation = globals.threeView.camera.getWorldDirection();
var dist = position.dot(cameraOrientation);
raycasterPlane.set(cameraOrientation, -dist);
var intersection = new THREE.Vector3();
raycaster.ray.intersectPlane(raycasterPlane, intersection);
return intersection;
}
// function getPointOfIntersectionWithObject(object){
// var intersections = raycaster.intersectObjects([object], false);
// if (intersections.length > 0) {
// return intersections[0].point;
// }
// console.warn("no intersection found");
// return null;
// }
function setHighlightedObj(object){
if (highlightedObj && (object != highlightedObj)) {
highlightedObj.unhighlight();
// globals.controls.hideMoreInfo();
}
highlightedObj = object;
if (highlightedObj) highlightedObj.highlight();
globals.threeView.render();
}
function checkForIntersections(e, objects){
var _highlightedObj = null;
var intersections = raycaster.intersectObjects(objects, true);
if (intersections.length > 0) {
var objectFound = false;
_.each(intersections, function (thing) {
if (objectFound) return;
if (thing.object && thing.object._myNode){
_highlightedObj = thing.object._myNode;
if (!_highlightedObj.fixed) return;
_highlightedObj.highlight();
objectFound = true;
}
});
}
return _highlightedObj;
}
function dragNode(e){
globals.threeView.enableControls(false);
highlightedObj.highlight();
raycasterPlane.set(raycasterPlane.normal, -highlightedObj.getPosition().z);
var intersection = new THREE.Vector3();
raycaster.ray.intersectPlane(raycasterPlane, intersection);
// globals.dynamicModel.updateFixedHeights();
// globals.dynamicModel.updateOriginalPosition();
} }
globals = initGlobals(); globals = initGlobals();
...@@ -45,4 +130,5 @@ $(function() { ...@@ -45,4 +130,5 @@ $(function() {
globals.dynamicModel = initDynamicModel(globals); globals.dynamicModel = initDynamicModel(globals);
globals.pattern = initPattern(globals); globals.pattern = initPattern(globals);
globals.threeView.render(); globals.threeView.render();
// globals.threeView.sceneAdd(raycasterPlane);
}); });
\ No newline at end of file
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
//wireframe model and folding structure //wireframe model and folding structure
function initModel(globals){ function initModel(globals){
var allNodeObject3Ds = [];
var nodes = []; var nodes = [];
nodes.push(new Node(new THREE.Vector3(0,0,0), nodes.length)); nodes.push(new Node(new THREE.Vector3(0,0,0), nodes.length));
nodes.push(new Node(new THREE.Vector3(0,0,10), nodes.length)); nodes.push(new Node(new THREE.Vector3(0,0,10), nodes.length));
...@@ -50,8 +52,11 @@ function initModel(globals){ ...@@ -50,8 +52,11 @@ function initModel(globals){
} }
globals.threeView.sceneClearModel(); globals.threeView.sceneClearModel();
var _allNodeObject3Ds = [];
_.each(_nodes, function(node){ _.each(_nodes, function(node){
globals.threeView.sceneAddModel(node.getObject3D()); var obj3D = node.getObject3D();
_allNodeObject3Ds.push(obj3D);
globals.threeView.sceneAddModel(obj3D);
}); });
_.each(_edges, function(edge){ _.each(_edges, function(edge){
globals.threeView.sceneAddModel(edge.getObject3D()); globals.threeView.sceneAddModel(edge.getObject3D());
...@@ -62,6 +67,7 @@ function initModel(globals){ ...@@ -62,6 +67,7 @@ function initModel(globals){
var oldCreases = creases; var oldCreases = creases;
nodes = _nodes; nodes = _nodes;
allNodeObject3Ds = _allNodeObject3Ds;
edges = _edges; edges = _edges;
faces = _faces; faces = _faces;
creases = _creases; creases = _creases;
...@@ -100,11 +106,16 @@ function initModel(globals){ ...@@ -100,11 +106,16 @@ function initModel(globals){
return creases; return creases;
} }
function getObjectsToIntersect(){
return allNodeObject3Ds;
}
return { return {
getNodes: getNodes, getNodes: getNodes,
getEdges: getEdges, getEdges: getEdges,
getFaces: getFaces, getFaces: getFaces,
getCreases: getCreases, getCreases: getCreases,
buildModel: buildModel buildModel: buildModel,
getObjectsToIntersect: getObjectsToIntersect
} }
} }
\ No newline at end of file
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
var nodeMaterial = new THREE.MeshBasicMaterial({color: 0x000000, side:THREE.DoubleSide}); var nodeMaterial = new THREE.MeshBasicMaterial({color: 0x000000, side:THREE.DoubleSide});
var nodeMaterialFixed = new THREE.MeshBasicMaterial({color: 0x000000, side:THREE.DoubleSide}); var nodeMaterialFixed = new THREE.MeshBasicMaterial({color: 0x000000, side:THREE.DoubleSide});
var nodeMaterialDelete = new THREE.MeshBasicMaterial({color: 0xff0000, side:THREE.DoubleSide}); var nodeMaterialHighlight = new THREE.MeshBasicMaterial({color: 0xffffff, side:THREE.DoubleSide});
var nodeMaterialHighlight = new THREE.MeshBasicMaterial({color: 0xff00ff, side:THREE.DoubleSide}); var nodeGeo = new THREE.SphereGeometry(10,20);
var nodeGeo = new THREE.CircleGeometry(0.2,20);
nodeGeo.rotateX(Math.PI/2); nodeGeo.rotateX(Math.PI/2);
var nodeFixedGeo = new THREE.CubeGeometry(1, 0.5, 1); var nodeFixedGeo = new THREE.CubeGeometry(10, 10, 10);
nodeFixedGeo.applyMatrix( new THREE.Matrix4().makeTranslation(0, 0.25, 0) ); nodeFixedGeo.applyMatrix( new THREE.Matrix4().makeTranslation(0, 0.25, 0) );
...@@ -47,6 +46,10 @@ Node.prototype.isFixed = function(){ ...@@ -47,6 +46,10 @@ Node.prototype.isFixed = function(){
return this.fixed; return this.fixed;
}; };
Node.prototype.moveManually = function(position){
this.object3D.position.set(position.x, position.y, position.z);
};
...@@ -142,6 +145,7 @@ Node.prototype.hide = function(){ ...@@ -142,6 +145,7 @@ Node.prototype.hide = function(){
}; };
Node.prototype.render = function(position){ Node.prototype.render = function(position){
if (this.fixed) return;
position.add(this.getOriginalPosition()); position.add(this.getOriginalPosition());
this.object3D.position.set(position.x, position.y, position.z); this.object3D.position.set(position.x, position.y, position.z);
}; };
...@@ -163,6 +167,10 @@ Node.prototype.getPosition = function(){ ...@@ -163,6 +167,10 @@ Node.prototype.getPosition = function(){
return this.object3D.position; return this.object3D.position;
}; };
Node.prototype.getRelativePositon = function(){
return this.object3D.position.clone().sub(this._originalPosition);
};
Node.prototype.getSimMass = function(){ Node.prototype.getSimMass = function(){
return 1; return 1;
}; };
......
...@@ -123,7 +123,7 @@ function initThreeView(globals) { ...@@ -123,7 +123,7 @@ function initThreeView(globals) {
} }
function sceneRemove(object){ function sceneRemove(object){
wrapper.remote(object); wrapper.remove(object);
} }
function onWindowResize() { function onWindowResize() {
...@@ -145,7 +145,11 @@ function initThreeView(globals) { ...@@ -145,7 +145,11 @@ function initThreeView(globals) {
} }
function centerModel(position){ function centerModel(position){
modelWrapper.position.set(position.x, 0, position.z); // modelWrapper.position.set(position.x, 0, position.z);
}
function getModelOffset(){
return modelWrapper.position.clone();
} }
...@@ -163,6 +167,7 @@ function initThreeView(globals) { ...@@ -163,6 +167,7 @@ function initThreeView(globals) {
startAnimation: startAnimation, startAnimation: startAnimation,
pauseAnimation: pauseAnimation, pauseAnimation: pauseAnimation,
enableControls: enableControls, enableControls: enableControls,
getModelOffset: getModelOffset,
scene: scene, scene: scene,
camera: camera camera: camera
} }
......
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