Esempio n. 1
0
 private void OnWidgetTransforming(Matrix4?transformation)
 {
     if (transformation.HasValue)
     {
         Document.SetSelectListTransform(transformation.Value);
     }
 }
Esempio n. 2
0
 public TextureConverter(uint[] data, int width, byte?alphaTolerance,
                         float?hullTolerance, bool?holeDetection, bool?multipartDetection,
                         bool?pixelOffsetOptimization, Matrix4?transform)
 {
     Initialize(data, width, alphaTolerance, hullTolerance, holeDetection,
                multipartDetection, pixelOffsetOptimization, transform);
 }
Esempio n. 3
0
        void ProcessStartSpatialPropAnim(ThnEvent ev)
        {
            var obj = Objects[(string)ev.Targets[0]];

            var     props  = (LuaTable)ev.Properties["spatialprops"];
            Matrix4?orient = null;
            object  tmp;

            if (ev.Properties.TryGetValue("orient", out tmp))
            {
                orient = ThnScript.GetMatrix((LuaTable)tmp);
            }
            if (obj.Camera != null)
            {
                if (orient != null)
                {
                    obj.Camera.Orientation = orient.Value;
                }
                if (ev.Duration > 0)
                {
                    FLLog.Error("Thn", "spatialpropanim.duration > 0 - unimplemented");
                    //return;
                }
            }
            if (obj.Camera == null)
            {
                FLLog.Error("Thn", "StartSpatialPropAnim unimplemented");
            }
        }
Esempio n. 4
0
        public Matrix4 GetMatrix4(StringHash key, Matrix4? @default = null)
        {
            var result = @default.GetValueOrDefault(Matrix4.Zero);

            Urho3D_Object_Event_GetMatrix4(_map, key.Hash, ref result);
            return(result);
        }
Esempio n. 5
0
        public void Update(float vw, float vh, Vector3 from, Vector3 to, Matrix4?rot = null)
        {
            pos        = from;
            projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(50), vw / vh, 0.1f, 300000);
            var up = (rot ?? Matrix4.Identity).Transform(Vector3.Up);

            view = Matrix4.LookAt(from, to, up);
            vp   = view * projection;
        }
Esempio n. 6
0
        private void OnWidgetTransformed(Matrix4?transformation)
        {
            if (transformation.HasValue)
            {
                ExecuteTransform("Manipulate", CreateMatrixMultTransformation(transformation.Value), false);
            }

            Document.EndSelectionTransform();
        }
Esempio n. 7
0
        /// <summary>
        /// Renders a 2D rectangle.
        /// </summary>
        /// <param name="xmin">The lower bounds of the the rectangle: X coordinate.</param>
        /// <param name="ymin">The lower bounds of the the rectangle: Y coordinate.</param>
        /// <param name="xmax">The upper bounds of the the rectangle: X coordinate.</param>
        /// <param name="ymax">The upper bounds of the the rectangle: Y coordinate.</param>
        /// <param name="rot">The rotation matrix, if any.</param>
        public void RenderRectangle(float xmin, float ymin, float xmax, float ymax, Matrix4?rot = null)
        {
            Matrix4 mat = Matrix4.CreateScale(xmax - xmin, ymax - ymin, 1) * (rot != null && rot.HasValue ? rot.Value : Matrix4.Identity) * Matrix4.CreateTranslation(xmin, ymin, 0);

            GL.UniformMatrix4(2, false, ref mat);
            GL.BindVertexArray(Square._VAO);
            GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, IntPtr.Zero);
            GL.BindVertexArray(0);
        }
