Пример #1
0
        public static VisualPolylineObject Create(IContextState context, ElementTag tag,
                                                  Vector3[] points, Vector4 color, bool isVisible = true)
        {
            var manager = context.GetEntityManager();

            var indeces = new List <int>();
            var pos     = new List <Vector3>();
            var prev    = points[0];

            for (var i = 0; i < points.Length; i++)
            {
                pos.Add(prev);
                pos.Add(points[i]);
                prev = points[i];
            }
            for (var i = 0; i < pos.Count; i++)
            {
                indeces.AddRange(new[] { i, i });
            }
            var geo = context.GetGeometryPool().AddGeometry(new ImmutableGeometryData(pos, indeces));

            manager
            .CreateEntity(tag)
            .AddComponent(geo)
            .AddComponent(TransformComponent.Identity())
            .AddComponent(ColorComponent.CreateDiffuse(color))
            .AddComponent(isVisible ? RenderableComponent.AsLineList() : RenderableComponent.AsLineList().Disable());

            return(new VisualPolylineObject(tag));
        }
Пример #2
0
        public CompositeGameObjectFromFile Build(Stream stream, IFileParserPlugin parser)
        {
            parser.Parse(stream, this);
            var colors = new Queue <Vector4>();

            colors.Enqueue(V4Colors.Red);
            colors.Enqueue(V4Colors.Blue);
            colors.Enqueue(V4Colors.Green);
            colors.Enqueue(V4Colors.Yellow);

            foreach (var com in components)
            {
                var tag    = new ElementTag("Obj_" + Guid.NewGuid());//DateTime.Now.Ticks
                var entity = manager.CreateEntity(tag);
                var cc     = new List <IGraphicComponent>();
                cc.Add(com);
                cc.Add(EntityBuilders.GetObjGroupsRender());
                cc.Add(EntityBuilders.GetTransformation());
                //var material = new PositionColorsComponent();

                //material.Colors = new Vector4[com.Positions.Length];
                //for (var i =0;i < com.Positions.Length; ++i) {
                //    material.Colors[i] = V4Colors.Red;
                //}

                cc.Add(ColorComponent.CreateDiffuse(V4Colors.Red));
                cc.Add(new ManipulatableComponent());

                entity.AddComponents(cc);
                entity.AddComponents(others);
                gobj.AddEntity(tag);
            }

            return(gobj); //new SingleGameObject(tag, info.File.Name);
        }
Пример #3
0
        public static LightGameObject CreateAmbientLight(IEntityManager manager)
        {
            var tag = new ElementTag("AmbientLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponents(
                LightComponent.CreateAmbient(0.4f, 0),
                ColorComponent.CreateDiffuse(V4Colors.White)
                );

            return(new LightGameObject(tag, "AmbientLight"));
        }
Пример #4
0
        public static LightGameObject CreatePointLight(IEntityManager manager, Vector3 position)  //
        {
            var tag = new ElementTag("PointLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponents(
                LightComponent.CreatePoint(0.4f, 1, position),
                ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1))
                );

            return(new LightGameObject(tag, "PointLight"));
        }
Пример #5
0
        public static LightGameObject CreateDirectionLight(IEntityManager manager, Vector3 direction)  // ,
        {
            var tag = new ElementTag("DirectionLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponents(
                LightComponent.CreateDirectional(0.2f, 2, direction),
                ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1))
                );

            return(new LightGameObject(tag, "DirectionLight"));
        }
Пример #6
0
        public static LightObject CreatePointLight(IEntityManager manager, Vector3 position)  //
        {
            var index = 1;

            if (!occupiedIndex.Add(index))
            {
                throw new LightIndexOccupiedException(index);
            }
            var tag = new ElementTag("PointLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponent(LightComponent.CreatePoint(0.4f, index, position))
            .AddComponent(ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1)));

            return(new LightObject(tag, "PointLight"));
        }
Пример #7
0
        public static LightObject CreateDirectionLight(IEntityManager manager, Vector3 direction, float intensity)  // ,
        {
            var index = 2;

            if (!occupiedIndex.Add(index))
            {
                throw new LightIndexOccupiedException(index);
            }

            var tag = new ElementTag("DirectionLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponent(LightComponent.CreateDirectional(intensity, index, direction))
            .AddComponent(ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1)));

            return(new LightObject(tag, "DirectionLight"));
        }
Пример #8
0
        public static LightObject CreateAmbientLight(IEntityManager manager, float intensity = 0.4f)
        {
            var index = 0;

            if (!occupiedIndex.Add(index))
            {
                throw new LightIndexOccupiedException(index);
            }

            var tag = new ElementTag("AmbientLight_" + Interlocked.Increment(ref lights));
            var sv4 = SharpDX.Color.White.ToVector4();

            manager.CreateEntity(tag)
            .AddComponent(LightComponent.CreateAmbient(intensity, index))
            .AddComponent(ColorComponent.CreateDiffuse(new Vector4(sv4.X, sv4.Y, sv4.Z, sv4.W)));

            return(new LightObject(tag, "AmbientLight"));
        }
Пример #9
0
        public static VisualPolylineObject CreateBox(IContextState context, ElementTag tag, AxisAlignedBox box, Vector4 color)
        {
            var indeces = new List <int>();
            var pos     = new List <Vector3>();

            var xbox = box.GetCornersBox();

            var NearBottomLeft  = xbox.NearBottomLeft;
            var NearBottomRight = xbox.NearBottomRight;
            var NearTopLeft     = xbox.NearTopLeft;
            var NearTopRight    = xbox.NearTopRight;

            var FarBottomLeft  = xbox.FarBottomLeft;
            var FarBottomRight = xbox.FarBottomRight;
            var FarTopLeft     = xbox.FarTopLeft;
            var FarTopRight    = xbox.FarTopRight;

            //top
            pos.Add(NearBottomLeft);
            pos.Add(NearBottomRight);

            pos.Add(NearBottomRight);
            pos.Add(NearTopRight);

            pos.Add(NearTopRight);
            pos.Add(NearTopLeft);

            pos.Add(NearTopLeft);
            pos.Add(NearBottomLeft);
            //side
            pos.Add(NearBottomLeft);
            pos.Add(FarBottomLeft);

            pos.Add(NearBottomRight);
            pos.Add(FarBottomRight);

            pos.Add(NearTopRight);
            pos.Add(FarTopRight);

            pos.Add(NearTopLeft);
            pos.Add(FarTopLeft);
            //bottom

            pos.Add(FarBottomLeft);
            pos.Add(FarBottomRight);

            pos.Add(FarBottomRight);
            pos.Add(FarTopRight);

            pos.Add(FarTopRight);
            pos.Add(FarTopLeft);

            pos.Add(FarTopLeft);
            pos.Add(FarBottomLeft);

            for (var i = 0; i < pos.Count; i++)
            {
                indeces.AddRange(new[] { i, i });
            }

            var manager = context.GetEntityManager();

            var geo = context.GetGeometryPool()
                      .AddGeometry(new ImmutableGeometryData(pos.ToArray(), indeces.ToArray()));

            manager
            .CreateEntity(tag)
            .AddComponent(geo)
            .AddComponent(TransformComponent.Identity())
            .AddComponent(ColorComponent.CreateDiffuse(color))
            .AddComponent(RenderableComponent.AsLineList());

            return(new VisualPolylineObject(tag));
        }