Commit ba32867c authored by amandaghassaei's avatar amandaghassaei

debugging

parent 58564e71
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -154,7 +154,7 @@
deltaP -= normalize(deltaP)*beamMeta[2];
vec3 deltaV = neighborLastVelocity-lastVelocity;
vec3 _force = deltaP*beamMeta[0];// + deltaV*beamMeta[1];
vec3 _force = deltaP*beamMeta[0] + deltaV*beamMeta[1];
force += _force;
}
......@@ -187,7 +187,7 @@
float momentArm = creaseMeta2[1];
vec3 _force = angForce/momentArm*normal;
force += _force;
//force += _force;
}
vec3 velocity = force*u_dt/mass.x + lastVelocity;
......@@ -234,7 +234,7 @@
<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/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/OrbitControls.js"></script>
<script type="text/javascript" src="dependencies/underscore-min.js"></script>
......
......@@ -119,9 +119,9 @@ function initDynamicModel(globals){
updateFixed();
globals.fixedHasChanged = false;
}
if (globals.materialHasChanged) {
updateMaterials();
globals.materialHasChanged = false;
if (globals.nodePositionHasChanged) {
updateLastPosition();
globals.nodePositionHasChanged = false;
}
if (globals.creaseMaterialHasChanged) {
updateCreasesMeta();
......@@ -187,7 +187,6 @@ function initDynamicModel(globals){
for (var i = 0; i < nodes.length; i++) {
var rgbaIndex = i * vectorLength;
var nodePosition = new THREE.Vector3(parsedPixels[rgbaIndex], parsedPixels[rgbaIndex + 1], parsedPixels[rgbaIndex + 2]);
// console.log(nodePosition);
nodes[i].render(nodePosition);
}
for (var i=0;i<edges.length;i++){
......@@ -204,7 +203,7 @@ function initDynamicModel(globals){
}
function setSolveParams(){
var dt = calcDt();
var dt = calcDt()/10;//todo this is weird
var numSteps = 0.5/dt;
globals.gpuMath.setProgram("velocityCalc");
globals.gpuMath.setUniformForProgram("velocityCalc", "u_dt", dt, "1f");
......@@ -379,7 +378,16 @@ function initDynamicModel(globals){
if (initing) creaseMeta[i*4+2] = crease.getTargetTheta();
}
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){
......@@ -478,6 +486,7 @@ function initDynamicModel(globals){
syncNodesAndEdges: syncNodesAndEdges,
pause: pause,
resume: resume,
setVisibility: setVisibility
setVisibility: setVisibility,
updateFixed: updateFixed
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ function initGlobals(){
shouldResetDynamicSim: false,
shouldChangeCreasePercent: false,
shouldSyncWithModel: false,
nodePositionHasChanged: false,
//3d vis
dynamicSimVisible: true,
......
......@@ -14,7 +14,10 @@ $(function() {
var mouse = new THREE.Vector2();
var raycasterPlane = new THREE.Plane(new THREE.Vector3(0,0,1));
var isDragging = false;
var draggingNode = null;
var draggingNodeFixed = false;
var mouseDown = false;
var highlightedObj;
$(document).dblclick(function() {
......@@ -25,6 +28,12 @@ $(function() {
}, false);
document.addEventListener('mouseup', function(e){
isDragging = false;
if (draggingNode){
draggingNode.setFixed(draggingNodeFixed);
draggingNode = null;
globals.fixedHasChanged = true;
globals.threeView.enableControls(true);
}
mouseDown = false;
}, false);
document.addEventListener( 'mousemove', mouseMove, false );
......@@ -38,6 +47,82 @@ $(function() {
mouse.x = (e.clientX/window.innerWidth)*2-1;
mouse.y = - (e.clientY/window.innerHeight)*2+1;
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();
......@@ -45,4 +130,5 @@ $(function() {
globals.dynamicModel = initDynamicModel(globals);
globals.pattern = initPattern(globals);
globals.threeView.render();
// globals.threeView.sceneAdd(raycasterPlane);
});
\ No newline at end of file
......@@ -5,6 +5,8 @@
//wireframe model and folding structure
function initModel(globals){
var allNodeObject3Ds = [];
var nodes = [];
nodes.push(new Node(new THREE.Vector3(0,0,0), nodes.length));
nodes.push(new Node(new THREE.Vector3(0,0,10), nodes.length));
......@@ -50,8 +52,11 @@ function initModel(globals){
}
globals.threeView.sceneClearModel();
var _allNodeObject3Ds = [];
_.each(_nodes, function(node){
globals.threeView.sceneAddModel(node.getObject3D());
var obj3D = node.getObject3D();
_allNodeObject3Ds.push(obj3D);
globals.threeView.sceneAddModel(obj3D);
});
_.each(_edges, function(edge){
globals.threeView.sceneAddModel(edge.getObject3D());
......@@ -62,6 +67,7 @@ function initModel(globals){
var oldCreases = creases;
nodes = _nodes;
allNodeObject3Ds = _allNodeObject3Ds;
edges = _edges;
faces = _faces;
creases = _creases;
......@@ -100,11 +106,16 @@ function initModel(globals){
return creases;
}
function getObjectsToIntersect(){
return allNodeObject3Ds;
}
return {
getNodes: getNodes,
getEdges: getEdges,
getFaces: getFaces,
getCreases: getCreases,
buildModel: buildModel
buildModel: buildModel,
getObjectsToIntersect: getObjectsToIntersect
}
}
\ No newline at end of file
......@@ -4,11 +4,10 @@
var nodeMaterial = 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: 0xff00ff, side:THREE.DoubleSide});
var nodeGeo = new THREE.CircleGeometry(0.2,20);
var nodeMaterialHighlight = new THREE.MeshBasicMaterial({color: 0xffffff, side:THREE.DoubleSide});
var nodeGeo = new THREE.SphereGeometry(10,20);
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) );
......@@ -47,6 +46,10 @@ Node.prototype.isFixed = function(){
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(){
};
Node.prototype.render = function(position){
if (this.fixed) return;
position.add(this.getOriginalPosition());
this.object3D.position.set(position.x, position.y, position.z);
};
......@@ -163,6 +167,10 @@ Node.prototype.getPosition = function(){
return this.object3D.position;
};
Node.prototype.getRelativePositon = function(){
return this.object3D.position.clone().sub(this._originalPosition);
};
Node.prototype.getSimMass = function(){
return 1;
};
......
......@@ -123,7 +123,7 @@ function initThreeView(globals) {
}
function sceneRemove(object){
wrapper.remote(object);
wrapper.remove(object);
}
function onWindowResize() {
......@@ -145,7 +145,11 @@ function initThreeView(globals) {
}
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) {
startAnimation: startAnimation,
pauseAnimation: pauseAnimation,
enableControls: enableControls,
getModelOffset: getModelOffset,
scene: scene,
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