Exemplo n.º 1
0
        private Model GetModel(TileSet tiles)
        {
            var meshDraw = GeometricPrimitive.Cube.New(_graphicsDevice).ToMeshDraw();
            var mesh     = new Xenko.Rendering.Mesh {
                Draw = meshDraw
            };

            return(new Model {
                mesh
            });
        }
Exemplo n.º 2
0
        private Model CreateModel()
        {
            // https://doc.xenko.com/latest/en/manual/scripts/create-a-model-from-code.html
            var indexBuffer = new Buffer();

            var indexBufferBinding  = new IndexBufferBinding(indexBuffer, true, 10);
            var vertexBufferBinding = new VertexBufferBinding();

            VertexBufferBinding[] vertexBufferBindings = { vertexBufferBinding };

            var meshDraw = new MeshDraw
            {
                VertexBuffers = vertexBufferBindings,
                IndexBuffer   = indexBufferBinding
            };
            ParameterCollection parms = null;
            var mesh = new Xenko.Rendering.Mesh(meshDraw, parms);

            var model = new Model {
                mesh
            };

            return(model);
        }
Exemplo n.º 3
0
        public Entity AttachDebugShapeAsChild()
        {
            System.Numerics.Vector3 min, max;
            if (ColliderShape is IConvexShape ics)
            {
                ics.ComputeBounds(BepuHelpers.ToBepu(Quaternion.Identity), out min, out max);
            }
            else if (ColliderShape is BepuPhysics.Collidables.Mesh cm)
            {
                cm.ComputeBounds(BepuHelpers.ToBepu(Quaternion.Identity), out min, out max);
            }
            else
            {
                return(null);
            }

            Vector3 centerOffset = BepuHelpers.ToXenko(max + min) * 0.5f;

            Game g = ServiceRegistry.instance.GetService <IGame>() as Game;

            if (debugShapeMaterial == null)
            {
                var materialDescription = new MaterialDescriptor
                {
                    Attributes =
                    {
                        DiffuseModel = new MaterialDiffuseLambertModelFeature(),
                        Diffuse      = new MaterialDiffuseMapFeature(new ComputeColor {
                            Key      = MaterialKeys.DiffuseValue
                        })
                    }
                };

                debugShapeMaterial = Material.New(g.GraphicsDevice, materialDescription);
                debugShapeMaterial.Passes[0].Parameters.Set(MaterialKeys.DiffuseValue, Color.Red);

                var meshDraw = GeometricPrimitive.Cube.New(g.GraphicsDevice, Vector3.One).ToMeshDraw();

                cubeMesh = new Rendering.Mesh {
                    Draw = meshDraw
                };
            }

            Entity e = new Entity(Entity.Name + "-physicsBB");

            Model m = new Model();

            m.Add(debugShapeMaterial);
            m.Meshes.Add(cubeMesh);

            ModelComponent mc = e.GetOrCreate <ModelComponent>();

            mc.Model = m;

            e.Transform.Scale    = new Vector3(max.X - min.X, max.Y - min.Y, max.Z - min.Z) / Entity.Transform.WorldScale();
            e.Transform.Position = centerOffset / Entity.Transform.WorldScale();
            if (this is BepuRigidbodyComponent rb && rb.IgnorePhysicsRotation)
            {
                e.Transform.Rotation = Rotation;
            }
            e.Transform.Parent = Entity.Transform;

            return(e);
        }