/*! \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); } }
void OnModuleWindowSlotGUI(CGModule module) { int i = 0; float h = 18; while (module.Input.Count > i || module.Output.Count > i) { float y = CurvyStyles.ModuleWindowTitleHeight + h * i; GUILayout.BeginHorizontal(); if (module.Input.Count > i) { CGModuleInputSlot slot = module.Input[i]; Color slotColor = getTypeColor(slot.Info.DataTypes); if (Canvas.IsLinkDrag && !slot.IsValidTarget(Canvas.LinkDragFrom)) { slotColor = new Color(0.2f, 0.2f, 0.2f).SkinAwareColor(true); } DTGUI.PushColor(slotColor); GUILayout.Box("<", CurvyStyles.Slot); DTGUI.PopColor(); string postfix = ""; if (slot.Info.Array) { postfix = (slot.LastDataCountINTERNAL > 0) ? "[" + slot.LastDataCountINTERNAL.ToString() + "]" : "[]"; } GUILayout.Label(new GUIContent(ObjectNames.NicifyVariableName(slot.Info.Name) + postfix, slot.Info.Tooltip), CurvyStyles.GetSlotLabelStyle(slot)); slot.DropZone = new Rect(0, y, module.Properties.Dimensions.width / 2, h); slot.Origin = new Vector2(module.Properties.Dimensions.xMin, module.Properties.Dimensions.yMin + y + h / 2); // LinkDrag? if (Canvas.IsLinkDrag) { // If ending drag over dropzone, create static link if (EV.type == EventType.MouseUp && slot.DropZone.Contains(EV.mousePosition) && slot.IsValidTarget(Canvas.LinkDragFrom)) { finishLink(slot); } } // Clicking on Dropzone to pick existing link else if (LMB && slot.Count == 1 && slot.DropZone.Contains(EV.mousePosition)) { var linkedOutSlot = slot.SourceSlot(); linkedOutSlot.UnlinkFrom(slot); EditorUtility.SetDirty(slot.Module); startLinkDrag(linkedOutSlot); GUIUtility.ExitGUI(); } } if (module.Output.Count > i) { CGModuleOutputSlot slot = module.Output[i]; string postfix = ""; if (slot.Info.Array) { postfix = (slot.Data != null && slot.Data.Length > 1) ? "[" + slot.Data.Length.ToString() + "]" : ""; } GUILayout.Label(new GUIContent(ObjectNames.NicifyVariableName(slot.Info.Name) + postfix, slot.Info.Tooltip), CurvyStyles.GetSlotLabelStyle(slot)); DTGUI.PushColor(getTypeColor(slot.Info.DataTypes)); GUILayout.Box(">", CurvyStyles.Slot); DTGUI.PopColor(); // Debug /* * if (Generator.ShowDebug) * { * GUI.enabled = slot.Data != null && slot.Data.Length>0; * if (GUILayout.Button(new GUIContent(CurvyStyles.DebugTexture, "Show Dump"), CurvyStyles.SmallButton, GUILayout.Width(16), GUILayout.Height(16))) * DTDebugWindow.Open(slot.Data[0].GetType().Name + ":", slot.Data[0].ToDumpString()); * GUI.enabled = true; * } */ slot.DropZone = new Rect(module.Properties.Dimensions.width / 2, y, module.Properties.Dimensions.width / 2, h); slot.Origin = new Vector2(module.Properties.Dimensions.xMax, module.Properties.Dimensions.yMin + y + h / 2); // Start Linking? if (LMB && !Canvas.IsSelectionRectDrag && slot.DropZone.Contains(EV.mousePosition)) { startLinkDrag(slot); } } GUILayout.EndHorizontal(); i++; } }
/*! \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); } }