Esempio n. 8
0
        public void DrawBillboardString(string text,
                                        Vector3 position,
                                        BitmapFont font   = null,
                                        int size          = 0,
                                        Matrix4?world     = null,
                                        Color4?color      = null,
                                        bool depthEnabled = false,
                                        float duration    = 0f)
        {
            // draw a string at a 3d position in world space.
            if (world.HasValue)
            {
                position = Vector3.Transform(position, world.Value);
            }

            //position = Vector3.Transform(position, _worldCamera.Matrix);
            Vector4 pv4 = Vector4.Transform(new Vector4(position, 1f), _graphicsDevice.ViewProjection);

            position = new Vector3(pv4 / pv4.W); // convert from clip space to screen space
            //position = Vector3.Transform(position, _graphicsDevice.ViewProjection);
            position.X = _screenCamera.Viewport.Width * (position.X * 0.5f + 0.5f);
            position.Y = _screenCamera.Viewport.Height * (1 - (position.Y * 0.5f + 0.5f)); // make y = 0 at top
            position.Z = (1f - (position.Z / (_worldCamera.Far - _worldCamera.Near))) * 2.0f - 1;

            // text is bellow the point and to the right of the point, make sure it can fit on screen, move text relative to the point.
            Vector2 stringSize = (font ?? _defaultFont).MeasureString(text);

            if (position.X < _screenCamera.Viewport.X ||
                position.Y < _screenCamera.Viewport.Y ||
                position.X - stringSize.X > _screenCamera.Viewport.X + _screenCamera.Viewport.Width ||
                position.Y - stringSize.Y > _screenCamera.Viewport.Y + _screenCamera.Viewport.Height)
            {
                return;
            }

            if (position.X + stringSize.X > _screenCamera.Viewport.X + _screenCamera.Viewport.Width) // put it to the left of the point
            {
                position.X -= stringSize.X;
            }
            if (position.Y + stringSize.Y > _screenCamera.Viewport.Y + _screenCamera.Viewport.Height) // put it above the point
            {
                position.Y -= stringSize.Y;
            }


            _textBatches.Add(new TextBatchItem()
            {
                Text         = text,
                Font         = font ?? _defaultFont,
                Size         = size,
                World        = Matrix4.CreateTranslation(position),
                Color        = color.HasValue ? color.Value : Color4.White,
                DepthEnabled = depthEnabled,
                Space        = CoordinateSpace.Screen,
                Duration     = duration
            });
        }
Esempio n. 9
0
        /// <summary>
        /// Renders a black line box.
        /// </summary>
        public void RenderLineBox(Location min, Location max, Matrix4?rot = null)
        {
            Engine.White.Bind();
            Location halfsize = (max - min) / 2;
            Matrix4  mat      = Matrix4.CreateScale(halfsize.ToOVector()) * (rot != null && rot.HasValue ? rot.Value : Matrix4.Identity) * Matrix4.CreateTranslation((min + halfsize).ToOVector());

            GL.UniformMatrix4(2, false, ref mat);
            GL.BindVertexArray(Box._VAO);
            GL.DrawElements(PrimitiveType.Lines, 24, DrawElementsType.UnsignedInt, IntPtr.Zero);
        }
Esempio n. 10
0
        private void BindMesh(ModelEntity modelEntity, int index, Matrix4?matrix = null, TextureBinder textureBinder = null, bool updateMeshData = true)
        {
            var mesh = GetMesh(index);

            if (mesh == null)
            {
                return;
            }
            if (updateMeshData)
            {
                var numTriangles = modelEntity.Triangles.Length;
                var elementCount = numTriangles * 3 * 3;
                var baseIndex    = 0;
                var positionList = new float[elementCount];
                var normalList   = new float[elementCount];
                var colorList    = new float[elementCount];
                var uvList       = new float[elementCount];
                for (var t = 0; t < numTriangles; t++)
                {
                    var triangle = modelEntity.Triangles[t];
                    for (var i = 0; i < 3; i++)
                    {
                        var index1 = baseIndex++;
                        var index2 = baseIndex++;
                        var index3 = baseIndex++;

                        var vertex = triangle.Vertices[i];
                        positionList[index1] = vertex.X;
                        positionList[index2] = vertex.Y;
                        positionList[index3] = vertex.Z;

                        var normal = triangle.Normals[i];
                        normalList[index1] = normal.X;
                        normalList[index2] = normal.Y;
                        normalList[index3] = normal.Z;

                        var color = triangle.Colors[i];
                        colorList[index1] = color.R;
                        colorList[index2] = color.G;
                        colorList[index3] = color.B;

                        var uv = triangle.Uv[i];
                        uvList[index1] = uv.X;
                        uvList[index2] = uv.Y;
                        uvList[index3] = uv.Z;
                    }
                }
                mesh.SetData(numTriangles * 3, positionList, normalList, colorList, uvList);
            }
            mesh.WorldMatrix = matrix ?? modelEntity.WorldMatrix;
            if (textureBinder != null)
            {
                mesh.Texture = modelEntity.Texture != null?textureBinder.GetTexture(modelEntity.TexturePage) : 0;
            }
        }
