fPolylineGameObject make_path <T>(LinearToolpath3 <T> path, fMaterial material, float width, Vector3d origin) where T : IToolpathVertex { Vector3d prev = Vector3d.Zero; tempPolyLine.Clear(); foreach (T vtx in path) { Vector3d v = origin + vtx.Position; v = MeshTransforms.ConvertZUpToYUp(v); v = MeshTransforms.FlipLeftRightCoordSystems(v); // [RMS] because of the sharp turns we make, unity polyline will get twisted up unless we put // in some duplicate vertices =\ if (tempPolyLine.Count > 0) { tempPolyLine.Add((Vector3f)Vector3d.Lerp(prev, v, 0.001)); tempPolyLine.Add((Vector3f)Vector3d.Lerp(prev, v, 0.998)); tempPolyLine.Add((Vector3f)Vector3d.Lerp(prev, v, 0.999)); } tempPolyLine.Add((Vector3f)v); prev = v; } fPolylineGameObject go = PolylinePool.Allocate(); go.SetMaterial(material, true); go.SetLineWidth(width); go.SetVertices(tempPolyLine.ToArray(), false, true); return(go); }
fPolylineGameObject allocate_polyline_go() { fPolylineGameObject go = GameObjectFactory.CreatePolylineGO( "gcode_path", new List <Vector3f>(), CCMaterials.PathMaterial_Default, true, 1.0f, LineWidthType.World); go.SetCornerQuality(fCurveGameObject.CornerQuality.Minimal); MaterialUtil.DisableShadows(go); return(go); }
public IEnumerator UpdateGeometryOnMainThread() { if (BoundaryInfo == null) { yield break; } if (is_disconnected) { yield break; } MeshBoundaryData boundary_info = BoundaryInfo; // if mesh was modified before we got here, push it back onto dirty list if (boundary_info.timestamp != SO.Mesh.ShapeTimestamp) { OnComputeUpdateRequired?.Invoke(this); yield break; } int add_per_frame = 100; int counter = 0; foreach (DCurve3 loop in boundary_info.Loops) { if (is_disconnected || boundary_info.timestamp != SO.Mesh.ShapeTimestamp) { yield break; } List <Vector3f> vertices = new List <Vector3f>(loop.Vertices.Select(x => (Vector3f)x).ToList()); vertices.Add(vertices[0]); fPolylineGameObject go = GameObjectFactory.CreatePolylineGO("boundary_curve", vertices, BoundaryLoopColor, BoundaryCurveWidth, LineWidthType.Pixel); SO.RootGameObject.AddChild(go, false); BoundaryCurveGOs.Add(go); if (counter++ == add_per_frame) { counter = 0; yield return(null); } } foreach (DCurve3 span in boundary_info.Spans) { if (is_disconnected || boundary_info.timestamp != SO.Mesh.ShapeTimestamp) { yield break; } List <Vector3f> vertices = new List <Vector3f>(span.Vertices.Select(x => (Vector3f)x).ToList()); fPolylineGameObject go = GameObjectFactory.CreatePolylineGO("boundary_span", vertices, BoundaryLoopColor, BoundaryCurveWidth, LineWidthType.Pixel); SO.RootGameObject.AddChild(go, false); BoundaryCurveGOs.Add(go); if (counter++ == add_per_frame) { counter = 0; yield return(null); } } }
//GameObject trailGO; //TrailRenderer trailRen; public PrintTempParticleSystem(GameObject parentGO) { heatParticlesGO = new GameObject("heatParticleSystem"); ps = heatParticlesGO.AddComponent <ParticleSystem>(); parentGO.AddChild(heatParticlesGO, false); Material heatMat = MaterialUtil.SafeLoadMaterial("HeatParticleMaterial"); heatParticlesGO.GetComponent <ParticleSystemRenderer>().material = heatMat; //MaterialUtil.SafeLoadMaterial("Particles/Alpha Blended Premultiply"); heatParticlesGO.SetLayer(FPlatform.WidgetOverlayLayer); heatParticlesGO.GetComponent <Renderer>().material.renderQueue = 4000; MaterialUtil.DisableShadows(heatParticlesGO); ps.Stop(); sparksGO = UnityUtil.FindGameObjectByName("SparksPS"); sparksGO.SetVisible(true); sparksPS = sparksGO.GetComponent <ParticleSystem>(); sparksPS.Stop(); parentGO.AddChild(sparksGO, false); fMaterial mat = MaterialUtil.CreateFlatMaterial(Colorf.VideoRed, 0.75f); trailGO = GameObjectFactory.CreatePolylineGO("trail", new List <Vector3f>(), mat, true, 0.5f, LineWidthType.World); trailGO.GetComponent <Renderer>().material.renderQueue = 3500; trailGO.SetCornerQuality(fCurveGameObject.CornerQuality.Minimal); trailGO.SetParent(parentGO); trailGO.SetLayer(FPlatform.WidgetOverlayLayer); MaterialUtil.DisableShadows(trailGO); //trailGO = new GameObject("heatTrail"); //trailRen = trailGO.AddComponent<TrailRenderer>(); //parentGO.AddChild(trailGO, false); //trailRen.material = MaterialUtil.CreateFlatMaterial(Colorf.VideoRed); //trailRen.material.renderQueue = 3500; //trailRen.minVertexDistance = 0.2f; //trailRen.numCornerVertices = 4; //trailRen.startWidth = 0.5f; //trailRen.endWidth = 0.1f; //trailRen.time = 2.0f; }
void compute_slice_polylines() { fMaterial mat1 = MaterialUtil.CreateFlatMaterialF(Colorf.Black); fMaterial mat2 = MaterialUtil.CreateFlatMaterialF(Colorf.BlueMetal); // [TODO] do we need to hold data_lock here? seems like no since main thread is blocked, // then it would never be the case that we are setting SliceSet = null // create geometry int slice_i = 0; SlicePolylines = new List <fPolylineGameObject>(); foreach (PlanarSlice slice in SliceSet.Slices) { //DebugUtil.Log(2, "Slice has {0} solids", slice.Solids.Count); Colorf slice_color = (slice_i % 2 == 0) ? Colorf.Black : Colorf.BlueMetal; fMaterial slice_mat = (slice_i % 2 == 0) ? mat1 : mat2; slice_i++; foreach (GeneralPolygon2d poly in slice.Solids) { List <Vector3f> polyLine = new List <Vector3f>(); for (int pi = 0; pi <= poly.Outer.VertexCount; ++pi) { int i = pi % poly.Outer.VertexCount; Vector2d v2 = poly.Outer[i]; Vector2d n2 = poly.Outer.GetTangent(i).Perp; Vector3d v3 = new Vector3d(v2.x, v2.y, slice.Z); v3 = MeshTransforms.ConvertZUpToYUp(v3); v3 = MeshTransforms.FlipLeftRightCoordSystems(v3); Vector3d n3 = MeshTransforms.ConvertZUpToYUp(new Vector3d(n2.x, n2.y, 0)); n3 = MeshTransforms.FlipLeftRightCoordSystems(n3); n3.Normalize(); v3 += 0.1f * n3; polyLine.Add((Vector3f)v3); } //DebugUtil.Log(2, "Polyline has {0} vertiecs", polyLine.Count); fPolylineGameObject go = GameObjectFactory.CreatePolylineGO( "slice_outer", polyLine, slice_color, 0.1f, LineWidthType.World); go.SetMaterial(slice_mat, true); CC.ActiveScene.RootGameObject.AddChild(go, false); SlicePolylines.Add(go); } } }
void compute_toolpath_polylines() { Func <Vector3d, byte> LayerFilterF = (v) => { return(255); }; Vector3d origin = BedOrigin; Interval1d zrange = ZInterval; double width = Settings.Machine.NozzleDiamMM; float extrude_width = (float)width / 2; float travel_width = (float)width / 3; Polylines.Clear(); // should already be empty, no? Action <LinearToolpath3 <PrintVertex> > drawPath3F = (polyPath) => { Vector3d v0 = polyPath.Start.Position; // LAYER FILTER if (zrange.Contains(v0.z) == false) { return; } byte layer_alpha = LayerFilterF(v0); if (layer_alpha == 0) { return; } bool is_below = (layer_alpha < 255); fMaterial mat = CCMaterials.PathMaterial_Default; float w = 0.1f; if (polyPath.Type == ToolpathTypes.Deposition) { if ((polyPath.TypeModifiers & FillTypeFlags.SupportMaterial) != 0) { mat = CCMaterials.PathMaterial_Support; } else { mat = CCMaterials.PathMaterial_Extrude; } w = extrude_width; } else if (polyPath.Type == ToolpathTypes.Travel) { mat = CCMaterials.PathMaterial_Travel; w = travel_width; } else if (polyPath.Type == ToolpathTypes.PlaneChange) { mat = CCMaterials.PathMaterial_PlaneChange; w = travel_width; } else { // } // todo layer alpha... //paint.Color = SkiaUtil.Color(paint.Color, layer_alpha); if (is_below) { w *= 6; } fPolylineGameObject path = make_path(polyPath, mat, w, origin); Polylines.Add(path); }; process_linear_paths(Toolpaths, drawPath3F); foreach (fPolylineGameObject go in Polylines) { AppendNewGO(go, parentGO, false); go.SetLayer(FPlatform.WidgetOverlayLayer); } }