Пример #1
0
 public BoneModel(PartBone element) : base(element)
 {
     UpdateBoundingBox();
     SetTransformFromElement();
     BoundingBox = BBox.FromCenterSize(Vector3.Zero, Vector3.One);
     BoneLength  = 0.4f;
     UpdateModelTransforms();
     CalculateBoneLength();
 }
Пример #2
0
 private void UpdateBoundingBox()
 {
     if (Bone.Bounding != null && !Bone.Bounding.IsEmpty)
     {
         BoneBounding = BBox.FromCenterSize(
             (Vector3)Bone.Bounding.Center.ToGL(),
             (Vector3)Bone.Bounding.Size.ToGL());
     }
     else
     {
         BoneBounding = BBox.Empty;
     }
 }
Пример #3
0
        public static void DrawBoundingBox(Matrix4 transform, BBox box, Vector4 color, float thickness = 1f)
        {
            ColorShader.Use();

            ColorShader.ModelMatrix.Set(Matrix4.CreateScale(box.Size) * Matrix4.CreateTranslation(box.Center) * transform);
            ColorShader.Color.Set(color);

            BoundingBoxBufffer.Bind();
            BoundingBoxBufffer.BindAttribute(ColorShader.Position, 0);

            GL.PushAttrib(AttribMask.LineBit);
            GL.LineWidth(thickness);
            BoundingBoxBufffer.DrawElements(PrimitiveType.Lines);
            GL.PopAttrib();
        }
Пример #4
0
        public static bool IntersectsBox(Ray ray, BBox box, out float distance, bool forwardOnly = true)
        {
            var rayInv = Vector3.Divide(Vector3.One, ray.Direction);
            var t1     = Vector3.Multiply(box.Min - ray.Origin, rayInv);
            var t2     = Vector3.Multiply(box.Max - ray.Origin, rayInv);

            var vMin = Vector3.ComponentMin(t1, t2);
            var vMax = Vector3.ComponentMax(t1, t2);
            var min  = Math.Max(vMin.X, System.Math.Max(vMin.Y, vMin.Z));
            var max  = Math.Min(vMax.X, System.Math.Min(vMax.Y, vMax.Z));

            distance = float.NaN;

            if (max >= min)
            {
                distance = forwardOnly & min < 0 ? max : min;
            }

            return(!float.IsNaN(distance));
        }
Пример #5
0
        private static void InitializeBoundingBoxBuffer()
        {
            BoundingBoxBufffer = new IndexedVertexBuffer <Vector3>();
            var box = BBox.FromCenterSize(Vector3.Zero, Vector3.One);

            BoundingBoxBufffer.SetVertices(box.GetCorners());
            var bboxIndices = new List <int>();

            for (int i = 0; i < 4; i++)
            {
                bboxIndices.Add((i * 2));
                bboxIndices.Add((i * 2) + 1);
                bboxIndices.Add((i * 2));
                bboxIndices.Add(((i + 1) * 2) % 8);
                bboxIndices.Add((i * 2) + 1);
                bboxIndices.Add((((i + 1) * 2) + 1) % 8);
            }

            BoundingBoxBufffer.SetIndices(bboxIndices);
        }
Пример #6
0
        public void CalculateBoneLength()
        {
            var newLength = 0.4f;
            var target    = Bone.GetLinkedBone();

            if (target != null)
            {
                newLength = (float)(target.Transform.Position - Bone.Transform.Position).Length;
            }

            if (BoneLength != newLength)
            {
                BoneLength = newLength;
                UpdateModelTransforms();
            }

            BoundingBox = BBox.FromCenterSize(
                new Vector3((newLength / 2f) - 0.1f, 0, 0),
                new Vector3(newLength + 0.2f, 0.4f, 0.4f)
                );
            IsLengthDirty = false;
        }