Esempio n. 11
0
        private static void PrepareModel(
            this NJObject obj,
            List <RenderMesh> opaque,
            List <RenderMesh> transparent,
            BufferingBridge buffer,
            Camera cam,
            NJObject activeObj,
            Matrix4?parentWorld,
            bool weighted)
        {
            Matrix4 world = obj.LocalMatrix;

            if (parentWorld.HasValue)
            {
                world *= parentWorld.Value;
            }

            if (obj.Attach != null && obj.Attach.MeshData.Length > 0)
            {
                // if a model is weighted, then the buffered vertex positions/normals will have to be set to world space, which means that world and normal matrix should be identities
                if (weighted)
                {
                    buffer.LoadToCache(obj.Attach.MeshData, world, obj == activeObj);
                }
                else if (!buffer.IsBuffered(obj.Attach.MeshData[0]))
                {
                    buffer.LoadToCache(obj.Attach.MeshData, null, false);
                }

                RenderMatrices matrices = weighted ? new(cam.ViewMatrix * cam.ProjectionMatrix) : new(world, world *cam.ViewMatrix *cam.ProjectionMatrix);

                var meshes = obj.Attach.GetDisplayMeshes();

                if (meshes.opaque.Length > 0)
                {
                    opaque.Add(new RenderMesh(meshes.opaque, matrices));
                }

                if (meshes.transparent.Length > 0)
                {
                    transparent.Add(new RenderMesh(meshes.transparent, matrices));
                }
            }

            for (int i = 0; i < obj.ChildCount; i++)
            {
                obj[i].PrepareModel(opaque, transparent, buffer, cam, activeObj, world, weighted);
            }
        }
Esempio n. 12
0
 public void SetMatrices(Matrix4?modelview, Matrix4?projection, Matrix4?hud)
 {
     if (modelview.HasValue)
     {
         this.modelview.Matrix = modelview.Value;
     }
     if (projection.HasValue)
     {
         this.projection.Matrix = projection.Value;
     }
     if (hud.HasValue)
     {
         this.hudMatrix.Matrix = hud.Value;
     }
 }
Esempio n. 13
0
 public void Batch(Entity entity, Matrix4?worldMatrix)
 {
     entityBatch.BatchItem(entity.VoxelObject, new BatchedEntity()
     {
         VoxelObject       = entity.VoxelObject,
         Position          = entity.Position,
         MeshRotation      = entity.MeshRotation,
         RenderFront       = entity.RenderFront,
         RenderAsWireframe = entity.RenderAsWireframe,
         ApplyNoLighting   = entity.ApplyNoLighting,
         ColorOverlay      = entity.ColorOverlay,
         CustomMatrix      = worldMatrix,
         OnlyRenderFor     = entity.OnlyRenderFor
     }, entity.RenderFront);
 }
Esempio n. 14
0
        internal static void GetModelLine(NJObject obj, List <Vector3> lines, Matrix4?parentWorld)
        {
            Matrix4 world = obj.LocalMatrix;

            if (parentWorld.HasValue)
            {
                world *= parentWorld.Value;

                lines.Add(Vector3.Transform(Vector3.Zero, parentWorld.Value));
                lines.Add(Vector3.Transform(Vector3.Zero, world));
            }

            for (int i = 0; i < obj.ChildCount; i++)
            {
                GetModelLine(obj[i], lines, world);
            }
        }
Esempio n. 15
0
        public Matrix4?GetInverseWorldTransform(SceneNode root)
        {
            if (!_inverseWorldTransforms.ContainsKey(root))
            {
                Matrix4?m = GetWorldTransform(root);
                if (!m.HasValue)
                {
                    return(null);
                }

                Matrix4 result = m.Value.Inverse;
                _inverseWorldTransforms.Add(root, result);
                return(result);
            }

            return(_inverseWorldTransforms[root]);
        }
