/// <summary> /// Creates a new surface game object. /// </summary> /// <param name="mesh">The mesh to attach. Can be null.</param> /// <param name="objectName">What to name this object.</param> /// <param name="parentObject">What to parent this object to.</param> /// <param name="meshID">Optional user specified ID for the mesh.</param> /// <returns>The newly created game object.</returns> protected GameObject AddSurfaceObject(Mesh mesh, string objectName, Transform parentObject, int meshID = 0) { SurfaceObject surfaceObject = new SurfaceObject(); surfaceObject.ID = meshID; surfaceObject.UpdateID = 0; surfaceObject.Object = new GameObject(objectName, componentsRequiredForSurfaceMesh); surfaceObject.Object.transform.SetParent(parentObject); surfaceObject.Object.layer = SpatialMappingManager.Instance.PhysicsLayer; surfaceObject.Filter = surfaceObject.Object.GetComponent<MeshFilter>(); surfaceObject.Filter.sharedMesh = mesh; surfaceObject.Renderer = surfaceObject.Object.GetComponent<MeshRenderer>(); surfaceObject.Renderer.sharedMaterial = RenderMaterial; SurfaceObjects.Add(surfaceObject); return surfaceObject.Object; }
/// <summary> /// Clean up the resources associated with the surface. /// </summary> /// <param name="surface">The surface whose resources will be cleaned up.</param> /// <param name="destroyGameObject"></param> /// <param name="destroyMeshes"></param> /// <param name="objectToPreserve">If the surface's game object matches this parameter, it will not be destroyed.</param> /// <param name="meshToPreserveA">If either of the surface's meshes matches this parameter, it will not be destroyed.</param> /// <param name="meshToPreserveB">If either of the surface's meshes matches this parameter, it will not be destroyed.</param> protected void CleanUpSurface( SurfaceObject surface, bool destroyGameObject = true, bool destroyMeshes = true, GameObject objectToPreserve = null, Mesh meshToPreserveA = null, Mesh meshToPreserveB = null ) { if (destroyGameObject && (surface.Object != null) && (surface.Object != objectToPreserve) ) { Destroy(surface.Object); } Mesh filterMesh = surface.Filter.sharedMesh; Mesh colliderMesh = surface.Collider.sharedMesh; if (destroyMeshes && (filterMesh != null) && (filterMesh != meshToPreserveA) && (filterMesh != meshToPreserveB) ) { Destroy(filterMesh); surface.Filter.sharedMesh = null; } if (destroyMeshes && (colliderMesh != null) && (colliderMesh != filterMesh) && (colliderMesh != meshToPreserveA) && (colliderMesh != meshToPreserveB) ) { Destroy(colliderMesh); surface.Collider.sharedMesh = null; } }
/// <summary> /// Update the first surface with a matching ID if one exists in <see cref="SurfaceObjects"/>, otherwise add the surface as new. /// </summary> /// <param name="toUpdateOrAdd">The surface to be updated or added.</param> /// <param name="destroyGameObjectIfReplaced">If a surface is updated, and a game object is being replaced, pass true to destroy the outgoing game object or false otherwise.</param> /// <param name="destroyMeshesIfReplaced">If a surface is updated, and new meshes are replacing old meshes, pass true to destroy the outgoing meshes or false otherwise.</param> /// <returns>The surface object that was updated or null if one was not found meaning a new surface was added.</returns> protected SurfaceObject?UpdateOrAddSurfaceObject(SurfaceObject toUpdateOrAdd, bool destroyGameObjectIfReplaced = true, bool destroyMeshesIfReplaced = true) { SurfaceObject?replaced = null; for (int iSurface = 0; iSurface < surfaceObjectsWriteable.Count; iSurface++) { SurfaceObject existing = surfaceObjectsWriteable[iSurface]; if (existing.ID == toUpdateOrAdd.ID) { surfaceObjectsWriteable[iSurface] = toUpdateOrAdd; var handlers = SurfaceUpdated; if (handlers != null) { handlers(this, DataEventArgs.Create(new SurfaceUpdate { Old = existing, New = toUpdateOrAdd })); } CleanUpSurface( existing, destroyGameObjectIfReplaced, destroyMeshesIfReplaced, objectToPreserve: toUpdateOrAdd.Object, meshToPreserveA: toUpdateOrAdd.Filter.sharedMesh, meshToPreserveB: toUpdateOrAdd.Collider.sharedMesh ); replaced = existing; break; } } if (replaced == null) { AddSurfaceObject(toUpdateOrAdd); } return(replaced); }
/// <summary> /// Creates a new surface game object. /// </summary> /// <param name="mesh">The mesh to attach. Can be null.</param> /// <param name="objectName">What to name this object.</param> /// <param name="parentObject">What to parent this object to.</param> /// <param name="meshID">Optional user specified ID for the mesh.</param> /// <returns>The newly created game object.</returns> protected GameObject AddSurfaceObject(Mesh mesh, string objectName, Transform parentObject, int meshID = 0) { SurfaceObject surfaceObject = new SurfaceObject(); surfaceObject.ID = meshID; surfaceObject.UpdateID = 0; surfaceObject.Object = new GameObject(objectName, componentsRequiredForSurfaceMesh); surfaceObject.Object.transform.SetParent(parentObject); surfaceObject.Object.layer = SpatialMappingManager.Instance.PhysicsLayer; surfaceObject.Filter = surfaceObject.Object.GetComponent <MeshFilter>(); surfaceObject.Filter.sharedMesh = mesh; surfaceObject.Renderer = surfaceObject.Object.GetComponent <MeshRenderer>(); surfaceObject.Renderer.sharedMaterial = RenderMaterial; SurfaceObjects.Add(surfaceObject); return(surfaceObject.Object); }
/// <summary> /// Cleans up references to objects that we have created. /// </summary> /// <param name="destroyGameObjects">True to destroy the game objects of each surface, false otherwise.</param> /// <param name="destroyMeshes">True to destroy the meshes of each surface, false otherwise.</param> protected void CleanupAfterSend(bool destroyGameObjects = true, bool destroyMeshes = true) { var deleteAmount = 3; if (surfaceObjectsWriteable.Count < deleteAmount) { //Debug.Log(System.String.Format("Not enough surfaces. {0} surfaces", surfaceObjectsWriteable.Count)); return; } var handlers = SurfaceRemoved; //var handlers = RemovingAllSurfaces; //if (handlers != null) //{ // handlers(this, EventArgs.Empty); //} var count = surfaceObjectsWriteable.Count - deleteAmount; Debug.Log(System.String.Format("{0} surfaces. DELETE {1} surfaces", surfaceObjectsWriteable.Count, count)); for (int index = 0; index < surfaceObjectsWriteable.Count; index++) { SurfaceObject surface = surfaceObjectsWriteable[index]; if (SpatialMappingManager.Instance.isSurfaceNearCamera(surface.Filter.sharedMesh.bounds)) { continue; } if (handlers != null) { handlers(this, DataEventArgs.Create(surface)); } CleanUpSurface(surface, destroyGameObjects, destroyMeshes); surfaceObjectsWriteable.RemoveAt(index); } //surfaceObjectsWriteable.Clear(); /// Remove deleted //surfaceObjectsWriteable.RemoveRange(0, count); }
private void LBObjects_SelectedIndexChanged(object sender, EventArgs e) { if (LBObjects.SelectedIndex == -1) { return; } ObjectSetElementData element = Manager.ObjectSet.Elements[LBObjects.SelectedIndex]; TBObjectName.Text = element.ElementName; TBOffsetU.Text = element.OffsetU.ToString(); TBOffsetV.Text = element.OffsetV.ToString(); TBWidth.Text = element.Size.Width.ToString(); TBHeight.Text = element.Size.Height.ToString(); SurfaceObject.DrawingRectangle = new Rectangle(element.OffsetU, element.OffsetV, element.Size.Width, element.Size.Height); SurfaceObject.Invalidate(); }
// // init surface entities // private void Init(int spawnObjectCount) { surfaceCursors = new Dictionary <int, SurfaceCursor>(); Vector3 spawnPosition = new Vector3(6f, 4.375f, 0f); surfaceObjects = new List <SurfaceObject>(spawnObjectCount); for (int i = 0; i < spawnObjectCount; i++) { SurfaceObject so = Instantiate <SurfaceObject>(surfaceObjectPrefab); surfaceObjects.Add(so); so.transform.localPosition = spawnPosition; so.transform.SetParent(transform, false); so.Init(i); } LayoutSurfaceObjects(); SortSurfaceObjects(); }
/// <summary> /// Create a new surface object. /// </summary> /// <param name="mesh">The mesh to attach. Can be null.</param> /// <param name="objectName">What to name this object.</param> /// <param name="parentObject">What to parent this object to.</param> /// <param name="meshID">Optional user specified ID for the mesh.</param> /// <param name="drawVisualMeshesOverride">If specified, overrides the default value for enabling/disabling the mesh renderer.</param> /// <param name="castShadowsOverride">If specified, overrides the default value for casting shadows.</param> /// <returns>The newly created surface object.</returns> protected SurfaceObject CreateSurfaceObject( Mesh mesh, string objectName, Transform parentObject, int meshID = 0, bool?drawVisualMeshesOverride = null, bool?castShadowsOverride = null ) { SurfaceObject surfaceObject = new SurfaceObject(); surfaceObject.ID = meshID; surfaceObject.Object = new GameObject(objectName, componentsRequiredForSurfaceMesh); surfaceObject.Object.transform.SetParent(parentObject); surfaceObject.Object.layer = SpatialMappingManager.Instance.PhysicsLayer; surfaceObject.Filter = surfaceObject.Object.GetComponent <MeshFilter>(); surfaceObject.Filter.sharedMesh = mesh; surfaceObject.Renderer = surfaceObject.Object.GetComponent <MeshRenderer>(); surfaceObject.Renderer.sharedMaterial = RenderMaterial; surfaceObject.Renderer.enabled = (drawVisualMeshesOverride ?? SpatialMappingManager.Instance.DrawVisualMeshes); surfaceObject.Renderer.shadowCastingMode = ((castShadowsOverride ?? SpatialMappingManager.Instance.CastShadows) ? ShadowCastingMode.On : ShadowCastingMode.Off); surfaceObject.Collider = surfaceObject.Object.GetComponent <MeshCollider>(); // Reset the surface mesh collider to fit the updated mesh. // Unity tribal knowledge indicates that to change the mesh assigned to a // mesh collider, the mesh must first be set to null. Presumably there // is a side effect in the setter when setting the shared mesh to null. surfaceObject.Collider.sharedMesh = null; surfaceObject.Collider.sharedMesh = surfaceObject.Filter.sharedMesh; //CTP ADDED TO MAKE ALL SURFACES BE UNDER SURFACE TAG surfaceObject.Object.gameObject.tag = "Surface"; spatialMap.Add(surfaceObject.Object.gameObject); return(surfaceObject); }
private void 불러오기ToolStripMenuItem_Click(object sender, EventArgs e) { DlgOpen.InitialDirectory = KAssetDir; DlgOpen.Filter = "오브젝트 셋 파일 (*.xml)|*.xml"; DlgOpen.DefaultExt = ".xml"; DlgOpen.FileName = ""; DlgOpen.Title = "오브젝트 셋 불러오기"; if (DlgOpen.ShowDialog() == DialogResult.OK) { Manager.LoadFromFile(DlgOpen.FileName); this.Text = "DirectX11Tutorial Object Editor: " + Manager.ObjectSet.ObjectSetName; SurfaceTexture.ClearTextures(); SurfaceTexture.AddTextureFromFile(Manager.ObjectSet.TextureFileName); SurfaceObject.ClearTextures(); SurfaceObject.AddTextureFromFile(Manager.ObjectSet.TextureFileName); SurfaceTexture.Invalidate(); SurfaceObject.Invalidate(); SSize texture_size = SurfaceTexture.GetTextureSize(0); hScrollBar1.LargeChange = KScrollDelta; hScrollBar1.Maximum = texture_size.Width / hScrollBar1.LargeChange; vScrollBar1.LargeChange = KScrollDelta; vScrollBar1.Maximum = texture_size.Height / vScrollBar1.LargeChange; LBObjects.Items.Clear(); foreach (ObjectSetElementData element in Manager.ObjectSet.Elements) { LBObjects.Items.Add(element.ElementName); } } }
/// <summary> /// Check if the triangle formed by the 3 points can correspond to the calibrated SurfaceObject /// </summary> /// <param name="obj"></param> /// <param name="points">an array of 3 points</param> /// <returns></returns> public bool DetectObject(SurfaceObject obj, Vector2[] points) { Vector2 barycentricPoint = BarycentricPoint(points); float[] distances = new float[3]; distances[0] = Vector2.Distance(points[0], barycentricPoint); distances[1] = Vector2.Distance(points[1], barycentricPoint); distances[2] = Vector2.Distance(points[2], barycentricPoint); /* Debug.Log("FirstDistance : " + distances[0]); * Debug.Log("SecondeDistance : " + distances[1]); * Debug.Log("ThirdDistance : " + distances[2]); */ for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (i != j && i != k && j != k) { if (Mathf.Abs(obj.calibratedDistances[0] - distances[i]) <= positionThreshold && Mathf.Abs(obj.calibratedDistances[1] - distances[j]) <= positionThreshold && Mathf.Abs(obj.calibratedDistances[2] - distances[k]) <= positionThreshold) { return(true); } } } } } return(false); }
// Fix the Space Center void FixCameras(GameScenes scene) { if (HighLogic.LoadedScene != GameScenes.SPACECENTER && !HighLogic.LoadedSceneIsEditor) { return; } // Get the parental body CelestialBody body = null; if (Planetarium.fetch != null) { body = Planetarium.fetch.Home; } else { body = FlightGlobals.Bodies.Find(b => b.isHomeWorld); } // If there's no body, exit. if (body == null) { Debug.Log("[Kopernicus]: Couldn't find the parental body!"); return; } // Get the KSC object PQSCity ksc = body.pqsController.GetComponentsInChildren <PQSCity>(true).Where(m => m.name == "KSC").First(); // If there's no KSC, exit. if (ksc == null) { Debug.Log("[Kopernicus]: Couldn't find the KSC object!"); return; } // Go throug the SpaceCenterCameras and fix them foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { if (ksc.repositionToSphere || ksc.repositionToSphereSurface) { double normalHeight = body.pqsController.GetSurfaceHeight((Vector3d)ksc.repositionRadial.normalized) - body.Radius; if (ksc.repositionToSphereSurface) { normalHeight += ksc.repositionRadiusOffset; } cam.altitudeInitial = 0f - (float)normalHeight; } else { cam.altitudeInitial = 0f - (float)ksc.repositionRadiusOffset; } // re-implement cam.Start() // fields Type camType = cam.GetType(); FieldInfo camPQS = null; FieldInfo transform1 = null; FieldInfo transform2 = null; FieldInfo surfaceObj = null; // get fields FieldInfo[] fields = camType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); for (int i = 0; i < fields.Length; ++i) { FieldInfo fi = fields[i]; if (fi.FieldType == typeof(PQS)) { camPQS = fi; } else if (fi.FieldType == typeof(Transform) && transform1 == null) { transform1 = fi; } else if (fi.FieldType == typeof(Transform) && transform2 == null) { transform2 = fi; } else if (fi.FieldType == typeof(SurfaceObject)) { surfaceObj = fi; } } if (camPQS != null && transform1 != null && transform2 != null && surfaceObj != null) { camPQS.SetValue(cam, body.pqsController); Transform initialTransform = body.pqsController.transform.Find(cam.initialPositionTransformName); if (initialTransform != null) { transform1.SetValue(cam, initialTransform); cam.transform.NestToParent(initialTransform); } else { Debug.Log("SSC2 can't find initial transform!"); Transform initialTrfOrig = transform1.GetValue(cam) as Transform; if (initialTrfOrig != null) { cam.transform.NestToParent(initialTrfOrig); } else { Debug.Log("SSC2 own initial transform null!"); } } Transform camTransform = transform2.GetValue(cam) as Transform; if (camTransform != null) { camTransform.NestToParent(cam.transform); if (FlightCamera.fetch != null && FlightCamera.fetch.transform != null) { FlightCamera.fetch.transform.NestToParent(camTransform); } if (LocalSpace.fetch != null && LocalSpace.fetch.transform != null) { LocalSpace.fetch.transform.position = camTransform.position; } } else { Debug.Log("SSC2 cam transform null!"); } cam.ResetCamera(); SurfaceObject so = surfaceObj.GetValue(cam) as SurfaceObject; if (so != null) { so.ReturnToParent(); DestroyImmediate(so); } else { Debug.Log("SSC2 surfaceObject is null!"); } surfaceObj.SetValue(cam, SurfaceObject.Create(initialTransform.gameObject, FlightGlobals.currentMainBody, 3, KFSMUpdateMode.FIXEDUPDATE)); Debug.Log("[Kopernicus]: Fixed SpaceCenterCamera"); } else { Debug.Log("[Kopernicus]: ERROR fixing space center camera, could not find some fields"); } } }
/// <summary> /// Begins to walk on a mesh providing the geodesics. /// Begins at the center of the triangle startSpot. /// </summary> public void GetReady(Geometry g, HeatGeodesics nav, Face startSpot) { coord = new SurfaceObject(g, nav, startSpot); UpdatePosition(); ready = true; }
protected override string OnInit() { surfaceObject = SurfaceObjectDetector.Instance.GetSurfaceObject(surfaceObjectID); return(base.OnInit()); }
/// <summary> /// Updates an existing surface object. /// </summary> /// <param name="gameObject">Game object reference to the surfaceObject.</param> /// <param name="meshID">User specified ID for the mesh.</param> /// <returns>True if successful</returns> protected void UpdateSurfaceObject(GameObject gameObject, int meshID) { // If it's in the list, update it for (int i = 0; i < SurfaceObjects.Count; ++i) { if (SurfaceObjects[i].Object == gameObject) { SurfaceObject thisSurfaceObject = SurfaceObjects[i]; thisSurfaceObject.ID = meshID; thisSurfaceObject.UpdateID++; SurfaceObjects[i] = thisSurfaceObject; return; } } // Not in the list, add it SurfaceObject surfaceObject = new SurfaceObject(); surfaceObject.ID = meshID; surfaceObject.UpdateID = 0; surfaceObject.Object = gameObject; surfaceObject.Filter = surfaceObject.Object.GetComponent<MeshFilter>(); surfaceObject.Renderer = surfaceObject.Object.GetComponent<MeshRenderer>(); SurfaceObjects.Add(surfaceObject); }
public static void AnimScale(this SurfaceObject self, double factor) { Animation.Animator.Resize(self.ScaleTransform, factor); self.HasResizeAnimation = true; }
public static void AnimMove(this SurfaceObject self, Point pt) { Animation.Animator.Move(self, pt.X, pt.Y); self.HasMovingAnimation = true; }
// Update is called once per frame. private void Update() { // If we have a connected client, presumably the client wants to send some meshes. if (clientConnected) { // Get the clients stream. NetworkStream stream = networkClient.GetStream(); // Make sure there is data in the stream. if (stream.DataAvailable) { // The first 4 bytes will be the size of the data containing the mesh(es). int datasize = ReadInt(stream); // Allocate a buffer to hold the data. byte[] dataBuffer = new byte[datasize]; // Read the data. // The data can come in chunks. int readsize = 0; while (readsize != datasize) { readsize += stream.Read(dataBuffer, readsize, datasize - readsize); } if (readsize != datasize) { Debug.Log("reading mesh failed: " + readsize + " != " + datasize); } // Pass the data to the mesh serializer. List <Mesh> meshes = new List <Mesh>(SimpleMeshSerializer.Deserialize(dataBuffer)); // For each mesh, create a GameObject to render it. for (int index = 0; index < meshes.Count; index++) { int meshID = SurfaceObjects.Count; SurfaceObject surface = CreateSurfaceObject( mesh: meshes[index], objectName: "Beamed-" + meshID, parentObject: transform, meshID: meshID ); surface.Object.transform.parent = SpatialMappingManager.Instance.transform; AddSurfaceObject(surface); } // Finally disconnect. clientConnected = false; networkClient.Close(); // And wait for the next connection. AsyncCallback callback = OnClientConnect; networkListener.BeginAcceptTcpClient(callback, this); } } }
public void StartCalibration(SurfaceObject obj) { this.currentState = State.CALIBRATING; this.calibratingSurfaceObject = obj; obj.isCalibrated = false; }
/// <summary> /// Handles the SurfaceObserver's OnDataReady event. /// </summary> /// <param name="cookedData">Struct containing output data.</param> /// <param name="outputWritten">Set to true if output has been written.</param> /// <param name="elapsedCookTimeSeconds">Seconds between mesh cook request and propagation of this event.</param> private void SurfaceObserver_OnDataReady(SurfaceData cookedData, bool outputWritten, float elapsedCookTimeSeconds) { if (outstandingMeshRequest == null) { Debug.LogErrorFormat("Got OnDataReady for surface {0} while no request was outstanding.", cookedData.id.handle ); return; } if (!IsMatchingSurface(outstandingMeshRequest.Value, cookedData)) { Debug.LogErrorFormat("Got mismatched OnDataReady for surface {0} while request for surface {1} was outstanding.", cookedData.id.handle, outstandingMeshRequest.Value.ID ); ReclaimSurface(outstandingMeshRequest.Value); outstandingMeshRequest = null; return; } if (ObserverState != ObserverStates.Running) { Debug.LogFormat("Got OnDataReady for surface {0}, but observer was no longer running.", cookedData.id.handle ); ReclaimSurface(outstandingMeshRequest.Value); outstandingMeshRequest = null; return; } if (!outputWritten) { ReclaimSurface(outstandingMeshRequest.Value); outstandingMeshRequest = null; return; } Debug.Assert(outstandingMeshRequest.Value.Object.activeSelf); // alters properites of mesh as desired: first sets renderer enabled field outstandingMeshRequest.Value.Renderer.enabled = SpatialMappingManager.Instance.DrawVisualMeshes; // create extra data SurfaceObject tmpSO = outstandingMeshRequest.Value; Transform tmpTransform = tmpSO.Renderer.transform; // Wvertices List <Vector3> tmpWvertices = tmpSO.Filter.sharedMesh.vertices.ToList(); for (int i = 0; i < tmpWvertices.Count; i++) { tmpWvertices[i] = tmpTransform.TransformPoint(tmpWvertices[i]); } // TriCount int tmpTriCount = tmpSO.Filter.sharedMesh.triangles.ToList().Count; // SurfacePoints obj SurfacePoints extras = new SurfacePoints( MeshManager.IntersectionPoints(outstandingMeshRequest.Value.Renderer.bounds), tmpWvertices, tmpTriCount, tmpSO.Renderer.bounds, cookedData.trianglesPerCubicMeter); // updates/adds mesh in source stored list of SurfaceObjects. SurfaceObject?replacedSurface = UpdateOrAddSurfaceObject(outstandingMeshRequest.Value, extras, destroyGameObjectIfReplaced: false); outstandingMeshRequest = null; if (replacedSurface != null) { ReclaimSurface(replacedSurface.Value); } }
// Update is called once per frame void Update() { line.enabled = false; // Find the triangle and the closest vertex the mouse is pointing to Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit info; bool pressingAlt = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); cursor.transform.position = new Vector3(1000, 0, 0); heatInfo.rectTransform.position = new Vector3(10000, 0, 0); if ((clicking || pressingAlt) && Physics.Raycast(ray, out info)) { if (info.triangleIndex != -1) { Face f = g.faces[info.triangleIndex]; // Find the closest vertex to the mouse in the hit triangle f.FillEdgeArray(); Vertex v = f.edges[0].vertex; if ((f.edges[1].vertex.p - info.point).sqrMagnitude < (v.p - info.point).sqrMagnitude) v = f.edges[1].vertex; if ((f.edges[2].vertex.p - info.point).sqrMagnitude < (v.p - info.point).sqrMagnitude) v = f.edges[2].vertex; f.ClearEdgeArray(); if (pressingAlt) { // Show vertex info cursor.transform.position = v.p; Vector3 vertScreenPoint = cam.WorldToScreenPoint(v.p); heatInfo.rectTransform.position = new Vector3(Mathf.Round(vertScreenPoint.x) + 170, Mathf.Round(vertScreenPoint.y) - 42, 0); heatInfo.text = "Vertex distance = " + hg.phi[v.index]; heatInfo.text += "\nVertex heat = " + hg.u[v.index]; heatInfo.text += "\nVertex index = " + v.index; if (hg.s.Contains(v)) { heatInfo.text += "\n<color=#22FF00>Source vertex</color>"; } if (v.onBorder) { heatInfo.text += "\n<color=#ff2200>Boundary vertex</color>"; } // Trace the shortest path line.enabled = true; SurfaceObject obj = new SurfaceObject(g, hg, f, info.point); List<Vector3> traj = obj.GoForward(500, 500, 0.001f); line.SetVertexCount(traj.Count); int i = 0; foreach (Vector3 pt in traj) { line.SetPosition(i, pt); i++; } } // When clicking on the surface of the mesh, reset source if (clicking) { Debug.Log("triangle hit = " + info.triangleIndex); Debug.Log("vertex hit = " + v.index); // Set the source bool wholeLine = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); bool additional = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) || wholeLine; List<Vertex> lineSources = null; if (!wholeLine) { hg.CalculateGeodesics(v, additional); } else { DijkstraEdgePathFinding deef = new DijkstraEdgePathFinding(g, lastClickedVertex); lineSources = deef.GetPathFrom(v); hg.CalculateGeodesics(lineSources, true); } warning.gameObject.SetActive(additional && Settings.useCholesky && Settings.useAccurateMultisource); // Put the mark at the source vertex if (!additional) { foreach (GameObject oldPin in pins) { Destroy(oldPin); } pins.Clear(); } if (!wholeLine) { GameObject newPin = Instantiate(pin); pins.Add(newPin); newPin.transform.position = v.p; newPin.transform.rotation = Quaternion.LookRotation(v.CalculateNormalTri()); } else { foreach (Vertex vert in lineSources) { GameObject newPin = Instantiate(pin); pins.Add(newPin); newPin.transform.position = vert.p; newPin.transform.rotation = Quaternion.LookRotation(vert.CalculateNormalTri()); } } lastClickedVertex = v; // Hide tutorial text if (firstClick) { tutorial.gameObject.SetActive(false); firstClick = false; } UpdateVisualGradient(); } } } clicking = false; // User changed the boundary condition through the slider if (Input.GetMouseButtonUp(0) && changedBoundaryCond >= 0) { Settings.boundaryCondition = changedBoundaryCond; useDefaultSettings = false; SetLevel(levelIndex); useDefaultSettings = true; changedBoundaryCond = -1; } // Scrolling the surface texture offset -= Settings.ScrollSpeed * Time.deltaTime; mainMat.mainTextureOffset = new Vector2(offset, 0); // Emission texture animation Material mat = mainMat; if (textureIndex == 2) { float T = 6f; t = (t + Time.deltaTime) % T; mat.SetColor("_EmissionColor", anim1.GetColor(t / T)); Settings.ScrollSpeed = (t < T / 2 || t > T - 0.1f) ? 0.08f : 0.04f; } else if (textureIndex == 3) { float tPeriod = 7f, tLight = 3f; t = (t + Time.deltaTime) % tPeriod; if (t < tLight) { float cos = Mathf.Cos(Mathf.PI * (t - tLight / 2) / tLight); float c = 0.7f * cos; Settings.ScrollSpeed = 0.05f * (1 - 0.9f * cos); mat.SetColor("_EmissionColor", new Color(c, c, c)); } else { mat.SetColor("_EmissionColor", new Color(0f, 0f, 0f)); } } else if (textureIndex == 6) { float tPeriod = 4f, tLight = 1f; t = (t + Time.deltaTime) % tPeriod; float tt = t % tLight; if (t / tLight < 3) { float cos = Mathf.Cos(Mathf.PI * (tt - tLight / 2) / tLight); float c = 0.9f * cos; mat.SetColor("_EmissionColor", new Color(c, c, c)); } else { mat.SetColor("_EmissionColor", new Color(0f, 0f, 0f)); } fire.enableEmission = t / tLight > 3 && t / tLight < 3.8f; } // Press P to stop animation if (Input.GetKey(KeyCode.P)) { Time.timeScale = Mathf.Max(0f, Time.timeScale - 1f * Time.unscaledDeltaTime); } else { Time.timeScale = Mathf.Min(1f, Time.timeScale + 1f * Time.unscaledDeltaTime); } // Press I to toggle background skybox if (Input.GetKeyDown(KeyCode.I)) { useBlankSky = !useBlankSky; RenderSettings.skybox = useBlankSky ? blankSky : sky; } // Press O to show/hide walking man if (Input.GetKeyDown(KeyCode.O)) { foreach (MeshRenderer renderer in man.gameObject.GetComponentsInChildren<MeshRenderer>()) { renderer.enabled = !renderer.enabled; } } // Press +/- to change UI size if (Input.GetKeyDown(KeyCode.Equals)) { canvasScaler.scaleFactor *= 1.1f; } if (Input.GetKeyDown(KeyCode.Minus)) { canvasScaler.scaleFactor /= 1.1f; } // Quit the application if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } }
public static void AnimRotate(this SurfaceObject self, double angle) { Animation.Animator.Rotate(self.RotateTransform, angle); self.HasRotateAnimation = true; }
public ChooseEndPointType(SurfaceObject obj) : base(obj) { InitializeComponent(); }
public static void AnimFadeIn(this SurfaceObject self) { Animation.Animator.FadeIn(self); }
public MessageDialog(SurfaceObject parent) : this(parent, OptionTypes.Close) { }