public static Csgjs FromPolygons(List <CsgPolygon> polygons)
        {
            var csg = new Csgjs();

            csg.Polygons.AddRange(polygons);
            return(csg);
        }
        public Csgjs Clone()
        {
            var csg = new Csgjs();

            csg.Polygons.AddRange(Polygons.Select(p => p.Clone()));
            return(csg);
        }
Beispiel #3
0
        public Csgjs GetCsg()
        {
            if (HasChanged)
            {
                _hasChanged = false;
                _transform  = CsgjsScript.Actor.Transform;
                _csg        = Create(out var surfaces);

                if (surfaces != null)
                {
                    for (int i = 0; i < surfaces.Count; i++)
                    {
                        for (int j = 0; j < Surfaces.Length; j++)
                        {
                            if (surfaces[i].Name == Surfaces[j].Name)
                            {
                                surfaces[i].SurfaceData = Surfaces[j];
                                break;
                            }
                        }
                    }
                }

                _csg.Polygons.ForEach(p =>
                {
                    Plane plane = new Plane(p.Plane.Normal, p.Plane.W);
                    plane       = LocalToWorldPlane(ref _transform, plane);

                    p.Plane.Normal = plane.Normal;
                    p.Plane.W      = plane.D;

                    // Vertices cannot be shared
                    p.Vertices.ForEach(v =>
                    {
                        v.Position = _transform.TransformPoint(v.Position);
                        v.Normal   = LocalToWorldNormal(ref _transform, v.Normal);
                    });
                });
            }

            return(_csg);
        }
        public Csgjs Union(Csgjs csg)
        {
            if (Polygons.Count == 0)
            {
                return(csg.Clone());
            }
            if (csg.Polygons.Count == 0)
            {
                return(Clone());
            }

            var a = new CsgNode(Clone().Polygons);
            var b = new CsgNode(csg.Clone().Polygons);

            a.ClipTo(b);
            b.ClipTo(a);
            b.Invert();
            b.ClipTo(a);
            b.Invert();
            a.Build(b.AllPolygons());
            return(FromPolygons(a.AllPolygons()));
        }
        public void Execute()
        {
            if (NodeType == CsgjsNodeType.Root)
            {
                var csgResult = DoCsg();
                _combinedCsg = csgResult;

                if (csgResult.Polygons.Count == 0)
                {
                    for (int i = 0; i < _virtualModelActor.Entries.Length; i++)
                    {
                        _virtualModelActor.Entries[i].Visible = false;
                    }
                }
                else
                {
                    for (int i = 0; i < _virtualModelActor.Entries.Length; i++)
                    {
                        _virtualModelActor.Entries[i].Visible = true;
                    }
                    Triangulate(csgResult, _virtualModel);
                }
            }
        }
 public override void OnDisable()
 {
     Destroy(ref _virtualModelActor);
     Destroy(ref _virtualModel);
     _combinedCsg = null;
 }
 protected override Csgjs Create(out List <Csgjs.CsgSurfaceSharedData> surfaces)
 {
     return(Csgjs.CreateCube(Center, Size, out surfaces));
 }
 protected override Csgjs Create(out List<Csgjs.CsgSurfaceSharedData> surfaces)
 {
     return Csgjs.CreateCylinder(Center + Vector3.UnitY, Center - Vector3.UnitY, Size, out surfaces);
 }