/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); var vol = InVolume.GetData <CGVolume>(); if (vol && vol.Count > 0 && vol.CrossSize > 0 && vol.CrossMaterialGroups.Count > 0) { List <IntRegion> volSets = new List <IntRegion>(); if (Split) { float dist; float lastdist = 0; int lastIndex = 0; for (int sample = 0; sample < vol.Count; sample++) { dist = vol.FToDistance(vol.F[sample]); if (dist - lastdist >= SplitLength) { volSets.Add(new IntRegion(lastIndex, sample)); lastdist = dist; lastIndex = sample; } } if (lastIndex < vol.Count - 1) { volSets.Add(new IntRegion(lastIndex, vol.Count - 1)); } } else { volSets.Add(new IntRegion(0, vol.Count - 1)); } CGVMesh[] data = OutVMesh.GetAllData <CGVMesh>(); System.Array.Resize <CGVMesh>(ref data, volSets.Count); prepare(vol); for (int sub = 0; sub < volSets.Count; sub++) { data[sub] = CGVMesh.Get(data[sub], vol, volSets[sub], GenerateUV, ReverseTriOrder); build(data[sub], vol, volSets[sub]); } OutVMesh.SetData(data); } else { OutVMesh.SetData(null); } }
public override void Refresh() { if (OutSpots.IsLinked) { OutSpots.SetData(new CGSpots(Spots.ToArray())); } }
public override void Refresh() { base.Refresh(); if (OutVMesh.IsLinked) { var vMesh = InVMesh.GetAllData <CGVMesh>(); var mat = Matrix; for (int i = 0; i < vMesh.Count; i++) { vMesh[i].TRS(mat); } OutVMesh.SetData(vMesh); } }
/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); if (Length == 0) { Reset(); } else { var req = new List <CGDataRequestParameter>(); req.Add(new CGDataRequestRasterization(From, Length, CGUtility.CalculateSamplePointsCacheSize(Resolution, InPath.SourceSlot().OnRequestPathModule.PathLength), AngleThreshold, (Optimize) ? CGDataRequestRasterization.ModeEnum.Optimized:CGDataRequestRasterization.ModeEnum.Even)); var path = InPath.GetData <CGPath>(req.ToArray()); OutPath.SetData(path); } }
/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); //OutVMesh if (OutVMesh.IsLinked) { var data = new CGVMesh[Meshes.Count]; int total = 0; for (int i = 0; i < Meshes.Count; i++) { if (Meshes[i].Mesh) { data[total++] = new CGVMesh(Meshes[i]); } } System.Array.Resize <CGVMesh>(ref data, total); OutVMesh.SetData(data); } }
/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); //OutVMesh if (OutGameObject.IsLinked) { var data = new CGGameObject[GameObjects.Count]; int total = 0; for (int i = 0; i < GameObjects.Count; i++) { if (GameObjects[i] != null) { data[total++] = new CGGameObject(GameObjects[i]); } } System.Array.Resize <CGGameObject>(ref data, total); OutGameObject.SetData(data); } }
/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); if (Length == 0) { Reset(); } else { var req = new List <CGDataRequestParameter>(); req.Add(new CGDataRequestRasterization(this.From, this.Length, CGUtility.CalculateSamplePointsCacheSize(Resolution, InPath.SourceSlot().OnRequestPathModule.PathLength *this.Length), AngleThreshold, (Optimize) ? CGDataRequestRasterization.ModeEnum.Optimized : CGDataRequestRasterization.ModeEnum.Even)); var path = InPath.GetData <CGPath>(req.ToArray()); req.Clear(); req.Add(new CGDataRequestRasterization(this.CrossFrom, this.CrossLength, CGUtility.CalculateSamplePointsCacheSize(CrossResolution, InCross.SourceSlot().OnRequestPathModule.PathLength *this.CrossLength), CrossAngleThreshold, (CrossOptimize) ? CGDataRequestRasterization.ModeEnum.Optimized : CGDataRequestRasterization.ModeEnum.Even)); if (CrossIncludeControlPoints || CrossHardEdges || CrossMaterials) { req.Add(new CGDataRequestMetaCGOptions(CrossHardEdges, CrossMaterials, CrossIncludeControlPoints, CrossExtendedUV)); } var cross = InCross.GetData <CGShape>(req.ToArray()); if (!path || !cross || path.Count == 0 || cross.Count == 0) { OutVolume.ClearData(); OutVolumeHollow.ClearData(); return; } var vol = CGVolume.Get(OutVolume.GetData <CGVolume>(), path, cross); var volHollow = (OutVolumeHollow.IsLinked) ? CGVolume.Get(OutVolumeHollow.GetData <CGVolume>(), path, cross) : null; PathSamples = path.Count; CrossSamples = cross.Count; CrossGroups = cross.MaterialGroups.Count; CrossPosition = vol.Position[0]; CrossRotation = Quaternion.LookRotation(vol.Direction[0], vol.Normal[0]); Vector3 baseScale = (ScaleUniform) ? new Vector3(ScaleX, ScaleX, 1) : new Vector3(ScaleX, ScaleY, 1); Vector3 scl = baseScale; int vtIdx = 0; float[] scaleFArray = (ScaleReference == CGReferenceMode.Source) ? path.SourceF : path.F; Matrix4x4 mat; Matrix4x4 matHollow; Quaternion R; int crossNormalMul = (CrossReverseNormals) ? -1 : 1; int hollowNormalMul = (HollowReverseNormals) ? -1 : 1; for (int sample = 0; sample < path.Count; sample++) { R = Quaternion.LookRotation(path.Direction[sample], path.Normal[sample]); getScaleInternal(scaleFArray[sample], baseScale, ref scl); mat = Matrix4x4.TRS(path.Position[sample], R, scl); if (volHollow == null) { for (int c = 0; c < cross.Count; c++) { vol.Vertex[vtIdx] = mat.MultiplyPoint(cross.Position[c]); vol.VertexNormal[vtIdx++] = R * cross.Normal[c] * crossNormalMul; } } else { matHollow = Matrix4x4.TRS(path.Position[sample], R, scl * (1 - HollowInset)); for (int c = 0; c < cross.Count; c++) { vol.Vertex[vtIdx] = mat.MultiplyPoint(cross.Position[c]); vol.VertexNormal[vtIdx] = R * cross.Normal[c]; volHollow.Vertex[vtIdx] = matHollow.MultiplyPoint(cross.Position[c]); volHollow.VertexNormal[vtIdx] = vol.VertexNormal[vtIdx++] * hollowNormalMul; } } } switch (CrossShiftMode) { case CrossShiftModeEnum.ByOrientation: // shift CrossF to match Path Orientation Vector2 hit; float frag; for (int i = 0; i < cross.Count - 1; i++) { if (DTMath.RayLineSegmentIntersection(vol.Position[0], vol.VertexNormal[0], vol.Vertex[i], vol.Vertex[i + 1], out hit, out frag)) { vol.CrossFShift = DTMath.SnapPrecision(vol.CrossF[i] + (vol.CrossF[i + 1] - vol.CrossF[i]) * frag, 2); break; } } if (vol.CrossClosed && DTMath.RayLineSegmentIntersection(vol.Position[0], vol.VertexNormal[0], vol.Vertex[cross.Count - 1], vol.Vertex[0], out hit, out frag)) { vol.CrossFShift = DTMath.SnapPrecision(vol.CrossF[cross.Count - 1] + (vol.CrossF[0] - vol.CrossF[cross.Count - 1]) * frag, 2); } break; case CrossShiftModeEnum.Custom: vol.CrossFShift = CrossShiftValue; break; default: vol.CrossFShift = 0; break; } if (volHollow != null) { volHollow.CrossFShift = vol.CrossFShift; } OutVolume.SetData(vol); OutVolumeHollow.SetData(volHollow); } }
public void Clear() { Count = 0; SimulatedSpots = new CGSpots(); OutSpots.SetData(SimulatedSpots); }
/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); CGVolume vol = InVolume.GetData <CGVolume>(); var holes = InVolumeHoles.GetAllData <CGVolume>(); if (vol) { bool genStart = (StartCap == CGYesNoAuto.Yes || (StartCap == CGYesNoAuto.Auto && !vol.Seamless)); bool genEnd = (EndCap == CGYesNoAuto.Yes || (EndCap == CGYesNoAuto.Auto && !vol.Seamless)); if (!genStart && !genEnd) { OutVMesh.SetData(null); return; } var vmesh = new CGVMesh(); Vector3[] vtStart = new Vector3[0]; Vector3[] vtEnd = new Vector3[0]; vmesh.AddSubMesh(new CGVSubMesh()); CGVSubMesh submesh = vmesh.SubMeshes[0]; if (genStart) { #region --- Start Cap --- var tess = new Tess(); tess.UsePooling = true; tess.AddContour(make2DSegment(vol, 0)); for (int h = 0; h < holes.Count; h++) { if (holes[h].Count < 3) { OutVMesh.SetData(null); UIMessages.Add("Hole Cross has <3 Vertices: Can't create Caps!"); return; } tess.AddContour(make2DSegment(holes[h], 0)); } tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3); vtStart = UnityLibTessUtility.FromContourVertex(tess.Vertices); Bounds b; vmesh.Vertex = applyMat(vtStart, getMat(vol, 0, true), out b); submesh.Material = StartMaterial; submesh.Triangles = tess.Elements; if (ReverseTriOrder) { flipTris(ref submesh.Triangles, 0, submesh.Triangles.Length); } if (GenerateUV) { vmesh.UV = new Vector2[vtStart.Length]; applyUV(vtStart, ref vmesh.UV, 0, vtStart.Length, StartMaterialSettings, b); } #endregion } if (genEnd) { #region --- End Cap --- var tess = new Tess(); tess.UsePooling = true; tess.AddContour(make2DSegment(vol, 0)); for (int h = 0; h < holes.Count; h++) { if (holes[h].Count < 3) { OutVMesh.SetData(null); UIMessages.Add("Hole Cross has <3 Vertices: Can't create Caps!"); return; } tess.AddContour(make2DSegment(holes[h], 0)); } tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3); vtEnd = UnityLibTessUtility.FromContourVertex(tess.Vertices); Bounds b; int l = vmesh.Vertex.Length; vmesh.Vertex = vmesh.Vertex.AddRange <Vector3>(applyMat(vtEnd, getMat(vol, vol.Count - 1, true), out b)); int[] tris = tess.Elements; if (!ReverseTriOrder) { flipTris(ref tris, 0, tris.Length); } for (int i = 0; i < tris.Length; i++) { tris[i] += l; } if (!CloneStartCap && StartMaterial != EndMaterial) { vmesh.AddSubMesh(new CGVSubMesh(tris, EndMaterial)); } else { submesh.Material = StartMaterial; submesh.Triangles = submesh.Triangles.AddRange <int>(tris); } if (GenerateUV) { System.Array.Resize <Vector2>(ref vmesh.UV, vmesh.UV.Length + vtEnd.Length); applyUV(vtEnd, ref vmesh.UV, vtStart.Length, vtEnd.Length, (CloneStartCap) ? StartMaterialSettings : EndMaterialSettings, b); } #endregion } OutVMesh.SetData(vmesh); } }
/*! \endcond */ #endregion #region ### Public Methods ### public override void Refresh() { base.Refresh(); CGVolume vol = InVolume.GetData <CGVolume>(); var holes = InVolumeHoles.GetAllData <CGVolume>(); if (vol) { bool genStart = (StartCap == CGYesNoAuto.Yes || (StartCap == CGYesNoAuto.Auto && !vol.Seamless)); bool genEnd = (EndCap == CGYesNoAuto.Yes || (EndCap == CGYesNoAuto.Auto && !vol.Seamless)); if (!genStart && !genEnd) { OutVMesh.SetData(null); return; } var vmesh = new CGVMesh(); Vector3[] vtStart = new Vector3[0]; Vector3[] vtEnd = new Vector3[0]; Polygon pOuter; vmesh.AddSubMesh(new CGVSubMesh()); CGVSubMesh submesh = vmesh.SubMeshes[0]; Vector3[] points; if (genStart) { #region --- Start Cap --- points = make2DSegment(vol, 0); if (points.Length < 3) { OutVMesh.SetData(null); UIMessages.Add("Cross has <3 Vertices: Can't create Caps!"); return; } pOuter = new Polygon(points); for (int h = 0; h < holes.Count; h++) { points = make2DSegment(holes[h], 0); if (points.Length < 3) { OutVMesh.SetData(null); UIMessages.Add("Hole Cross has <3 Vertices: Can't create Caps!"); return; } pOuter.AddHole(new Polygon(points)); } try { P2T.Triangulate(pOuter); } catch (System.Exception e) { Debug.LogException(e); OutVMesh.SetData(null); return; } submesh.Material = StartMaterial; pOuter.GetResults(out vtStart, out submesh.Triangles, ReverseTriOrder); vmesh.Vertex = applyMat(vtStart, getMat(vol, 0, true)); if (GenerateUV) { vmesh.UV = new Vector2[vtStart.Length]; applyUV(vtStart, ref vmesh.UV, 0, vtStart.Length, pOuter.Bounds.Bounds, StartMaterialSettings); } #endregion } if (genEnd) { #region --- End Cap --- points = make2DSegment(vol, vol.Count - 1); if (points.Length < 3) { OutVMesh.SetData(null); UIMessages.Add("Cross has <3 Vertices: Can't create Caps!"); return; } pOuter = new Polygon(points); for (int h = 0; h < holes.Count; h++) { points = make2DSegment(holes[h], holes[h].Count - 1); if (points.Length < 3) { OutVMesh.SetData(null); UIMessages.Add("Hole Cross has <3 Vertices: Can't create Caps!"); return; } pOuter.AddHole(new Polygon(points)); } try { P2T.Triangulate(pOuter); } catch (System.Exception e) { Debug.LogException(e); OutVMesh.SetData(null); return; } int[] tris; pOuter.GetResults(out vtEnd, out tris, !ReverseTriOrder, vtStart.Length); vmesh.Vertex = vmesh.Vertex.AddRange <Vector3>(applyMat(vtEnd, getMat(vol, vol.Count - 1, true))); if (!CloneStartCap && StartMaterial != EndMaterial) { vmesh.AddSubMesh(new CGVSubMesh(tris, EndMaterial)); } else { submesh.Material = StartMaterial; submesh.Triangles = submesh.Triangles.AddRange <int>(tris); } if (GenerateUV) { System.Array.Resize <Vector2>(ref vmesh.UV, vmesh.UV.Length + vtEnd.Length); applyUV(vtEnd, ref vmesh.UV, vtStart.Length, vtEnd.Length, pOuter.Bounds.Bounds, (CloneStartCap) ? StartMaterialSettings : EndMaterialSettings); } #endregion } OutVMesh.SetData(vmesh); } }