Esempio n. 16
0
 public void DrawPrimitive(IPrimitive primitive,
                           CoordinateSpace coordinateSpace = CoordinateSpace.World,
                           Matrix4?world     = null,
                           bool depthEnabled = false,
                           float lineWidth   = 1.0f,
                           Color4?color      = null,
                           float duration    = 0f)
 {
     _primitiveBatches.Add(new PrimitiveBatchItem()
     {
         Primitive    = primitive,
         Space        = coordinateSpace,
         World        = world.HasValue ? world.Value : Matrix4.Identity,
         DepthEnabled = depthEnabled,
         LineWidth    = lineWidth,
         Color        = color.HasValue ? color.Value : Color4.White,
         Duration     = duration
     });
 }
Esempio n. 17
0
        public bool IsInViewFrustum(SceneNode node, SceneNode root)
        {
            if (!UseViewFrustumCulling || node.BoundingBox == null || !node.BoundingBox.IsValid)
            {
                return(true);
            }

            Matrix4?invCamTrans = this.GetInverseWorldTransform(root);
            Matrix4?worldTrans  = node.GetWorldTransform(root);

            if (!invCamTrans.HasValue || !worldTrans.HasValue)
            {
                return(false);
            }

            Matrix4 modelViewTrans = invCamTrans.Value * worldTrans.Value;

            return(this._viewFrustum.IsInViewFrustum(modelViewTrans, node.BoundingBox));
        }
        // scene entity velocity, orientation, location

        public static Matrix4 ApplyX3DTransform
        (
            Vector3 centerOffset,
            Vector3 rotation,
            Vector3 scale,
            Vector3 scaleOrientation,
            Vector3 translation,
            Matrix4?ParentTransform = null
        )
        {
            Matrix4    PDerived;
            Matrix4    R;
            Matrix4    SR;
            Quaternion qR;
            Quaternion qSR;
            Matrix4    S;
            Matrix4    C;
            Matrix4    T;

            if (ParentTransform.HasValue == false)
            {
                ParentTransform = Matrix4.Identity;
            }

            qR  = QuaternionExtensions.QuaternionFromEulerAnglesRad(rotation);
            qSR = QuaternionExtensions.QuaternionFromEulerAnglesRad(scaleOrientation);
            T   = Matrix4.CreateTranslation(translation);
            C   = Matrix4.CreateTranslation(centerOffset);
            R   = Matrix4.CreateFromQuaternion(qR);
            SR  = Matrix4.CreateFromQuaternion(qSR);
            S   = Matrix4.CreateScale(scale);

            PDerived = T
                       * C
                       * R
                       //* SR
                       * S
                       //* SR.Inverted()
                       * C.Inverted()
                       * ParentTransform.Value.Inverted();

            return(PDerived);
        }
Esempio n. 19
0
        private Matrix4 GetGlobalTransform(FbxSDK.Node node, Matrix4?parentGlobalTransform = null)
        {
            Matrix4 globalTransform        = Matrix4.Identity;
            bool    isGlobalTransformReady = false;

            if (curPose != null)
            {
                int nodeIndex = curPose.Find(node);
                if (nodeIndex >= 0)
                {
                    Matrix4 poseMat = Converter.Convert(curPose.GetMatrix(nodeIndex));

                    if (curPose.IsBindPose() || !curPose.IsLocalMatrix(nodeIndex))
                    {
                        globalTransform = poseMat;
                    }
                    else
                    {
                        if (parentGlobalTransform.HasValue)
                        {
                            globalTransform = poseMat * parentGlobalTransform.Value;
                        }
                        else
                        {
                            if (node.GetParent() != null)
                            {
                                globalTransform = poseMat * GetGlobalTransform(node.GetParent());
                            }
                        }
                    }

                    isGlobalTransformReady = true;
                }
            }

            if (isGlobalTransformReady == false)
            {
                globalTransform = Converter.Convert(node.EvaluateGlobalTransform(curTime));
            }

            return(globalTransform);
        }
