Beispiel #1
0
        internal protected override bool PartialHitTest(ref HitTestArgs args)
        {
            if (Widget == null)
            {
                return(false);
            }
            var plane    = GetPlane();
            var ray      = args.Ray;
            var distance = ray.Intersects(plane);

            if (distance.HasValue && distance <= args.Distance)
            {
                var oldPoint = args.Point;
                try {
                    args.Point = (Vector2)GlobalTransform.CalcInverted().TransformVector(ray.Position + ray.Direction * distance.Value) * new Vector2(1, -1);
                    Widget.RenderChainBuilder?.AddToRenderChain(renderChain);
                    if (renderChain.HitTest(ref args))
                    {
                        args.Distance = distance.Value;
                        return(true);
                    }
                } finally {
                    args.Point = oldPoint;
                    renderChain.Clear();
                }
            }
            return(false);
        }
Beispiel #2
0
        public override void Render()
        {
            if (SkipRender)
            {
                return;
            }

            bool lightningEnabled = ProcessLightning && Viewport != null && Viewport.LightSource != null && Viewport.LightSource.Visible;
            bool shadowsEnabled   = lightningEnabled && Viewport.LightSource.ShadowMappingEnabled;

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;
            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    skin.SkinEnabled = sm.Bones.Count > 0;
                    if (skin.SkinEnabled)
                    {
                        if (sharedBoneTransforms.Length < sm.Bones.Count)
                        {
                            sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                        }
                        for (var i = 0; i < sm.Bones.Count; i++)
                        {
                            sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                        }
                        skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                    }
                }
                var lightningMaterial = sm.Material as IMaterialLightning;
                if (lightningMaterial != null)
                {
                    lightningMaterial.ProcessLightning = lightningEnabled;
                    if (lightningEnabled)
                    {
                        lightningMaterial.SetLightData(Viewport.LightSource);
                    }
                }

                var shadowMaterial = sm.Material as IMaterialShadowReciever;
                if (shadowMaterial != null)
                {
                    shadowMaterial.RecieveShadows = shadowsEnabled && RecieveShadow;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;
            }
        }
Beispiel #3
0
        public void RenderDepthBuffer(IMaterial mat)
        {
            if (SkipRender)
            {
                return;
            }

            Renderer.World    = GlobalTransform;
            Renderer.CullMode = CullMode;

            var invWorld = GlobalTransform.CalcInverted();

            foreach (var sm in Submeshes)
            {
                var def = sm.Material;

                sm.Material = mat;

                var skin = sm.Material as IMaterialSkin;
                if (skin != null && sm.Bones.Count > 0)
                {
                    if (sharedBoneTransforms.Length < sm.Bones.Count)
                    {
                        sharedBoneTransforms = new Matrix44[sm.Bones.Count];
                    }
                    for (var i = 0; i < sm.Bones.Count; i++)
                    {
                        sharedBoneTransforms[i] = sm.BoneBindPoses[i] * sm.Bones[i].GlobalTransform * invWorld;
                    }

                    skin.SkinEnabled = true;
                    skin.SetBones(sharedBoneTransforms, sm.Bones.Count);
                }
                else
                {
                    skin.SkinEnabled = false;
                }

                for (int i = 0; i < sm.Material.PassCount; i++)
                {
                    sm.Material.Apply(i);
                    PlatformRenderer.DrawTriangles(sm.Mesh, 0, sm.Mesh.IndexBuffer.Data.Length);
                }
                Renderer.PolyCount3d += sm.Mesh.IndexBuffer.Data.Length / 3;

                sm.Material = def;
            }
        }
Beispiel #4
0
        private bool HitTestGeometry(Ray ray, out float distance)
        {
            var hit = false;

            distance = float.MaxValue;
            ray      = ray.Transform(GlobalTransform.CalcInverted());
            foreach (var submesh in Submeshes)
            {
                var vertices = ((IVertexBuffer <Vertex>)submesh.Mesh.VertexBuffers[0]).Data;
                for (int i = 0; i <= vertices.Length - 3; i += 3)
                {
                    var d = ray.IntersectsTriangle(vertices[i].Pos, vertices[i + 1].Pos, vertices[i + 2].Pos);
                    if (d != null && d.Value < distance)
                    {
                        distance = d.Value;
                        hit      = true;
                    }
                }
            }
            return(hit);
        }
Beispiel #5
0
 private void RecalcGlobalTransformInverse()
 {
     globalTransformInverse = GlobalTransform.CalcInverted();
 }