예제 #1
0
        public static PolylineGameObject Create(IEntityManager manager, ElementTag tag,
                                                IEnumerable <Vector3> points, Vector4[] color)
        {
            var indeces = new List <int>();

            for (var i = 0; i < points.Count(); i++)
            {
                indeces.AddRange(new[] { i, i });
            }
            var geo = new SimpleGeometryComponent()
            {
                Positions = points.ToImmutableArray(),
                Indices   = indeces.ToImmutableArray(),
                Colors    = color.ToImmutableArray(),
            };
            var tag1 = manager
                       .CreateEntity(tag)
                       .AddComponent(geo)
                       .AddComponent(SDX.Engine.Components.D3DLineVertexRenderComponent.AsLineList())
                       .AddComponent(new TransformComponent())
                       //.AddComponent(new PositionColorsComponent { Colors = color })
                       .Tag;

            return(new PolylineGameObject(tag1));
        }
예제 #2
0
        static SimpleGeometryComponent GenerateSphere(float radius, Vector3 center, float stepDegree)
        {
            //{Minimum:X:-2 Y:-2 Z:-2 Maximum:X:2 Y:2 Z:2}
            var com = new SimpleGeometryComponent();

            for (var angle = stepDegree; angle < 360f; angle += stepDegree)
            {
            }

            return(com);
        }
예제 #3
0
        public static ElementTag BuildLineEntity(this IEntityManager manager, Vector3[] points)
        {
            var geo = new SimpleGeometryComponent()
            {
                Positions = points.ToImmutableArray(),
                Indices   = ImmutableArray.Create <int>(),
                Color     = new Vector4(0, 1, 0, 1)
            };

            return(manager
                   .CreateEntity(new ElementTag("Points" + Guid.NewGuid()))
                   .AddComponent(geo)
                   .AddComponent(new SDX.Engine.Components.D3DLineVertexRenderComponent())
                   .Tag);
        }
예제 #4
0
        public static ElementTag Build(IEntityManager manager, List <Vector3> pos, List <int> indexes, List <Vector4> colors)
        {
            var geo = new SimpleGeometryComponent()
            {
                Positions = pos.ToImmutableArray(),
                Indices   = indexes.ToImmutableArray(),
                Colors    = colors.ToImmutableArray(),
                Normals   = pos.CalculateNormals(indexes).ToImmutableArray()
            };

            return(manager
                   .CreateEntity(new ElementTag("Geometry" + Guid.NewGuid()))
                   .AddComponent(geo)
                   .AddComponent(TransformComponent.Identity())
                   .AddComponent(GetObjGroupsRender())
                   .Tag);
        }
예제 #5
0
        public void Parse(Stream stream, IParseResultVisiter visiter)
        {
            var r = new ObjSpanReader();

            try {
                var sw = new Stopwatch();
                sw.Start();

                r.Read(stream);

                sw.Stop();
                Trace.WriteLine($"Reader {sw.Elapsed.TotalMilliseconds}");

                //r.FullGeometry1.Color = new Vector4(0, 1, 0, 1);
                //r.FullGeometry1.Normals = r.FullGeometry1.Positions.CalculateNormals(r.FullGeometry.Indices.ToList());

                //var full = r.FullGeometry1;// r.FullGeometry;
                //var c = new SimpleGeometryComponent {
                //    Positions = full.Positions.ToImmutableArray(),
                //    Indices = full.Indices.ToImmutableArray(),
                //    Normals = full.Positions.ToList().CalculateNormals(full.Indices.ToList()).ToImmutableArray(),

                //};


                //    visiter.Handle(c);
                var onlypoints  = new List <Vector3>();
                var onlypoints1 = new List <Vector3>();
                r.FullGeometry.Fixed();

                var com = new ObjGroupsComponent();
                foreach (var part in r.FullGeometry.Parts)
                {
                    //com.OrderedGroups.Add(new OrderedObjGroups(part.Name, part.Groups));
                    if (part.Groups.Any(i => i.IndxGroupInfo != null))   // geo is created only by triangles
                    {
                        visiter.Handle(new VirtualGroupGeometryComponent(part));
                    }
                    else
                    {
                        onlypoints.AddRange(part.Positions);
                    }
                    //break;
                }
                //visiter.Handle(com);
            } catch (Exception exc) {
                exc.ToString();
            }
            return;

            var readerA = new ObjReader();
            var res     = readerA.Read(stream);
            var meshes  = new List <AbstractGeometry3D>();

            var colors = new Vector4[4];

            colors[0] = new Vector4(1, 0, 0, 1);
            colors[1] = new Vector4(0, 1, 0, 1);
            colors[2] = new Vector4(0, 0, 1, 1);
            colors[3] = new Vector4(1, 1, 0, 1);

            for (int i = 0; i < res.Count; i++)
            {
                Object3D m    = res[i];
                var      mesh = m.Geometry;
                mesh.Color = colors.Length > i ? colors[i] : colors[0];
                //meshes.Add(mesh);
                var c = new SimpleGeometryComponent {
                    Positions = mesh.Positions.ToImmutableArray(),
                    Indices   = mesh.Indices.ToImmutableArray(),
                    Normals   = mesh.Positions.ToList().CalculateNormals(mesh.Indices.ToList()).ToImmutableArray(),
                };
                visiter.Handle(c);
            }
        }