Esempio n. 20
0
        private Matrix4?GetTransformMatrix(Viewport2D viewport, ViewportEvent e)
        {
            if (_currentTool == null)
            {
                return(null);
            }

            Matrix4?ret = null;

            if (State.Handle == ResizeHandle.Center)
            {
                ret = _tools.OfType <MoveTool>().First().GetTransformationMatrix(viewport, e, State, Document, _widgets);
            }
            else
            {
                ret = _currentTool.GetTransformationMatrix(viewport, e, State, Document, _widgets);
            }

            return(ret);
        }
Esempio n. 21
0
 public void DrawString(string text,
                        CoordinateSpace space = CoordinateSpace.Screen,
                        BitmapFont font       = null,
                        int size          = 0,
                        Matrix4?world     = null,
                        Color4?color      = null,
                        bool depthEnabled = false,
                        float duration    = 0f)
 {
     _textBatches.Add(new TextBatchItem()
     {
         Text         = text,
         Font         = font ?? _defaultFont,
         Size         = size,
         World        = world.HasValue ? world.Value : Matrix4.Identity,
         Color        = color.HasValue ? color.Value : Color4.White,
         DepthEnabled = depthEnabled,
         Space        = space,
         Duration     = duration
     });
 }
Esempio n. 22
0
        public Matrix4?GetWorldTransform(SceneNode root)
        {
            if (root == this)
            {
                // this is the root node
                return(LocalTransform);
            }

            if (ParentNode == null)
            {
                // without a parent there is no chance to find the root node
                return(null);
            }

            if (!_cachedWorldTransforms.ContainsKey(root))
            {
                // get world transformation of parent node
                Matrix4?parentWorldTrans = ParentNode.GetWorldTransform(root);

                if (parentWorldTrans == null)
                {
                    // there is no path to the root node
                    return(null);
                }

                // calculate new world transformation
                Matrix4 newWorldTrans = parentWorldTrans.Value * LocalTransform;

                // cache the transformation
                _cachedWorldTransforms.Add(root, newWorldTrans);

                return(newWorldTrans);
            }

            // return cached transformation
            return(_cachedWorldTransforms[root]);
        }
Esempio n. 23
0
 public void SetScaleMatrix(Matrix4 scaleMatrix)
 {
     this.scaleMatrix = scaleMatrix;
 }
Esempio n. 24
0
        public static void GetBoxMinMax(Vector3 center, Vector3 size, out Vector3 outMin, out Vector3 outMax, Matrix4?matrix = null)
        {
            var min = new Vector3(center.X - size.X, center.Y - size.Y, center.Z - size.Z);
            var max = new Vector3(center.X + size.X, center.Y + size.Y, center.Z + size.Z);

            if (matrix.HasValue)
            {
                outMin = Vector3.TransformPosition(min, matrix.Value);
                outMax = Vector3.TransformPosition(max, matrix.Value);
            }
            else
            {
                outMin = min;
                outMax = max;
            }
        }
Esempio n. 25
0
 /// <summary>
 /// Creates a custom texture from bytes and other data.
 /// </summary>
 /// <param name="data">The bytes to upload to OpenGL.</param>
 /// <param name="width">The width of the texture.</param>
 /// <param name="height">The height of the texture.</param>
 /// <param name="componentCount">The texture's component count.</param>
 /// <param name="format">The format of the bytes.</param>
 /// <param name="textureMatrix">An additional matrix to multiply the texture matrix by.</param>
 public Texture(byte[] data, int width, int height, TextureComponentCount componentCount, PixelFormat format, Matrix4?textureMatrix = null)
 {
     Name          = "Custom Texture";
     Size          = new Vector2(width, height);
     TextureMatrix = Matrix4.CreateOrthographicOffCenter(0, Size.X * 2, Size.Y * 2, 0, 0, 1);
     if (textureMatrix != null)
     {
         TextureMatrix *= (Matrix4)textureMatrix;
     }
     CreateFromBytes(data, componentCount, format);
 }
