Exemplo n.º 1
0
        public override void Refresh()
        {
            base.Refresh();

            var VGO   = InGameObjectArray.GetAllData <CGGameObject>();
            var Spots = InSpots.GetData <CGSpots>();

            Clear();
            var existingPools          = GetAllPrefabPools();
            HashSet <string> usedPools = new HashSet <string>();

            if (VGO.Count > 0 && Spots.Count > 0)
            {
                CGSpot spot;
                for (int s = 0; s < Spots.Count; s++)
                {
                    spot = Spots.Points[s];
                    int id = spot.Index;
                    if (id >= 0 && id < VGO.Count && VGO[id].Object != null)
                    {
                        string poolIdent = GetPrefabPool(VGO[id].Object).Identifier;
                        usedPools.Add(poolIdent);
                        var res = (Transform)AddManagedResource("GameObject", poolIdent, s);
                        res.gameObject.isStatic = MakeStatic;
                        res.gameObject.layer    = Layer;
                        res.localPosition       = spot.Position;
                        res.localRotation       = spot.Rotation;
                        res.localScale          = new Vector3(res.localScale.x * spot.Scale.x * VGO[id].Scale.x, res.localScale.y * spot.Scale.y * VGO[id].Scale.y, res.localScale.z * spot.Scale.z * VGO[id].Scale.z);
                        if (VGO[id].Matrix != Matrix4x4.identity)
                        {
                            res.Translate(VGO[id].Translate);
                            res.Rotate(VGO[id].Rotate);
                        }

                        GameObjects.Items.Add(res);
                        GameObjects.PoolNames.Add(poolIdent);
                    }
                }
            }

            // Remove unused pools
            foreach (var pool in existingPools)
            {
                if (!usedPools.Contains(pool.Identifier))
                {
                    Generator.PoolManager.DeletePool(pool);
                }
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public override void Refresh()
        {
            base.Refresh();
            mBounds = InBounds.GetAllData <CGBounds>();
            Path    = InPath.GetData <CGPath>();
            if (Path != null && Volume == null && UseVolume)
            {
                m_UseVolume = false;
            }
            List <CGSpot>   spots     = new List <CGSpot>();
            List <GroupSet> endGroups = null;

            prepare();

            if (Path && mBounds.Count > 0 && mGroupsHaveDepth)
            {
                float remainingLength = Length;
                StartDistance = Path.FToDistance(m_Range.Low);
                float currentDistance = StartDistance;

                // Fixed start group(s)
                for (int g = 0; g < FirstRepeating; g++)
                {
                    addGroupItems(Groups[g], ref spots, ref remainingLength, ref currentDistance);
                    if (remainingLength <= 0)
                    {
                        break;
                    }
                }
                // Fixed end group(s)
                if (GroupCount - LastRepeating - 1 > 0)
                {
                    endGroups = new List <GroupSet>();
                    float endDist = 0;
                    for (int g = LastRepeating + 1; g < GroupCount; g++)
                    {
                        endGroups.Add(addGroupItems(Groups[g], ref spots, ref remainingLength, ref endDist, true));
                    }
                }
                // Mid-Groups, either in row or random
                if (RepeatingOrder == CurvyRepeatingOrderEnum.Row)
                {
                    int g = FirstRepeating;
                    while (remainingLength > 0)
                    {
                        addGroupItems(Groups[g++], ref spots, ref remainingLength, ref currentDistance);
                        if (g > LastRepeating)
                        {
                            g = FirstRepeating;
                        }
                    }
                }
                else
                {
                    while (remainingLength > 0)
                    {
                        addGroupItems(Groups[mGroupBag.Next()], ref spots, ref remainingLength, ref currentDistance);
                    }
                }
                // If we have previously generated endgroups data, shift them now
                if (endGroups != null)
                {
                    rebase(ref spots, ref endGroups, currentDistance, remainingLength);
                }
            }

            Count = spots.Count;

            SimulatedSpots = new CGSpots(spots);
            if (Simulate)
            {
                OutSpots.SetData(new CGSpots());
            }
            else
            {
                OutSpots.SetData(SimulatedSpots);
            }
        }
Exemplo n.º 4
0
        /*! \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);
            }
        }
Exemplo n.º 5
0
        /*! \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);
            }
        }