Ejemplo n.º 1
0
 public override void Reset()
 {
     base.Reset();
     m_Range        = FloatRegion.ZeroOne;
     Resolution     = 50;
     AngleThreshold = 10;
     OutPath.ClearData();
 }
Ejemplo n.º 2
0
        /*! \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);
            }
        }