//[ContextMenu("Saves to File")] for debugging uncomment and make public /// <param name="clear">If true completely clears out the list of objects previously saved during session</param> private void AbstractGeoObjtoGeoObj(bool clear) { AbstractGeoObj[] allObj = FindObjectsOfType <AbstractGeoObj>().Where(g => (g.tag != "NoSave" && ((g.GetComponent <AnchorableBehaviour>() != null && !g.GetComponent <AnchorableBehaviour>().isAttached) || g.GetComponent <AnchorableBehaviour>() == null))).ToArray(); if (clear) { GeoObjDB.list = new List <GeoObj>(); } foreach (AbstractGeoObj obj in allObj) { List <string> dependencyList = new List <string>(); GeoObjDef thisObjDef; switch (obj.figType) { case GeoObjType.point: thisObjDef = determineDef(obj, GeoObjType.point); GeoObjDB.list.Add(new GeoObj(obj.figName, obj.transform.position, thisObjDef, GeoObjType.point)); break; case GeoObjType.line: thisObjDef = determineDef(obj, GeoObjType.line); AbstractLineSegment thisLineRef = obj.GetComponent <AbstractLineSegment>(); HW_GeoSolver.ins.geomanager.neighborsOfNode(thisLineRef.figName) .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPoint>() != null).ToList() .ForEach(d => dependencyList.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractGeoObj>().figName)); GeoObjDB.list.Add(new GeoObj(obj.figName, obj.transform.position, obj.transform.rotation, new figData.line(thisLineRef.vertex0, thisLineRef.vertex1), thisObjDef, dependencyList, GeoObjType.line)); break; case GeoObjType.polygon: thisObjDef = determineDef(obj, GeoObjType.polygon); AbstractPolygon thisPolyRef = obj.GetComponent <AbstractPolygon>(); dependencyList = new List <string>(); thisPolyRef.pointList.ForEach(p => dependencyList.Add(p.figName)); thisPolyRef.lineList.ForEach(l => dependencyList.Add(l.figName)); GeoObjDB.list.Add(new GeoObj( obj.figName, obj.transform.position, obj.transform.rotation, new figData.polygon(thisPolyRef.normDir, thisPolyRef.lineList.Count), thisObjDef, dependencyList, GeoObjType.polygon)); break; case GeoObjType.prism: thisObjDef = determineDef(obj, GeoObjType.prism); InteractablePrism thisPrismRef = obj.GetComponent <InteractablePrism>(); // no abstract version List <string> bases = new List <string>(); List <string> sides = new List <string>(); List <string> edges = new List <string>(); thisPrismRef.bases.ForEach(b => bases.Add(b.figName)); thisPrismRef.sides.ForEach(s => sides.Add(s.figName)); thisPrismRef.lineSegments.ForEach(e => edges.Add(e.figName)); GeoObjDB.list.Add(new GeoObj(obj.figName, obj.transform.position, obj.transform.rotation, new figData.prism(bases, sides, edges), thisObjDef, GeoObjType.prism)); break; case GeoObjType.pyramid: thisObjDef = determineDef(obj, GeoObjType.pyramid); DependentPyramid thisPyramidRef = GetComponent <DependentPyramid>(); // no abstract version HW_GeoSolver.ins.geomanager.neighborsOfNode(thisPyramidRef.figName).ToList() .ForEach(d => dependencyList.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractGeoObj>().figName)); GeoObjDB.list.Add(new GeoObj( obj.figName, obj.transform.position, obj.transform.rotation, new figData.pyramid(thisPyramidRef.apex.figName, thisPyramidRef.apex.transform.position), thisObjDef, dependencyList, GeoObjType.pyramid)); break; case GeoObjType.circle: thisObjDef = determineDef(obj, GeoObjType.circle); AbstractCircle thisCircleRef = obj.GetComponent <AbstractCircle>(); HW_GeoSolver.ins.geomanager.neighborsOfNode(thisCircleRef.figName).ToList() .ForEach(d => dependencyList.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractGeoObj>().figName)); GeoObjDB.list.Add(new GeoObj( obj.figName, obj.transform.position, obj.transform.rotation, new figData.circle(thisCircleRef.centerPos, thisCircleRef.edgePos, thisCircleRef.normalDir), thisObjDef, dependencyList, GeoObjType.circle)); break; case GeoObjType.sphere: thisObjDef = determineDef(obj, GeoObjType.sphere); AbstractSphere thisSphereRef = obj.GetComponent <AbstractSphere>(); HW_GeoSolver.ins.geomanager.neighborsOfNode(thisSphereRef.figName).ToList() .ForEach(d => dependencyList.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractGeoObj>().figName)); GeoObjDB.list.Add(new GeoObj(obj.figName, obj.transform.position, obj.transform.rotation, new figData.sphere(thisSphereRef.edgePosition), thisObjDef, dependencyList, GeoObjType.sphere)); break; case GeoObjType.revolvedsurface: thisObjDef = determineDef(obj, GeoObjType.revolvedsurface); AbstractRevolvedSurface thisRevSurfRef = obj.GetComponent <AbstractRevolvedSurface>(); HW_GeoSolver.ins.geomanager.neighborsOfNode(thisRevSurfRef.figName).ToList() .ForEach(d => dependencyList.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractGeoObj>().figName)); GeoObjDB.list.Add(new GeoObj(obj.figName, obj.transform.position, obj.transform.rotation, new figData.revSurf(thisRevSurfRef.normalDirection), thisObjDef, dependencyList, GeoObjType.revolvedsurface)); break; //case GeoObjType.torus: // thisObjDef = determineDef(obj, GeoObjType.torus); // Case doesn't exist yet. // break; case GeoObjType.flatface: thisObjDef = GeoObjDef.none; GeoObjDB.list.Add(new GeoObj(obj.name, obj.transform.position, obj.transform.rotation, thisObjDef, GeoObjType.flatface)); break; case GeoObjType.straightedge: thisObjDef = GeoObjDef.none; GeoObjDB.list.Add(new GeoObj(obj.name, obj.transform.position, obj.transform.rotation, thisObjDef, GeoObjType.straightedge)); break; default: Debug.Log("Object type not supported within XMLManager! " + obj.figType + " was attempted and failed to serialize."); break; } } if (!clear) { GeoObjDB.list.Distinct(); //if you dont clear the list then remove exact duplicates } }
// Use this for initialization private void Start() { volumeLineRenderer = GetComponentInChildren <LineRenderer>(); TMPro = GetComponentInChildren <TextMeshPro>(); myAudioSource = GetComponent <AudioSource>(); xLen = .1f; controllPoint = GeoObjConstruction.iPoint(this.transform.position); prismBase.Add(controllPoint); prismBase.Add(GeoObjConstruction.dPoint(controllPoint.Position3 + Vector3.right * (sideLength1 - 2 * xLen))); prismBase.Add(GeoObjConstruction.dPoint(controllPoint.Position3 + Vector3.right * (sideLength1 - 2 * xLen) + Vector3.forward * (sideLength2 - 2 * xLen))); prismBase.Add(GeoObjConstruction.dPoint(controllPoint.Position3 + Vector3.forward * (sideLength2 - 2 * xLen))); List <AbstractLineSegment> prismBaseLines = new List <AbstractLineSegment>(); for (int i = 0; i < 3; i++) { prismBaseLines.Add(GeoObjConstruction.dLineSegment(prismBase[i], prismBase[i + 1])); } prismBaseLines.Add(GeoObjConstruction.dLineSegment(prismBase[prismBase.Count - 1], prismBase[0])); prismBasePoly = GeoObjConstruction.dPolygon(prismBaseLines, prismBase); prism = GeoObjConstruction.dPrism(prismBasePoly, prismBasePoly.center + Vector3.up * xLen); prismTopPoly = prism.bases[1]; cutoutRectangle.Add(prismBase[0]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[0].Position3 + Vector3.back * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[1].Position3 + Vector3.back * xLen)); cutoutRectangle.Add(prismBase[1]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[1].Position3 + Vector3.right * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[2].Position3 + Vector3.right * xLen)); cutoutRectangle.Add(prismBase[2]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[2].Position3 + Vector3.forward * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[3].Position3 + Vector3.forward * xLen)); cutoutRectangle.Add(prismBase[3]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[3].Position3 + Vector3.left * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[0].Position3 + Vector3.left * xLen)); List <AbstractLineSegment> cutoutLines = new List <AbstractLineSegment>(); for (int i = 0; i < cutoutRectangle.Count - 1; i++) { cutoutLines.Add(GeoObjConstruction.dLineSegment(cutoutRectangle[i], cutoutRectangle[i + 1])); } cutoutLines.Add(GeoObjConstruction.dLineSegment(cutoutRectangle[0], cutoutRectangle[cutoutRectangle.Count - 1])); cutoutRectanglePoly = GeoObjConstruction.dPolygon(cutoutLines, cutoutRectangle); foreach (MasterGeoObj mgo in prism.transform.parent.GetComponentsInChildren <MasterGeoObj>()) { if (mgo != controllPoint) { mgo.LeapInteraction = false; } } controllPoint.GetComponent <Leap.Unity.Interaction.InteractionBehaviour>().OnGraspedMovement += updateDiagram; controllPoint.GetComponent <Leap.Unity.Interaction.InteractionBehaviour>().OnGraspEnd += updateDiagram; volumeLineRenderer.useWorldSpace = false; Color tmp = Color.blue; tmp.a = .5f; cutoutRectanglePoly.figColor = tmp; foreach (AbstractPolygon poly in prism.allfaces) { tmp = Color.red; tmp.a = .5f; poly.figColor = tmp; } prism.bases[0].figColor = Color.clear; }
internal void Start() { shearingLabManager labMan = FindObjectOfType <shearingLabManager>(); labMan.measurementDisplays.Add(surfaceAreaModel.transform); labMan.measurementDisplays.Add(volumeModel.transform); //labMan.measurementDisplays.Add(crossSectionModel.transform); labMan.disableDisplays(); surfaceAreaModel.GetComponent <MeshRenderer>().materials[0].color = mgoColor; volumeModel.GetComponent <MeshRenderer>().materials[0].color = mgoColor; crossSectionModel.GetComponent <MeshRenderer>().materials[0].color = mgoColor; //copy into base scene on Load. //this.transform.parent = SceneManager.GetSceneByName("HandWaverBase").GetRootGameObjects()[0].transform.parent; //construct parallel planes flatface1 = flatlandSurface.Constructor(); flatface2 = flatlandSurface.Constructor(); flatface1.otherFlatlandSurface = flatface2; flatface2.otherFlatlandSurface = flatface1; flatface1.transform.localScale = new Vector3(3f, .0001f, 3f); flatface2.transform.localScale = new Vector3(3f, .0001f, 3f); AbstractPoint apexPoint = GeoObjConstruction.iPoint(Vector3.ProjectOnPlane(this.transform.position, Vector3.up) + Vector3.up * height2); AbstractPolygon basePoly = GeoObjConstruction.rPoly(nSides, .3f, Vector3.ProjectOnPlane(this.transform.position, Vector3.up) + Vector3.up * height1); myPyramid = GeoObjConstruction.dPyramid(basePoly, apexPoint); foreach (AbstractLineSegment line in myPyramid.allEdges) { line.LeapInteraction = false; } foreach (AbstractPoint point in basePoly.pointList) { point.LeapInteraction = false; flatface1.attachedObjs.Add(point); } foreach (AbstractPolygon face in myPyramid.allfaces) { face.LeapInteraction = false; } flatface2.attachedObjs.Add(apexPoint); flatface2.attachedObjs.Add(basePoly); myPyramid.GetComponent <InteractionBehaviour>().enabled = false; mf.transform.position = Vector3.zero; mf.transform.localScale = Vector3.one; mf.transform.rotation = Quaternion.identity; palmDetectors = GetComponentsInChildren <PalmDirectionDetector>(); //NATHAN HELP ME HERE for (int i = 0; i < palmDetectors.Length; i++) { PalmDirectionDetector palm = palmDetectors[i]; palm.OnActivate.AddListener(startUpdateMesh); palm.OnDeactivate.AddListener(endUpdateMesh); ExtendedFingerDetector finger = palm.GetComponent <ExtendedFingerDetector>(); finger.OnDeactivate.AddListener(endUpdateMesh); //the extended finger detectors are set to enable/disable the respective PalmDirectionDetectors. switch (i) { case 0: palm.HandModel = leapHandDataLogger.ins.currHands.Lhand_rigged; finger.HandModel = leapHandDataLogger.ins.currHands.Lhand_rigged; break; case 1: palm.HandModel = leapHandDataLogger.ins.currHands.RHand_rigged; finger.HandModel = leapHandDataLogger.ins.currHands.RHand_rigged; break; default: break; } } updateMesh = updateMeshRoutine(); if (overrideHandInput) { startUpdateMesh(); } foreach (AbstractPolygon face in myPyramid.allfaces) { face.figColor = mgoColor; } myPyramid.apex.GetComponent <InteractionBehaviour>().OnGraspEnd += constantVelOutOfRange; labMan.addApexToList(myPyramid.apex); }
private void polyCut() { List <AbstractPolygon> prevPointPolygons = new List <AbstractPolygon>(); List <AbstractPolygon> currPointPolygons = new List <AbstractPolygon>(); HW_GeoSolver.ins.geomanager.bidirectionalNeighborsOfNode(_prevPoint.figName) //all bidirectional neighbors .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>() != null).ToList() // list of all abstractpolygons in prev list .ForEach(d => prevPointPolygons.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>())); //foreach adds the polygon to final list HW_GeoSolver.ins.geomanager.bidirectionalNeighborsOfNode(_currPoint.figName) //same as above but with other point .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>() != null).ToList() .ForEach(d => currPointPolygons.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>())); //prevPointPolygons.ForEach(p => Debug.Log(_prevPoint.figName + " is in the following: " + p.figName)); //Debug.Log("_____+_____"); //currPointPolygons.ForEach(p => Debug.Log(_currPoint.figName + " is in the following: " + p.figName)); //Debug.Log("_____=_____"); List <AbstractPolygon> sharedPolygons; if (prevPointPolygons.Count > currPointPolygons.Count) { sharedPolygons = prevPointPolygons.Intersect(currPointPolygons).Where(poly => poly.lineList.Count > 3).ToList(); } else { sharedPolygons = currPointPolygons.Intersect(prevPointPolygons).Where(poly => poly.lineList.Count > 3).ToList(); } //sharedPolygons.ForEach(p => Debug.Log("Both are in the following: " + p.figName)); //list created from any duplicates from two prev lists that have more than 3 sides //Debug.Log(_prevPoint.figName + " and " + _currPoint.figName + " are both on " + sharedPolygons.Count + " together."); if (sharedPolygons.Count > 0) { DependentLineSegment cutLine = GeoObjConstruction.dLineSegment(_prevPoint, _currPoint); foreach (AbstractPolygon p in sharedPolygons) { List <AbstractPoint> currPointList = p.pointList; List <AbstractLineSegment> currLineList = p.lineList; if (Mathf.Abs(currPointList.IndexOf(_prevPoint) - currPointList.IndexOf(_currPoint)) > 1) { List <AbstractPoint> newPointList1 = newPointListGen(currPointList, currPointList.IndexOf(_prevPoint), currPointList.IndexOf(_currPoint)); List <AbstractPoint> newPointList2 = newPointListGen(currPointList, currPointList.IndexOf(_currPoint), currPointList.IndexOf(_prevPoint)); List <AbstractLineSegment> newLineList1 = new List <AbstractLineSegment>() { cutLine }; //creates list and adds the line created by the cut List <AbstractLineSegment> newLineList2 = new List <AbstractLineSegment>() { cutLine }; //creates list and adds the line created by the cut foreach (AbstractLineSegment currLine in currLineList //newLineList1 Generator .Where(cL => ((cL.GetComponent <InteractableLineSegment>() != null && //is interactable line segment and point1 or point2 is found in newPointList1 newPointList1.Any(point => point == cL.GetComponent <InteractableLineSegment>().point1 || point == cL.GetComponent <InteractableLineSegment>().point2)) || ((cL.GetComponent <DependentLineSegment>() != null && //is dependent line segment and point1 or point2 is found in newPointList1 newPointList1.Any(point => point == cL.GetComponent <DependentLineSegment>().point1 || point == cL.GetComponent <DependentLineSegment>().point2)))))) { newLineList1.Add(currLine); } foreach (AbstractLineSegment currLine in currLineList //newLineList2 Generator .Where(cL => ((cL.GetComponent <InteractableLineSegment>() != null && //is interactable line segment and point1 or point2 is found in newPointList1 newPointList2.Any(point => point == cL.GetComponent <InteractableLineSegment>().point1 || point == cL.GetComponent <InteractableLineSegment>().point2)) || ((cL.GetComponent <DependentLineSegment>() != null && //is dependent line segment and point1 or point2 is found in newPointList1 newPointList2.Any(point => point == cL.GetComponent <DependentLineSegment>().point1 || point == cL.GetComponent <DependentLineSegment>().point2)))))) { newLineList2.Add(currLine); } AbstractPolygon newPoly1 = GeoObjConstruction.iPolygon(newLineList1, newPointList1); AbstractPolygon newPoly2 = GeoObjConstruction.iPolygon(newLineList2, newPointList2); List <InteractablePrism> currPrismList = new List <InteractablePrism>(); HW_GeoSolver.ins.geomanager.bidirectionalNeighborsOfNode(p.figName) //all bidirectional neighbors .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <InteractablePrism>() != null).ToList().ForEach(prism => currPrismList.Add(prism.mytransform.GetComponent <InteractablePrism>())); foreach (InteractablePrism cPrism in currPrismList) { HW_GeoSolver.ins.AddDependence(newPoly1, cPrism); HW_GeoSolver.ins.AddDependence(newPoly2, cPrism); } HW_GeoSolver.ins.removeComponent(p); } } } }
internal void Start() { shearingLabManager labMan = FindObjectOfType <shearingLabManager>(); labMan.measurementDisplays.Add(areaModel.transform); labMan.measurementDisplays.Add(perimeterModel.transform); //labMan.measurementDisplays.Add(crossSectionModel.transform); labMan.disableDisplays(); areaModel.GetComponent <MeshRenderer>().materials[0].color = mgoColor; perimeterModel.GetComponent <LineRenderer>().materials[0].color = mgoColor; crossSectionModel.GetComponent <LineRenderer>().materials[0].color = mgoColor; line1 = parallelLines.Constructor(); parallelLines line2 = parallelLines.Constructor(); line1.Position3 = Vector3.ProjectOnPlane(this.transform.position, Vector3.up) + Vector3.up * height2; line2.Position3 = Vector3.ProjectOnPlane(this.transform.position, Vector3.up) + Vector3.up * height1; line1.otherLine = line2; line2.otherLine = line1; AbstractPoint p1 = GeoObjConstruction.iPoint(line1.Position3); AbstractPoint p2 = GeoObjConstruction.iPoint(line2.Position3); AbstractPoint p3 = GeoObjConstruction.iPoint(line2.Position3 + line2.normalDir * 0.3f); p1.GetComponent <InteractionBehaviour>().OnGraspedMovement += checkOutOfRange; p1.GetComponent <InteractionBehaviour>().OnGraspEnd += constantVelOutOfRange; labMan.addApexToList(p1); //line not on Parallel l1 = GeoObjConstruction.dLineSegment(p1, p2); //line not on parallel l2 = GeoObjConstruction.dLineSegment(p1, p3); //line on parallel AbstractLineSegment l3 = GeoObjConstruction.dLineSegment(p3, p2); line1.attachedObjs.Add(p1); line2.attachedObjs.Add(p2); line2.attachedObjs.Add(p3); points.Add(p1); points.Add(p2); points.Add(p3); lines.Add(l1); lines.Add(l2); lines.Add(l3); triangle = GeoObjConstruction.dPolygon(lines, points); foreach (AbstractLineSegment line in lines) { line.GetComponent <InteractionBehaviour>().enabled = false; } triangle.GetComponent <InteractionBehaviour>().enabled = false; myLR = GetComponent <LineRenderer>(); palmDetectors = GetComponentsInChildren <PalmDirectionDetector>(); for (int i = 0; i < palmDetectors.Length; i++) { PalmDirectionDetector palm = palmDetectors[i]; palm.OnActivate.AddListener(startUpdateMesh); palm.OnDeactivate.AddListener(endUpdateMesh); ExtendedFingerDetector finger = palm.GetComponent <ExtendedFingerDetector>(); finger.OnDeactivate.AddListener(endUpdateMesh); switch (i) { case 0: palm.HandModel = leapHandDataLogger.ins.currHands.Lhand_rigged; finger.HandModel = leapHandDataLogger.ins.currHands.Lhand_rigged; break; case 1: palm.HandModel = leapHandDataLogger.ins.currHands.RHand_rigged; finger.HandModel = leapHandDataLogger.ins.currHands.RHand_rigged; break; default: break; } //the extended finger detectors are set to enable/disable the respective PalmDirectionDetectors. } updateLR = updateLR_Routine(); if (overridePalmDetector) { startUpdateMesh(); } triangle.figColor = mgoColor; movePointOnLine = animatePoint(points[0]); }