Esempio n. 26
0
        private void Initialize(uint[] data, int?width, byte?alphaTolerance,
                                float?hullTolerance, bool?holeDetection, bool?multipartDetection,
                                bool?pixelOffsetOptimization, Matrix4?transform)
        {
            if (data != null && !width.HasValue)
            {
                throw new ArgumentNullException("width", "'width' can't be null if 'data' is set.");
            }

            if (data == null && width.HasValue)
            {
                throw new ArgumentNullException("data", "'data' can't be null if 'width' is set.");
            }

            if (data != null && width.HasValue)
            {
                SetTextureData(data, width.Value);
            }

            if (alphaTolerance.HasValue)
            {
                AlphaTolerance = alphaTolerance.Value;
            }
            else
            {
                AlphaTolerance = 20;
            }

            if (hullTolerance.HasValue)
            {
                HullTolerance = hullTolerance.Value;
            }
            else
            {
                HullTolerance = 1.5f;
            }

            if (holeDetection.HasValue)
            {
                HoleDetection = holeDetection.Value;
            }
            else
            {
                HoleDetection = false;
            }

            if (multipartDetection.HasValue)
            {
                MultipartDetection = multipartDetection.Value;
            }
            else
            {
                MultipartDetection = false;
            }

            if (pixelOffsetOptimization.HasValue)
            {
                PixelOffsetOptimization = pixelOffsetOptimization.Value;
            }
            else
            {
                PixelOffsetOptimization = false;
            }

            if (transform.HasValue)
            {
                Transform = transform.Value;
            }
            else
            {
                Transform = Matrix4.Identity;
            }
        }
Esempio n. 27
0
        private void BindMesh(ModelEntity modelEntity, Matrix4?matrix = null, TextureBinder textureBinder = null, bool updateMeshData = true, Vector3[] initialVertices = null, Vector3[] initialNormals = null, Vector3[] finalVertices = null, Vector3[] finalNormals = null, float?interpolator = null)
        {
            if (!modelEntity.Visible)
            {
                return;
            }
            var mesh = GetMesh(_modelIndex++);

            if (mesh == null)
            {
                return;
            }
            //var rootEntity = modelEntity.ParentEntity as RootEntity; //todo
            mesh.WorldMatrix = matrix ?? modelEntity.WorldMatrix;
            if (updateMeshData)
            {
                var numTriangles = modelEntity.Triangles.Length;
                var elementCount = numTriangles * 3 * 3;
                var baseIndex    = 0;
                var positionList = new float[elementCount];
                var normalList   = new float[elementCount];
                var colorList    = new float[elementCount];
                var uvList       = new float[elementCount];
                for (var t = 0; t < numTriangles; t++)
                {
                    var lastVertex = Vector3.Zero;
                    var lastNormal = Vector3.Zero;
                    var lastColor  = Color.White;
                    var lastUv     = Vector3.Zero;
                    var triangle   = modelEntity.Triangles[t];
                    for (var i = 0; i < 3; i++)
                    {
                        var index1 = baseIndex++;
                        var index2 = baseIndex++;
                        var index3 = baseIndex++;

                        var sourceVertex = triangle.Vertices[i];
                        if (triangle.AttachedIndices != null)
                        {
                            var attachedIndex = triangle.AttachedIndices[i];
                            if (attachedIndex != uint.MaxValue)
                            {
                                if (!_scene.AutoAttach)
                                {
                                    sourceVertex = new Vector3(DiscardValue, DiscardValue, DiscardValue);
                                }
                            }
                        }

                        Vector3 vertex;
                        if (_scene.VibRibbonWireframe && i == 2)
                        {
                            vertex = lastVertex;
                        }
                        else
                        {
                            if (initialVertices != null && finalVertices != null && triangle.OriginalVertexIndices[i] < finalVertices.Length)
                            {
                                var initialVertex = sourceVertex + initialVertices[triangle.OriginalVertexIndices[i]];
                                var finalVertex   = sourceVertex + finalVertices[triangle.OriginalVertexIndices[i]];
                                vertex = Vector3.Lerp(initialVertex, finalVertex, interpolator.GetValueOrDefault());
                            }
                            else
                            {
                                vertex = sourceVertex;
                            }
                        }

                        positionList[index1] = vertex.X;
                        positionList[index2] = vertex.Y;
                        positionList[index3] = vertex.Z;

                        Vector3 normal;
                        if (_scene.VibRibbonWireframe && i == 2)
                        {
                            normal = lastNormal;
                        }
                        else
                        {
                            if (initialNormals != null && finalNormals != null && triangle.OriginalNormalIndices[i] < finalNormals.Length)
                            {
                                var initialNormal = triangle.Normals[i] + initialNormals[triangle.OriginalNormalIndices[i]] / 4096f;
                                var finalNormal   = triangle.Normals[i] + finalNormals[triangle.OriginalNormalIndices[i]] / 4096f;
                                normal = Vector3.Lerp(initialNormal, finalNormal, interpolator.GetValueOrDefault());
                            }
                            else
                            {
                                normal = triangle.Normals[i];
                            }
                        }

                        normalList[index1] = normal.X;
                        normalList[index2] = normal.Y;
                        normalList[index3] = normal.Z;

                        Color color;
                        if (_scene.VibRibbonWireframe && i == 2)
                        {
                            color = lastColor;
                        }
                        else
                        {
                            color = triangle.Colors[i];
                        }
                        colorList[index1] = color.R;
                        colorList[index2] = color.G;
                        colorList[index3] = color.B;

                        Vector3 uv;
                        if (_scene.VibRibbonWireframe && i == 2)
                        {
                            uv = lastUv;
                        }
                        else
                        {
                            uv = triangle.Uv[i];
                        }
                        uvList[index1] = uv.X;
                        uvList[index2] = uv.Y;
                        uvList[index3] = uv.Z;

                        lastVertex = vertex;
                        lastNormal = normal;
                        lastColor  = color;
                        lastUv     = uv;
                    }
                }
                mesh.SetData(numTriangles * 3, positionList, normalList, colorList, uvList);
            }
            if (textureBinder != null)
            {
                mesh.Texture = modelEntity.Texture != null?textureBinder.GetTexture((int)modelEntity.TexturePage) : 0;
            }
        }
