//-------------------------------------------------------------------------------------------------- public void EnableClipPlane(bool enable) { if (enable) { if (_ClipPlane != null) { return; } var sketchPlane = Sketch.Plane; var reversedPlane = new Pln(new Ax3(sketchPlane.Location, sketchPlane.Axis.Direction.Reversed())); reversedPlane.Translate(reversedPlane.Axis.Direction.Reversed().ToVec().Scaled(0.0001)); _ClipPlane = new ClipPlane(reversedPlane); _ClipPlane.AddViewport(WorkspaceController.ActiveViewport); WorkspaceController.Invalidate(); RaisePropertyChanged(nameof(ClipPlaneEnabled)); } else { if (_ClipPlane == null) { return; } _ClipPlane.Remove(); _ClipPlane = null; WorkspaceController.Invalidate(); RaisePropertyChanged(nameof(ClipPlaneEnabled)); } }
public static void Run(Tekla.Technology.Akit.IScript akit) { ModelViewEnumerator ViewEnum = ViewHandler.GetVisibleViews(); while (ViewEnum.MoveNext()) { ; } { View ActiveView = ViewEnum.Current; ClipPlaneCollection ClipPlanes = ActiveView.GetClipPlanes(); if (ClipPlanes.Count > 0) { IEnumerator PlaneEnum = ClipPlanes.GetEnumerator(); while (PlaneEnum.MoveNext()) { ClipPlane CPlane = PlaneEnum.Current as ClipPlane; if (CPlane != null) { CPlane.Delete(); } } } } }
internal void RenderShadowMap(Camera camera, ShadowBox shadows, ClipPlane clipPlane = ClipPlane.None) { GL.UseProgram(shadowShader.Program); GL.UniformMatrix4(shadowShader.ViewMatrix, false, ref shadows.ViewMatrix); GL.UniformMatrix4(shadowShader.ProjectionMatrix, false, ref shadows.ProjectionMatrix); GL.UniformMatrix4(shadowShader.WorldMatrix, false, ref worldTransform); GL.Uniform3(shadowShader.CameraPosition, camera.Position); GL.Uniform1(shadowShader.TessFactor, TerrainConfig.TessFactor); GL.Uniform1(shadowShader.TessSlope, TerrainConfig.TessSlope); GL.Uniform1(shadowShader.TessShift, TerrainConfig.TessShift); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, HeightMap.Texture); GL.Uniform1(shadowShader.HeightMap, 0); GL.Uniform1(shadowShader.HeightMapScale, TerrainConfig.HeightMapScale); GL.Uniform1(shadowShader.ClipPlane, (int)clipPlane); for (int i = 0; i < 8; i++) { GL.Uniform1(shadowShader.LodMorphAreas[i], TerrainConfig.LodMorphAreas[i]); } GL.BindVertexArray(vaoId); GL.EnableVertexAttribArray(0); quadTree.Render(shadows.ShadowFrustumPlanes, shadowShader); GL.BindVertexArray(0); }
public static dynamic GetTSObject(ClipPlane dynObject) { if (dynObject is null) { return(null); } return(dynObject.teklaObject); }
public void Render(Camera camera, Light light, ShadowBox shadows, ClipPlane clipPlane = ClipPlane.None) { GL.UseProgram(shader.Program); shader.ApplyCamera(camera); shader.ApplyLight(light); shader.ApplyShadows(shadows); GL.UniformMatrix4(shader.WorldMatrix, false, ref worldTransform); GL.Uniform1(shader.TessFactor, TerrainConfig.TessFactor); GL.Uniform1(shader.TessSlope, TerrainConfig.TessSlope); GL.Uniform1(shader.TessShift, TerrainConfig.TessShift); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, HeightMap.Texture); GL.Uniform1(shader.HeightMap, 0); GL.Uniform1(shader.HeightMapScale, TerrainConfig.HeightMapScale); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, NormalMap.Texture.TextureId); GL.Uniform1(shader.NormalMap, 1); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2DArray, texture.TextureId); GL.Uniform1(shader.Texture, 2); GL.ActiveTexture(TextureUnit.Texture3); GL.BindTexture(TextureTarget.Texture2DArray, SplatMap.Texture); GL.Uniform1(shader.SplatMap, 3); GL.Uniform1(shader.SplatCount, TerrainConfig.Textures.Length); GL.ActiveTexture(TextureUnit.Texture4); GL.BindTexture(TextureTarget.Texture2D, textureNoise.Texture); GL.Uniform1(shader.TextureNoise, 4); GL.Uniform1(shader.ClipPlane, (int)clipPlane); GL.Uniform1(shader.GridLines, State.ShowGridLines ? 1 : 0); GL.Uniform3(shader.MousePosition, State.TerrainMousePosition); GL.Uniform1(shader.SelectionSize, State.ToolRadius); GL.Uniform4(shader.FogColor, Color.FromArgb(255, 124, 151, 185)); GL.Uniform1(shader.FarPlane, State.Far); for (int i = 0; i < 8; i++) { GL.Uniform1(shader.LodMorphAreas[i], TerrainConfig.LodMorphAreas[i]); } GL.BindVertexArray(vaoId); GL.EnableVertexAttribArray(0); quadTree.Render(camera.FrustumPlanes, shader); GL.BindVertexArray(0); }
private GameObject CopyStructure(GameObject structureToCopy) { ClipPlane cp = FindObjectOfType <ClipPlane>(); GameObject copiedStructure = (GameObject)Instantiate(structureToCopy, structureToCopy.transform.parent); copiedStructure.transform.position = structureToCopy.transform.position; copiedStructure.transform.localScale = structureToCopy.transform.localScale; foreach (Renderer rend in copiedStructure.GetComponentsInChildren <Renderer>()) { cp.AddRenderer(rend); } return(copiedStructure); }
public void RenderShadowMap(ShadowBox shadows, TerrainRenderer terrain, ClipPlane clip = ClipPlane.None) { GL.UseProgram(shadowShader.Program); GL.UniformMatrix4(shadowShader.ViewMatrix, false, ref shadows.ViewMatrix); GL.UniformMatrix4(shadowShader.ProjectionMatrix, false, ref shadows.ProjectionMatrix); GL.Uniform1(shadowShader.ClipPlane, (int)clip); assetQuadTree.Render(shadows.ShadowFrustumPlanes, shader); GL.DisableVertexAttribArray(4); GL.DisableVertexAttribArray(5); GL.DisableVertexAttribArray(6); }
public GMesh ClipGeometryToPlane(GClipPlane gcp) { GMesh clip_gm = new GMesh(); // Add the textures first for (int i = 0; i < m_tex_name.Count; i++) { #if OVERLOAD_LEVEL_EDITOR clip_gm.AddTexture(m_tex_gl_id[i], m_tex_name[i]); #else clip_gm.m_tex_name.Add(m_tex_name[i]); #endif } // Copy the clip planes for (int i = 0; i < (int)EdgeOrder.NUM; i++) { clip_gm.m_clip_plane[i] = new GClipPlane(m_clip_plane[i]); } ClipPlane cp = ClipPlane.CreateFrom3Points(gcp.edge_pos1, gcp.edge_pos2, gcp.edge_pos2 + gcp.normal); for (int i = 0; i < m_triangle.Count; i++) { CTriangle ct = new CTriangle(m_triangle[i], m_vertex[m_triangle[i].vert[0]], m_vertex[m_triangle[i].vert[1]], m_vertex[m_triangle[i].vert[2]]); ct.ClipFacePlane(cp); if (ct.clipped_verts.Length < 3) { continue; } int num_triangles = ct.clipped_verts.Length - 2; for (int clipped_tri_idx = 0; clipped_tri_idx < num_triangles; ++clipped_tri_idx) { CTriangle extracted_ct = ct.ExtractClippedTriangle(clipped_tri_idx); if (extracted_ct.HasDegenerateTriangles(false)) { continue; } clip_gm.AddFaceFromCTriangle(extracted_ct); } } return(clip_gm); }
public void ClipPlane() { var ctx = Context.Current; // The imprint we want to edit var imprint = TestGeomGenerator.CreateImprint(); var sketch = imprint.Sketch; imprint.Make(Shape.MakeFlags.None); ctx.ViewportController.ZoomFitAll(); var plane = sketch.Plane; plane.UReverse(); var clipPlane = new ClipPlane(plane); clipPlane.AddViewport(ctx.Viewport); AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ClipPlane01")); clipPlane.Remove(); AssertHelper.IsSameViewport(Path.Combine(_BasePath, "ClipPlane02")); }
public void GenerateNonClippedGeometry(Decal d, DMesh dm) { // Limit max repeats based on the size of the face // NOTE: This may not the best way to limit repeats, but it works FindBaseAttributes(d); float max_length = d.side.FindLongestDiagonal(); int max_repeats = 2 + (int)(max_length / 4f); int repeat_u = (d.repeat_u > 0 ? d.repeat_u : max_repeats); int repeat_v = (d.repeat_v > 0 ? d.repeat_v : max_repeats); int offset_u = d.offset_u; switch (d.align) { case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_UP: case DecalAlign.EDGE_LEFT: // COMPATIBILITY: Due to a bug Offset U was effectively reversed in the original 1.0.1.0 release // For backwards compatibility, retain this behaviour. offset_u = -offset_u; break; default: break; } // Get the implied offset based on the repeats int implied_offset_u = CalculateImpiedOffset(d.repeat_u, repeat_u); int implied_offset_v = CalculateImpiedOffset(d.repeat_v, repeat_v); // Adjust implied_offset_v for EDGE alignment (add 2) if (d.IsEdgeAlign()) { implied_offset_v += 2; } // Temporary DMesh to hold the dm if it has to be mirrored DMesh temp_dm = new DMesh(dm.name); temp_dm.Copy(dm); temp_dm.MaybeFlip(d.mirror); // Create repeats of the geometry for (int i = 0; i < repeat_u; i++) { for (int j = 0; j < repeat_v; j++) { // Before adding, must do WHOLE clipping (can't do it after because we don't have the data then) // Create a CQuad that covers the outline of the expected area Vector3[] v = CreateGhostQuad(m_base_pos + m_base_rvec * (implied_offset_u - offset_u + i * 4) + m_base_uvec * (implied_offset_v + d.offset_v + j * 4), m_base_rot); CTriangle ct = new CTriangle(v); bool clip = false; // See if that clips against a whole plane, if not add it for (int k = 0; k < (int)EdgeOrder.NUM; k++) { if (m_clip_plane[k].whole) { ClipPlane cp = ClipPlane.CreateFrom3Points(m_clip_plane[k].edge_pos1, m_clip_plane[k].edge_pos2, m_clip_plane[k].edge_pos2 + m_clip_plane[k].normal); if (ct.WouldBeClipped(cp)) { clip = true; } } } if (!clip) { Vector3 offset = m_base_rvec * (implied_offset_u - offset_u + i * 4) + m_base_uvec * (implied_offset_v + d.offset_v + j * 4); Vector3 gcenter = m_base_pos + offset; AddGeometry(temp_dm, gcenter); AddLights(temp_dm, gcenter); } } } // Add the textures for (int i = 0; i < dm.tex_name.Count; i++) { m_tex_name.Add(dm.tex_name[i]); #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id.Add(-1); #endif } }
public void Update() { _UpdateApplicationLifecycle(); // If the player has not touched the screen, we are done with this update. Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } // Should not handle input if the player is pointing on UI. if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { return; } // Raycast against the location the player touched to search for planes. TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. if ((hit.Trackable is DetectedPlane) && Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("Hit at back of the current DetectedPlane"); } else { // Choose the Andy model for the Trackable that got hit. GameObject prefab; if (hit.Trackable is FeaturePoint) { prefab = AndyPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = AndyVerticalPlanePrefab; } else { prefab = AndyHorizontalPlanePrefab; } } else { prefab = AndyHorizontalPlanePrefab; } if (sum > 0) { return; } if (andyObject == null) { return; } andyObject.SetActive(false); GameObject plane = GameObject.Find("Plane Generator"); sum++; plane.SetActive(false); ClipPlane clipPlane = andyObject.AddComponent <ClipPlane>(); // Instantiate Andy model at the hit pose. // var andyObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); andyObject.transform.position = new Vector3(hit.Pose.position.x, hit.Pose.position.y + 0.02f, hit.Pose.position.z); // Discovery Point Cloud //GameObject point = GameObject.Find("Discovery Point Cloud"); //if (point != null) { // Debug.Log("=====1=="); // PointcloudVisualizer pointcloudVisualizer = point.GetComponent<PointcloudVisualizer>(); // pointcloudVisualizer.OnDisable(); // point.SetActive(false); // // Destroy(point); //} // point.GetComponent<Renderer>().enabled = false; // andyObject.transform.parent = anchor.transform; // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). andyObject.transform.Rotate(0 + 0, k_ModelRotation, 0, Space.Self); // Create an anchor to allow ARCore to track the hitpoint as understanding of // the physical world evolves. var anchor = hit.Trackable.CreateAnchor(hit.Pose); // Make Andy model a child of the anchor. andyObject.transform.parent = anchor.transform; andyObject.SetActive(true); } } }
float GetVisibilityPointDistance( ) { float _desiredDistance = -1f; if (thisCamera == null) { thisCamera = GetComponent <Camera>(); if (thisCamera == null) { return(_desiredDistance); } } ClipPlane cpPonits = new ClipPlane(thisCamera); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.leftBottom,Color.blue); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.rightBottom, Color.blue); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.leftTop, Color.blue); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.rightTop, Color.blue); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.center, Color.blue); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.centerTop, Color.blue); //Debug.DrawLine(target.position + Vector3.up * 2, cpPonits.centerBottom, Color.blue); RaycastHit hitInfo; Vector3 start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.leftTop, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } // 2 точка start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.rightTop, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.leftBottom, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.rightBottom, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.center, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.centerTop, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } start = target.position + Vector3.up * 2; //Пускаем луч до тех пор, пока тег объекта столкновения не будет отличатся от "Player", либо пока не промажем for (int i = 0; i < 10; i++) { if (Physics.Linecast(start, cpPonits.centerBottom, out hitInfo)) { if (hitInfo.collider.tag == "Player") { start = hitInfo.point; } else { if ((hitInfo.distance < _desiredDistance || _desiredDistance == -1f) && hitInfo.transform.gameObject.isStatic) { _desiredDistance = hitInfo.distance; break; } } } else { break; } } return(_desiredDistance); }
public void Render(Camera camera, Light light, ShadowBox shadows, TerrainRenderer terrain, ClipPlane clip = ClipPlane.None) { GL.UseProgram(shader.Program); shader.ApplyCamera(camera); shader.ApplyLight(light); shader.ApplyShadows(shadows); GL.Uniform1(shader.ClipPlane, (int)clip); GL.Uniform4(shader.FogColor, State.ClearColor); GL.Uniform1(shader.FarPlane, State.Far); assetQuadTree.Render(camera.FrustumPlanes, shader); GL.DisableVertexAttribArray(4); GL.DisableVertexAttribArray(5); GL.DisableVertexAttribArray(6); }
/// <summary> /// Get world position coordinates of the mouse position from <paramref name="camera"/>. /// </summary> /// <param name="camera">Camera used to get world position coordinates.</param> /// <param name="clipPlane">If <c><paramref name="clipPlane"/> == <see cref="ClipPlane.Near"/></c>, <see cref="Camera.nearClipPlane"/> will be used as Z-axis distance to <paramref name="camera"/>.<br/> /// If <c><paramref name="clipPlane"/> == <see cref="ClipPlane.Far"/></c>, <see cref="Camera.farClipPlane"/> will be used.</param> /// <returns>World position coordinates.</returns> public static Vector2 GetMouseWorldPositionInGame(this Camera camera, ClipPlane clipPlane) => camera.GetMouseWorldPositionInGame(clipPlane == ClipPlane.Near ? camera.nearClipPlane : camera.farClipPlane);
/// <summary> /// Get world position coordinates of the mouse position from <see cref="Camera.main"/>. /// </summary> /// <param name="clipPlane">If <c><paramref name="clipPlane"/> == <see cref="ClipPlane.Near"/></c>, <see cref="Camera.nearClipPlane"/> will be used as Z-axis distance to <paramref name="camera"/>.<br/> /// If <c><paramref name="clipPlane"/> == <see cref="ClipPlane.Far"/></c>, <see cref="Camera.farClipPlane"/> will be used.</param> /// <returns>World position coordinates.</returns> public static Vector2 GetMouseWorldPositionInGame(ClipPlane clipPlane) => Camera.main.GetMouseWorldPositionInGame(clipPlane);