Пример #7
0
        //public void BuildBoneWeightBuffer(int selectedBone)
        //{
        //    BoneWeightBuffer.ClearBuffers();

        //}

        private SurfaceModelMesh AddMeshGeometry(ModelMeshReference modelMesh, List <int> indexList, List <VertVNT> vertexList)
        {
            var geometry = modelMesh.GetGeometry();

            if (geometry == null)
            {
                Trace.WriteLine("Could not load mesh geometry!");
                return(null);
            }
            int     indexOffset     = indexList.Count;
            int     vertexOffset    = vertexList.Count;
            var     triangleIndices = geometry.GetTriangleIndices();
            Vector3 minPos          = new Vector3(9999f);
            Vector3 maxPos          = new Vector3(-9999f);

            indexList.AddRange(triangleIndices);
            bool isTextured = geometry.IsTextured;

            foreach (var vertex in geometry.Vertices)
            {
                var glVertex = new VertVNT()
                {
                    Position = vertex.Position.ToGL(),
                    Normal   = vertex.Normal.ToGL(),
                    TexCoord = isTextured ? vertex.TexCoord.ToGL() : Vector2.Zero
                };

                minPos = Vector3.ComponentMin(minPos, glVertex.Position);
                maxPos = Vector3.ComponentMax(maxPos, glVertex.Position);
                vertexList.Add(glVertex);
            }

            var model = new SurfaceModelMesh(this, modelMesh, indexOffset, geometry.IndexCount, vertexOffset);

            model.BoundingBox = BBox.FromMinMax(minPos, maxPos);

            MeshModels.Add(model);
            return(model);
        }
Пример #8
0
        private static PartialModel AppendPartialMesh(Assimp.Mesh mesh)
        {
            var primitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles;

            if (mesh.Faces[0].IndexCount == 4)
            {
                primitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Quads;
            }

            int curIdx  = GeneralMeshBuffer.IndexCount;
            int curVert = GeneralMeshBuffer.VertexCount;

            GeneralMeshBuffer.LoadModelVertices(mesh, true);
            int idxCount = GeneralMeshBuffer.IndexCount - curIdx;
            var vertices = GeneralMeshBuffer.VertexBuffer.Content.Skip(curVert);

            var bounding = BBox.FromVertices(vertices.Select(x => x.Position));

            var model = new PartialModel(GeneralMeshBuffer, curIdx, curVert, idxCount, primitiveType);

            model.LoadVertices();
            model.CalculateBoundingBox();
            return(model);
        }
Пример #9
0
 public void TransformSize(Vector3 amount)
 {
     EditedScale    = Scale + amount;
     ScaleTransform = Matrix4.CreateScale(EditedScale);
     BoundingBox    = BBox.FromCenterSize(Vector3.Zero, EditedScale);
 }
Пример #10
0
        //public static Buffer<StudGridCell> StudGridBuffer { get; private set; }

        #endregion

        public static void InitializeResources()
        {
            ColorShader          = ProgramFactory.Create <ColorShaderProgram>();
            WireframeShader      = ProgramFactory.Create <WireframeShaderProgram>();
            ModelShader          = ProgramFactory.Create <ModelShaderProgram>();
            WireframeShader2     = ProgramFactory.Create <WireframeShader2Program>();
            StudConnectionShader = ProgramFactory.Create <StudConnectionShaderProgram>();
            SimpleTextureShader  = ProgramFactory.Create <SimpleTextureShaderProgram>();

            BoundingBoxBufffer = new IndexedVertexBuffer <Vector3>();
            var box = BBox.FromCenterSize(Vector3.Zero, Vector3.One);

            BoundingBoxBufffer.SetVertices(box.GetCorners());
            var bboxIndices = new List <int>();

            for (int i = 0; i < 4; i++)
            {
                bboxIndices.Add((i * 2));
                bboxIndices.Add((i * 2) + 1);
                bboxIndices.Add((i * 2));
                bboxIndices.Add(((i + 1) * 2) % 8);
                bboxIndices.Add((i * 2) + 1);
                bboxIndices.Add((((i + 1) * 2) + 1) % 8);
            }

            BoundingBoxBufffer.SetIndices(bboxIndices);

            //StudGridBuffer = new Buffer<StudGridCell>();


            CollisionMaterial = new MaterialInfo
            {
                Diffuse   = new Vector4(1f, 0.05f, 0.05f, 1f),
                Specular  = new Vector3(1f),
                Shininess = 2f
            };

            ConnectionMaterial = new MaterialInfo
            {
                Diffuse   = new Vector4(0.95f, 0.95f, 0.05f, 1f),
                Specular  = new Vector3(1f),
                Shininess = 2f
            };

            MaleConnectorMaterial = new MaterialInfo
            {
                Diffuse   = new Vector4(0.05f, 0.05f, 0.95f, 1f),
                Specular  = new Vector3(1f),
                Shininess = 2f
            };

            FemaleConnectorMaterial = new MaterialInfo
            {
                Diffuse   = new Vector4(0.05f, 0.95f, 0.05f, 1f),
                Specular  = new Vector3(1f),
                Shininess = 2f
            };

            WireframeColor        = new Vector4(0, 0, 0, 1f);
            WireframeColorAlt     = new Vector4(0.85f, 0.85f, 0.85f, 1f);
            SelectionOutlineColor = new Vector4(1f);
        }