Esempio n. 28
0
        public void Begin(SpriteSortMode sortMode, RenderState renderState, Sampler sampler = null, Program shader = null, Matrix4?transform = null)
        {
            if (_beginCalled)
            {
                throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");
            }

            _sortMode    = sortMode;
            _renderState = renderState;
            if (shader != null)
            {
                _shader = shader;
            }
            else
            {
                _shader = _spriteShader;
            }
            if (transform.HasValue)
            {
                _matrix = transform.Value;
            }
            else
            {
                _matrix = Matrix4.Identity;
            }
            _sampler = sampler ?? _defaultSampler;

            if (sortMode == SpriteSortMode.Immediate)
            {
                Setup();
            }

            _beginCalled = true;
        }
Esempio n. 29
0
        private void ProcessAnimationObject(AnimationObject animationObject, int frameIndex, Matrix4?parentMatrix, AnimationObject selectedAnimationObject = null, RootEntity selectedEntity = null)
        {
            var animationFrames = animationObject.AnimationFrames;
            var totalFrames     = animationFrames.Count;
            var localMatrix     = Matrix4.Identity;

            for (var f = 0; f <= frameIndex && f < totalFrames; f++)
            {
                if (!animationFrames.ContainsKey(f))
                {
                    continue;
                }

                var matrix = Matrix4.Identity;

                var sumFrame = animationFrames[f];

                if (sumFrame.Rotation != null)
                {
                    var r = Matrix4.CreateFromQuaternion(sumFrame.Rotation.Value);
                    matrix = matrix * r;
                }
                else if (sumFrame.EulerRotation != null)
                {
                    var r = GeomUtils.CreateR(sumFrame.EulerRotation.Value);
                    matrix = matrix * r;
                }

                if (sumFrame.Scale != null)
                {
                    var scale = (Vector3)sumFrame.Scale;
                    var s     = GeomUtils.CreateS(scale.X);
                    matrix = matrix * s;
                }

                if (sumFrame.Translation != null)
                {
                    var translation = (Vector3)sumFrame.Translation;
                    var t           = GeomUtils.CreateT(translation);
                    matrix = matrix * t;
                }

                var absoluteMatrixValue = sumFrame.AbsoluteMatrix;
                if (!absoluteMatrixValue)
                {
                    matrix = matrix * localMatrix;
                }
                localMatrix = matrix;
            }

            Matrix4 worldMatrix;

            if (parentMatrix != null)
            {
                worldMatrix = localMatrix * parentMatrix.Value;
                _scene.SkeletonBatch.AddLine(Vector3.TransformPosition(Vector3.One, parentMatrix.Value), Vector3.TransformPosition(Vector3.One, worldMatrix), animationObject == selectedAnimationObject ? Color.Blue : Color.Red);
            }
            else
            {
                worldMatrix = localMatrix;
            }

            if (selectedEntity != null)
            {
                var objectId = animationObject.TMDID.GetValueOrDefault();
                if (objectId > 0)
                {
                    var models = selectedEntity.GetModelsWithTMDID(objectId - 1);
                    foreach (var model in models)
                    {
                        _scene.MeshBatch.BindModelBatch(model, _animationProcessIndex++, worldMatrix, _scene.TextureBinder);
                    }
                }
            }

            foreach (var childObject in animationObject.Children)
            {
                ProcessAnimationObject(childObject, frameIndex, worldMatrix, selectedAnimationObject, selectedEntity);
            }
        }
        void ProcessVertex(ref Vector3F position, out Vector3F result)
        {
            Matrix4? nullable = new Matrix4?(PosCenter.Value.ToMatrix4());
            Matrix4  matrix4  = nullable ?? Matrix4.Identity;
            Matrix4F matrix4f = matrix4.ToMatrix4F();
            bool     inv      = matrix4f.Inverse();

            MatrixInv = inv;

            ResPosVec1 = matrix4f * Pos1n.Value.Position.ToVector3F();

            result = position;
            var sc        = new Vector3F(0.2f, 0.2f, 0.2f);
            var rposition = position * sc;

            var   l_r01   = (float)Pos01n.Value.Scale.X;
            var   relp01  = (Pos01n.Value.Position).ToVector3F();
            var   l_dist1 = (rposition - relp01);
            float l_l01   = l_dist1.Length();

            var   l_r02   = (float)Pos02n.Value.Scale.X;
            var   relp02  = (Pos02n.Value.Position).ToVector3F();
            var   l_dist2 = (rposition - relp02);
            float l_l02   = l_dist2.Length();

            var   l_r03   = (float)Pos03n.Value.Scale.X;
            var   relp03  = (Pos03n.Value.Position).ToVector3F();
            var   l_dist3 = (rposition - relp03);
            float l_l03   = l_dist3.Length();

            var   l_r04   = (float)Pos04n.Value.Scale.X;
            var   relp04  = (Pos04n.Value.Position).ToVector3F();
            var   l_dist4 = (rposition - relp04);
            float l_l04   = l_dist4.Length();

            var f = ((ResPos1.Value.Position - PosCenter.Value.Position) / sc).ToVector3F().GetNormalize();
            SphericalDirectionF sd = new SphericalDirectionF(f.X, f.Y);
            float       ax         = MathEx.Acos(f.X);
            float       ay         = MathEx.Asin(f.X);
            QuaternionF q          = new AnglesF().ToQuaternion();


            if (l_l01 <= l_r01)
            {
                var relp1 = matrix4f * Pos1n.Value.Position.ToVector3F();
                result = relp1;
            }
            if (l_l02 <= l_r02)
            {
                var relp2 = matrix4f * Pos2n.Value.Position.ToVector3F();;
                result = relp2;
            }
            if (l_l03 <= l_r03)
            {
                var relp3 = matrix4f * Pos3n.Value.Position.ToVector3F();;
                result = relp3;
            }
            if (l_l04 <= l_r04)
            {
                var relp4 = matrix4f * Pos4n.Value.Position.ToVector3F();;
                result = relp4;
            }
        }