Ejemplo n.º 1
0
        public static void Test_Quat_Generic_Initialization_Against_Unity(float a, float b, float c, float d)
        {
            //arrange
            Quaternion<float> genericQuat = new Quaternion<float>(a, b, c, d);
            UnityEngine.Quaternion unityQuat = new UnityEngine.Quaternion(a, b, c, d);

            //assert
            for (int i = 0; i < 4; i++)
                Assert.AreEqual(genericQuat[i], unityQuat[i]);
        }
        public void ProcessPacket(CreatePrebuildsRequest packet, NebulaConnection conn)
        {
            PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);

            if (planet.factory == null)
            {
                Log.Warn($"planet.factory was null create new one");
                planet.factory = GameMain.data.GetOrCreateFactory(planet);
            }

            PlayerAction_Build pab = GameMain.mainPlayer.controller?.actionBuild;

            if (pab != null)
            {
                //Make backup of values that are overwritten
                List <BuildPreview> tmpList   = pab.buildPreviews;
                bool tmpConfirm               = pab.waitConfirm;
                UnityEngine.Vector3    tmpPos = pab.previewPose.position;
                UnityEngine.Quaternion tmpRot = pab.previewPose.rotation;

                PlanetFactory     tmpFactory       = null;
                NearColliderLogic tmpNearcdLogic   = null;
                PlanetPhysics     tmpPlanetPhysics = null;
                float             tmpBuildArea     = GameMain.mainPlayer.mecha.buildArea;
                PlanetData        tmpData          = null;
                bool loadExternalPlanetData        = GameMain.localPlanet != planet;

                //Load temporary planet data, since host is not there
                if (loadExternalPlanetData)
                {
                    tmpFactory       = (PlanetFactory)AccessTools.Field(typeof(PlayerAction_Build), "factory").GetValue(GameMain.mainPlayer.controller.actionBuild);
                    tmpNearcdLogic   = (NearColliderLogic)AccessTools.Field(typeof(PlayerAction_Build), "nearcdLogic").GetValue(GameMain.mainPlayer.controller.actionBuild);
                    tmpPlanetPhysics = (PlanetPhysics)AccessTools.Field(typeof(PlayerAction_Build), "planetPhysics").GetValue(pab);
                    tmpData          = GameMain.mainPlayer.planetData;
                }

                //Create Prebuilds from incomming packet and prepare new position
                pab.buildPreviews = packet.GetBuildPreviews();
                pab.waitConfirm   = true;
                using (FactoryManager.EventFromServer.On())
                {
                    FactoryManager.EventFactory = planet.factory;
                    pab.previewPose.position    = new UnityEngine.Vector3(packet.PosePosition.x, packet.PosePosition.y, packet.PosePosition.z);
                    pab.previewPose.rotation    = new UnityEngine.Quaternion(packet.PoseRotation.x, packet.PoseRotation.y, packet.PoseRotation.z, packet.PoseRotation.w);

                    //Check if some mandatory variables are missing
                    if (planet.physics == null || planet.physics.colChunks == null)
                    {
                        planet.physics = new PlanetPhysics(planet);
                        planet.physics.Init();
                    }
                    if (AccessTools.Field(typeof(CargoTraffic), "beltRenderingBatch").GetValue(planet.factory.cargoTraffic) == null)
                    {
                        planet.factory.cargoTraffic.CreateRenderingBatches();
                    }
                    if (planet.aux == null)
                    {
                        planet.aux = new PlanetAuxData(planet);
                    }

                    //Set temporary Local Planet / Factory data that are needed for original methods CheckBuildConditions() and CreatePrebuilds()
                    AccessTools.Field(typeof(PlayerAction_Build), "factory").SetValue(GameMain.mainPlayer.controller.actionBuild, planet.factory);
                    AccessTools.Field(typeof(PlayerAction_Build), "planetPhysics").SetValue(GameMain.mainPlayer.controller.actionBuild, planet.physics);
                    AccessTools.Field(typeof(PlayerAction_Build), "nearcdLogic").SetValue(GameMain.mainPlayer.controller.actionBuild, planet.physics.nearColliderLogic);
                    AccessTools.Property(typeof(global::Player), "planetData").SetValue(GameMain.mainPlayer, planet, null);

                    //Check if prebuilds can be build (collision check, height check, etc)
                    GameMain.mainPlayer.mecha.buildArea = float.MaxValue;
                    bool canBuild;
                    using (FactoryManager.IgnoreBasicBuildConditionChecks.On())
                    {
                        canBuild  = pab.CheckBuildConditions();
                        canBuild &= CheckBuildingConnections(pab.buildPreviews, planet.factory.entityPool, planet.factory.prebuildPool);
                    }

                    if (canBuild)
                    {
                        FactoryManager.PacketAuthor = packet.AuthorId;
                        pab.CreatePrebuilds();
                        FactoryManager.PacketAuthor = -1;
                    }

                    //Revert changes back to the original planet
                    if (loadExternalPlanetData)
                    {
                        planet.physics.Free();
                        planet.physics = null;
                        AccessTools.Property(typeof(global::Player), "planetData").SetValue(GameMain.mainPlayer, tmpData, null);
                        AccessTools.Field(typeof(PlayerAction_Build), "planetPhysics").SetValue(GameMain.mainPlayer.controller.actionBuild, tmpPlanetPhysics);
                        AccessTools.Field(typeof(PlayerAction_Build), "factory").SetValue(GameMain.mainPlayer.controller.actionBuild, tmpFactory);
                        AccessTools.Field(typeof(PlayerAction_Build), "nearcdLogic").SetValue(GameMain.mainPlayer.controller.actionBuild, tmpNearcdLogic);
                    }

                    GameMain.mainPlayer.mecha.buildArea = tmpBuildArea;
                    FactoryManager.EventFactory         = null;
                }

                pab.buildPreviews        = tmpList;
                pab.waitConfirm          = tmpConfirm;
                pab.previewPose.position = tmpPos;
                pab.previewPose.rotation = tmpRot;
            }
        }
Ejemplo n.º 3
0
        static void WriteBackInstance(ILRuntime.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.Quaternion instance_of_this_method)
        {
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            switch (ptr_of_this_method->ObjectType)
            {
            case ObjectTypes.Object:
            {
                __mStack[ptr_of_this_method->Value] = instance_of_this_method;
            }
            break;

            case ObjectTypes.FieldReference:
            {
                var ___obj = __mStack[ptr_of_this_method->Value];
                if (___obj is ILTypeInstance)
                {
                    ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    var t = __domain.GetType(___obj.GetType()) as CLRType;
                    t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.StaticFieldReference:
            {
                var t = __domain.GetType(ptr_of_this_method->Value);
                if (t is ILType)
                {
                    ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.ArrayReference:
            {
                var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.Quaternion[];
                instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
            }
            break;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Copies data from a Unity rotation into the structure
 /// </summary>
 /// <param name="rot">Rotation data</param>
 ///
 public void CopyFrom(UnityEngine.Quaternion rot)
 {
     qx = rot.x; qy = rot.y; qz = rot.z; qw = rot.w;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Copies data from the structure to a Unity position class
 /// </summary>
 /// <param name="rot">Rotation data to copy into</param>
 ///
 public void CopyTo(ref UnityEngine.Quaternion rot)
 {
     rot.x = qx; rot.y = qy; rot.z = qz; rot.w = qw;
 }
Ejemplo n.º 6
0
 public static T Create <T>(string name, UnityEngine.Transform parent, Vector3 position, Quaternion rotation, Vector3 scale) where T : ChiselNode
 {
     return(Create <T>(name, parent, Matrix4x4.TRS(position, rotation, scale)));
 }
Ejemplo n.º 7
0
 public static T Create <T>(string name, ChiselModel model, Vector3 position, Quaternion rotation, Vector3 scale) where T : ChiselNode
 {
     return(Create <T>(name, model ? model.transform : null, position, rotation, scale));
 }
Ejemplo n.º 8
0
        public static T Create <T>(string name, UnityEngine.Transform parent, Vector3 position, Quaternion rotation, Vector3 scale) where T : ChiselNode
        {
            // TODO: ensure we're creating this in the active scene
            // TODO: handle scene being locked by version control

            if (string.IsNullOrEmpty(name))
            {
#if UNITY_EDITOR
                name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent, typeof(T).Name);
#else
                name = typeof(T).Name;
#endif
            }

            var newGameObject = new UnityEngine.GameObject(name);
#if UNITY_EDITOR
            UnityEditor.Undo.RegisterCreatedObjectUndo(newGameObject, "Created " + name);
#endif
            newGameObject.SetActive(false);
            try
            {
                var brushTransform = newGameObject.transform;
#if UNITY_EDITOR
                if (parent)
                {
                    UnityEditor.Undo.SetTransformParent(brushTransform, parent, "Move child node underneath parent operation");
                }
                UnityEditor.Undo.RecordObject(brushTransform, "Move child node to given position");
                brushTransform.localPosition = position;
                brushTransform.localRotation = rotation;
                brushTransform.localScale    = scale;
                return(UnityEditor.Undo.AddComponent <T>(newGameObject));
#else
                if (parent)
                {
                    brushTransform.SetParent(parent, false);
                }
                brushTransform.localPosition = position;
                brushTransform.localRotation = rotation;
                brushTransform.localScale    = scale;
                return(newGameObject.AddComponent <T>());
#endif
            }
            finally
            {
                newGameObject.SetActive(true);
            }
        }
Ejemplo n.º 9
0
 static public GfQuatf QuaternionToQuatf(UnityEngine.Quaternion quaternion)
 {
     // See pxr/unity quaternion layout above.
     return(new GfQuatf(quaternion.w, quaternion.x, quaternion.y, quaternion.z));
 }
Ejemplo n.º 10
0
 public static IDG.Fixed ToFixedRotation(this UnityEngine.Quaternion rotation)
 {
     return(-rotation.eulerAngles.y.ToFixed());
 }
Ejemplo n.º 11
0
 public static UnityEngine.Object Instantiate(UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation)
 {
     throw new NotImplementedException("This function was automatically generated by Mockery and has no real implementation yet.");
 }
Ejemplo n.º 12
0
        public void ProcessPacket(CreatePrebuildsRequest packet, NebulaConnection conn)
        {
            PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);

            if (planet.factory == null)
            {
                // We only execute the code if the client has loaded the factory at least once.
                // Else it will get it once it goes to the planet for the first time.
                return;
            }

            PlayerAction_Build pab = GameMain.mainPlayer.controller?.actionBuild;

            if (pab != null)
            {
                //Make backup of values that are overwritten
                List <BuildPreview> tmpList             = pab.buildPreviews;
                bool tmpConfirm                         = pab.waitConfirm;
                UnityEngine.Vector3    tmpPos           = pab.previewPose.position;
                UnityEngine.Quaternion tmpRot           = pab.previewPose.rotation;
                PlanetFactory          tmpFactory       = (PlanetFactory)AccessTools.Field(typeof(PlayerAction_Build), "factory").GetValue(GameMain.mainPlayer.controller.actionBuild);
                PlanetPhysics          tmpPlanetPhysics = (PlanetPhysics)AccessTools.Field(typeof(PlayerAction_Build), "planetPhysics").GetValue(pab);

                //Create Prebuilds from incomming packet
                pab.buildPreviews = packet.GetBuildPreviews();
                pab.waitConfirm   = true;
                using (FactoryManager.EventFromServer.On())
                {
                    FactoryManager.EventFactory = planet.factory;
                    pab.previewPose.position    = new UnityEngine.Vector3(packet.PosePosition.x, packet.PosePosition.y, packet.PosePosition.z);
                    pab.previewPose.rotation    = new UnityEngine.Quaternion(packet.PoseRotation.x, packet.PoseRotation.y, packet.PoseRotation.z, packet.PoseRotation.w);
                    AccessTools.Field(typeof(PlayerAction_Build), "factory").SetValue(GameMain.mainPlayer.controller.actionBuild, planet.factory);

                    //Create temporary physics for spawning building's colliders
                    if (planet.physics == null || planet.physics.colChunks == null)
                    {
                        planet.physics = new PlanetPhysics(planet);
                        planet.physics.Init();
                    }
                    if (AccessTools.Field(typeof(CargoTraffic), "beltRenderingBatch").GetValue(planet.factory.cargoTraffic) == null)
                    {
                        planet.factory.cargoTraffic.CreateRenderingBatches();
                    }

                    //Take item from the inventory if player is author of the build
                    if (packet.AuthorId == LocalPlayer.PlayerId)
                    {
                        foreach (BuildPreview buildPreview in pab.buildPreviews)
                        {
                            if (GameMain.mainPlayer.inhandItemId == buildPreview.item.ID && GameMain.mainPlayer.inhandItemCount > 0)
                            {
                                GameMain.mainPlayer.UseHandItems(1);
                            }
                            else
                            {
                                int num = 1;
                                GameMain.mainPlayer.package.TakeTailItems(ref buildPreview.item.ID, ref num, false);
                            }
                        }
                    }

                    AccessTools.Field(typeof(PlayerAction_Build), "planetPhysics").SetValue(GameMain.mainPlayer.controller.actionBuild, planet.physics);
                    pab.CreatePrebuilds();
                    FactoryManager.EventFactory = null;
                }

                //Author has to call this for the continuous belt building
                if (packet.AuthorId == LocalPlayer.PlayerId)
                {
                    pab.AfterPrebuild();
                }

                //Revert changes back
                AccessTools.Field(typeof(PlayerAction_Build), "planetPhysics").SetValue(GameMain.mainPlayer.controller.actionBuild, tmpPlanetPhysics);
                AccessTools.Field(typeof(PlayerAction_Build), "factory").SetValue(GameMain.mainPlayer.controller.actionBuild, tmpFactory);
                pab.buildPreviews        = tmpList;
                pab.waitConfirm          = tmpConfirm;
                pab.previewPose.position = tmpPos;
                pab.previewPose.rotation = tmpRot;
            }
        }
Ejemplo n.º 13
0
 public static UnityEngine.Vector3 ToEulerAngles(UnityEngine.Quaternion rotation)
 {
     throw new NotImplementedException("This function was automatically generated by Mockery and has no real implementation yet.");
 }
Ejemplo n.º 14
0
 public static System.Single Dot(UnityEngine.Quaternion a, UnityEngine.Quaternion b)
 {
     throw new NotImplementedException("This function was automatically generated by Mockery and has no real implementation yet.");
 }
Ejemplo n.º 15
0
 /// <summary>Write quaternion</summary>
 /// <param name="stream">Bit Stream</param>
 /// <param name="value">Value</param>
 public static void WriteQuaternion(this BitStream stream, UnityEngine.Quaternion value)
 {
     stream.WriteVector3(value.eulerAngles);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Decompose the given matrix into translation, rotation, and scale, accounting for potential
        /// handedness changes in the matrix. Returns false if the matrix is singular.
        /// </summary>
        /// <remarks>
        /// Note that for a change of handedness, all scales will invert and a corrective rotation will
        /// be aded, which will not match the original TSR values, but will be correct in terms of
        /// orientation, position and scale.
        /// </remarks>
        public static bool Decompose(
            UnityEngine.Matrix4x4 matrix,
            out UnityEngine.Vector3 translation,
            out UnityEngine.Quaternion rotation,
            out UnityEngine.Vector3 scale)
        {
            // PERFORMANCE: Move this into C++.

            translation = new UnityEngine.Vector3();
            rotation    = new UnityEngine.Quaternion();
            scale       = new UnityEngine.Vector3();

            if (matrix[3, 3] == 0.0f)
            {
                return(false);
            }

            // Normalize the matrix.
            for (int i = 0; i < 4; ++i)
            {
                for (int j = 0; j < 4; ++j)
                {
                    matrix[i, j] /= matrix[3, 3];
                }
            }

            // perspectiveMatrix is used to solve for perspective, but it also provides
            // an easy way to test for singularity of the upper 3x3 component.
            UnityEngine.Matrix4x4 persp = matrix;

            for (int i = 0; i < 3; i++)
            {
                persp[3, i] = 0;
            }
            persp[3, 3] = 1;

            if (persp.determinant == 0.0f)
            {
                return(false);
            }

            // Next take care of translation (easy).
            translation  = new UnityEngine.Vector3(matrix[0, 3], matrix[1, 3], matrix[2, 3]);
            matrix[3, 0] = 0;
            matrix[3, 1] = 0;
            matrix[3, 2] = 0;

            UnityEngine.Vector3[] rows = new UnityEngine.Vector3[3];
            UnityEngine.Vector3   Pdum3;

            // Now get scale and shear.
            for (int i = 0; i < 3; ++i)
            {
                rows[i].x = matrix[0, i];
                rows[i].y = matrix[1, i];
                rows[i].z = matrix[2, i];
            }

            // Compute X scale factor and normalize first row.
            scale.x = rows[0].magnitude;
            rows[0] = rows[0].normalized;

            // Compute XY shear factor and make 2nd row orthogonal to 1st.
            UnityEngine.Vector3 Skew;
            Skew.z  = UnityEngine.Vector3.Dot(rows[0], rows[1]);
            rows[1] = WeightedAvg(rows[1], rows[0], 1, -Skew.z);

            // Now, compute Y scale and normalize 2nd row.
            scale.y = rows[1].magnitude;
            rows[1] = rows[1].normalized;

            // Compute XZ and YZ shears, orthogonalize 3rd row.
            Skew.y  = UnityEngine.Vector3.Dot(rows[0], rows[2]);
            rows[2] = WeightedAvg(rows[2], rows[0], 1, -Skew.y);

            Skew.x  = UnityEngine.Vector3.Dot(rows[1], rows[2]);
            rows[2] = WeightedAvg(rows[2], rows[1], 1, -Skew.x);

            // Next, get Z scale and normalize 3rd row.
            scale.z = rows[2].magnitude;
            rows[2] = rows[2].normalized;

            // At this point, the matrix (in rows[]) is orthonormal.
            // Check for a coordinate system flip.  If the determinant
            // is -1, then negate the matrix and the scaling factors.
            Pdum3 = UnityEngine.Vector3.Cross(rows[1], rows[2]);
            if (UnityEngine.Vector3.Dot(rows[0], Pdum3) < 0)
            {
                for (int i = 0; i < 3; i++)
                {
                    scale[i] *= -1;
                    rows[i]  *= -1;
                }
            }

            // Now, get the rotations out, as described in the gem.

#if false
            // Euler Angles.
            rotation.y = UnityEngine.Mathf.Asin(-rows[0][2]);
            if (Mathf.Cos(rotation.y) != 0)
            {
                rotation.x = UnityEngine.Mathf.Atan2(rows[1][2], rows[2][2]);
                rotation.z = UnityEngine.Mathf.Atan2(rows[0][1], rows[0][0]);
            }
            else
            {
                rotation.x = UnityEngine.Mathf.Atan2(-rows[2][0], rows[1][1]);
                rotation.z = 0;
            }
#else
            // Quaternions.
            {
                int   i, j, k = 0;
                float root, trace = rows[0].x + rows[1].y + rows[2].z;
                if (trace > 0)
                {
                    root       = UnityEngine.Mathf.Sqrt(trace + 1.0f);
                    rotation.w = 0.5f * root;
                    root       = 0.5f / root;
                    rotation.x = root * (rows[1].z - rows[2].y);
                    rotation.y = root * (rows[2].x - rows[0].z);
                    rotation.z = root * (rows[0].y - rows[1].x);
                } // End if > 0
                else
                {
                    int[] Next = new int[] { 1, 2, 0 };
                    i = 0;
                    if (rows[1].y > rows[0].x)
                    {
                        i = 1;
                    }
                    if (rows[2].z > rows[i][i])
                    {
                        i = 2;
                    }
                    j = Next[i];
                    k = Next[j];

                    root = UnityEngine.Mathf.Sqrt(rows[i][i] - rows[j][j] - rows[k][k] + 1.0f);

                    rotation[i] = 0.5f * root;
                    root        = 0.5f / root;
                    rotation[j] = root * (rows[i][j] + rows[j][i]);
                    rotation[k] = root * (rows[i][k] + rows[k][i]);
                    rotation.w  = root * (rows[j][k] - rows[k][j]);
                } // End if <= 0
            }
#endif
            return(true);
        }
Ejemplo n.º 17
0
 public static UnityEngine.Quaternion Slerp(UnityEngine.Quaternion from, UnityEngine.Quaternion to, System.Single t)
 {
     throw new NotImplementedException("This function was automatically generated by Mockery and has no real implementation yet.");
 }
        public static bool GenerateRevolvedShapeAsset(CSGBrushMeshAsset brushMeshAsset, CSGRevolvedShapeDefinition definition)
        {
            definition.Validate();
            var surfaces     = definition.surfaceAssets;
            var descriptions = definition.surfaceDescriptions;


            var shapeVertices       = new List <Vector2>();
            var shapeSegmentIndices = new List <int>();

            GetPathVertices(definition.shape, definition.curveSegments, shapeVertices, shapeSegmentIndices);

            Vector2[][] polygonVerticesArray;
            int[][]     polygonIndicesArray;

            if (!Decomposition.ConvexPartition(shapeVertices, shapeSegmentIndices,
                                               out polygonVerticesArray,
                                               out polygonIndicesArray))
            {
                brushMeshAsset.Clear();
                return(false);
            }

            // TODO: splitting it before we do the composition would be better
            var polygonVerticesList = polygonVerticesArray.ToList();

            for (int i = polygonVerticesList.Count - 1; i >= 0; i--)
            {
                SplitPolygon(polygonVerticesList, i);
            }

            var subMeshes = new List <CSGBrushSubMesh>();

            var horzSegments         = definition.revolveSegments;           //horizontalSegments;
            var horzDegreePerSegment = definition.totalAngle / horzSegments;


            // TODO: make this work when intersecting rotation axis
            //			1. split polygons along rotation axis
            //			2. if edge lies on rotation axis, make sure we don't create infinitely thin quad
            //					collapse this quad, or prevent this from happening
            // TODO: share this code with torus generator
            for (int p = 0; p < polygonVerticesList.Count; p++)
            {
                var polygonVertices = polygonVerticesList[p];
//				var segmentIndices		= polygonIndicesArray[p];
                var shapeSegments = polygonVertices.Length;

                var vertSegments     = polygonVertices.Length;
                var descriptionIndex = new int[2 + vertSegments];

                descriptionIndex[0] = 0;
                descriptionIndex[1] = 1;

                for (int v = 0; v < vertSegments; v++)
                {
                    descriptionIndex[v + 2] = 2;
                }

                var horzOffset = definition.startAngle;
                for (int h = 1, pr = 0; h < horzSegments + 1; pr = h, h++)
                {
                    var hDegree0        = (pr * horzDegreePerSegment) + horzOffset;
                    var hDegree1        = (h * horzDegreePerSegment) + horzOffset;
                    var rotation0       = Quaternion.AngleAxis(hDegree0, Vector3.forward);
                    var rotation1       = Quaternion.AngleAxis(hDegree1, Vector3.forward);
                    var subMeshVertices = new Vector3[vertSegments * 2];
                    for (int v = 0; v < vertSegments; v++)
                    {
                        subMeshVertices[v + vertSegments] = rotation0 * new Vector3(polygonVertices[v].x, 0, polygonVertices[v].y);
                        subMeshVertices[v] = rotation1 * new Vector3(polygonVertices[v].x, 0, polygonVertices[v].y);
                    }

                    var subMesh = new CSGBrushSubMesh();
                    if (!CreateExtrudedSubMesh(subMesh, vertSegments, descriptionIndex, descriptionIndex, 0, 1, subMeshVertices, surfaces, descriptions))
                    {
                        continue;
                    }

                    if (!subMesh.Validate())
                    {
                        brushMeshAsset.Clear();
                        return(false);
                    }
                    subMeshes.Add(subMesh);
                }
            }

            brushMeshAsset.SubMeshes = subMeshes.ToArray();

            brushMeshAsset.CalculatePlanes();
            brushMeshAsset.SetDirty();
            return(true);
        }
Ejemplo n.º 19
0
 public static T Create <T>(Vector3 position, Quaternion rotation, Vector3 scale) where T : ChiselNode
 {
     return(Create <T>(null, (UnityEngine.Transform)null, position, rotation, scale));
 }
Ejemplo n.º 20
0
        public static bool Intersect(CubeXCollider src, CylinderXCollider dst, out XContact?contact)
        {
            var     invP = Quaternion.Inverse(src.Quaternion) * (dst.Position - src.Position);
            Vector3 n    = Vector3.zero;

            n.x = invP.x;
            n.z = invP.z;

            var extents = src.Size * 0.5f;
            var halfHa  = extents.y;
            var topA    = halfHa;
            var bottomA = -halfHa;
            var halfHb  = dst.Height * 0.5f;
            var topB    = invP.y + halfHb;
            var bottomB = invP.y - halfHb;

            var space    = dst.Radius;
            var sqrSpace = space * space;

            // 相撞时,俯视图下的圆和矩形必然相交
            var closest = n;

            closest.x = Mathf.Clamp(closest.x, -extents.x, extents.x);
            closest.z = Mathf.Clamp(closest.z, -extents.z, extents.z);

            if ((n - closest).sqrMagnitude > sqrSpace)
            {
                contact = null;
                return(false);
            }

            // 处理相交的情况
            Vector3 normal;
            float   penetration;
            float   verticalP = float.PositiveInfinity;
            float   horizontalP;

            var inside = false;

            if (n == closest)
            {
                inside = true;
                var disX = extents.x - Mathf.Abs(n.x);
                var disZ = extents.z - Mathf.Abs(n.z);
                //找到最近的一个面
                if (disX < disZ)
                {
                    // 沿X轴
                    if (n.x > 0)
                    {
                        closest.x = extents.x;
                    }
                    else
                    {
                        closest.x = -extents.x;
                    }
                }
                else
                {
                    // 沿Z轴
                    if (n.z > 0)
                    {
                        closest.z = extents.z;
                    }
                    else
                    {
                        closest.z = -extents.z;
                    }
                }
                horizontalP = space + (n - closest).magnitude;
            }
            else
            {
                horizontalP = space - (n - closest).magnitude;
            }

            if (Mathf.Sign(topA - topB) != Mathf.Sign(bottomB - bottomA))
            {
                // 斜向相撞
                if (topB > topA)
                {
                    verticalP = topA - bottomB;
                }
                else
                {
                    verticalP = topB - bottomA;
                }
            }

            if (horizontalP < verticalP)
            {
                normal = (src.Quaternion * (n - closest)).normalized;
                if (inside)
                {
                    normal = -normal;
                }
                penetration = horizontalP;
            }
            else
            {
                normal      = topB > topA ? Vector3.up : Vector3.down;
                penetration = verticalP;
            }
            if (normal == Vector3.zero)
            {
                normal = Vector3.up;
            }
            contact = new XContact(src, dst, normal, penetration);
            return(true);
        }
Ejemplo n.º 21
0
 public Entity BuildPlayer(UnityEngine.Vector3 pos, UnityEngine.Quaternion rot, float size, float height)
 {
     return(BuildPlayer(EntitiesManager.GetNextID(), pos, rot, size, height));
 }
Ejemplo n.º 22
0
        public static bool Intersect(CubeXCollider src, SphereXCollider dst, out XContact?contact)
        {
            // 反向旋转sphere的位置,使得可以在cube的坐标系下进行碰撞判断
            var extents = src.Size * 0.5f;
            var invQ    = Quaternion.Inverse(src.Quaternion);
            var invP    = invQ * (dst.Position - src.Position);

            // 以下所有操作都是在cube的坐标系下,随后的实际方向需要进行坐标系转换
            var n       = invP;
            var closest = n;

            closest.x = Mathf.Clamp(closest.x, -extents.x, extents.x);
            closest.y = Mathf.Clamp(closest.y, -extents.y, extents.y);
            closest.z = Mathf.Clamp(closest.z, -extents.z, extents.z);
            var inside = false;

            if (n == closest)
            {
                inside = true;
                var disX = extents.x - Mathf.Abs(n.x);
                var disY = extents.y - Mathf.Abs(n.y);
                var disZ = extents.z - Mathf.Abs(n.z);
                //找到最近的一个面
                if (disX < disY && disX < disZ)
                {
                    // 沿X轴
                    if (n.x > 0)
                    {
                        closest.x = extents.x;
                    }
                    else
                    {
                        closest.x = -extents.x;
                    }
                }
                else if (disY < disX && disY < disZ)
                {
                    // 沿Y轴
                    if (n.y > 0)
                    {
                        closest.y = extents.y;
                    }
                    else
                    {
                        closest.y = -extents.y;
                    }
                }
                else
                {
                    // 沿Z轴
                    if (n.z > 0)
                    {
                        closest.z = extents.z;
                    }
                    else
                    {
                        closest.z = -extents.z;
                    }
                }
            }
            var dir      = n - closest;
            var sqrDist  = dir.sqrMagnitude;
            var space    = dst.Radius;
            var sqrSpace = space * space;

            if (sqrDist < sqrSpace || inside)
            {
                var dist        = Mathf.Sqrt(sqrDist);
                var normal      = (src.Quaternion * dir).normalized;
                var penetration = space - dist;
                if (inside)
                {
                    normal      = -normal;
                    penetration = space + dist;
                }
                if (normal == Vector3.zero)
                {
                    normal = Vector3.up;
                }
                contact = new XContact(src, dst, normal, penetration);
                return(true);
            }
            contact = null;
            return(false);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Copies data from a Unity position and rotation into the structure
 /// </summary>
 /// <param name="pos">Position data</param>
 /// <param name="rot">Rotation data</param>
 ///
 public void CopyFrom(UnityEngine.Vector3 pos, UnityEngine.Quaternion rot)
 {
     px = pos.x; py = pos.y; pz = pos.z;
     qx = rot.x; qy = rot.y; qz = rot.z; qw = rot.w;
 }
Ejemplo n.º 24
0
 public static void DrawMesh(UnityEngine.Mesh mesh, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Material material, System.Int32 layer, UnityEngine.Camera camera, System.Int32 submeshIndex)
 {
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Copies data from the structure to a Unity position and rotation class
 /// </summary>
 /// <param name="pos">Position data to copy into</param>
 /// <param name="rot">Rotation data to copy into</param>
 ///
 public void CopyTo(ref UnityEngine.Vector3 pos, ref UnityEngine.Quaternion rot)
 {
     pos.x = px; pos.y = py; pos.z = pz;
     rot.x = qx; rot.y = qy; rot.z = qz; rot.w = qw;
 }
Ejemplo n.º 26
0
 public static void DrawMesh(UnityEngine.Mesh mesh, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Material material, System.Int32 layer)
 {
 }
Ejemplo n.º 27
0
        public static void Test_Quat_Generic_Vector_Multiplication_Against_Unity(float a, float b, float c, float d)
        {
            //arrange
            Quaternion<float> genericQuat = new Quaternion<float>(a, b, c, d);
            Vector3<float> genericVec3 = new Vector3<float>(b, c, d);

            //arrange
            UnityEngine.Quaternion unityQuat = new UnityEngine.Quaternion(a, b, c, d);
            UnityEngine.Vector3 unityVec3 = new UnityEngine.Vector3(b, c, d);

            //act
            Vector3<float> genericResultVec3 = genericQuat.RotateVector(genericVec3);
            UnityEngine.Vector3 unityResultVec3 = unityQuat * unityVec3;

            //assert
            for (int i = 0; i < 3; i++)
                //for Vector3 I rewrote the code so that it mostly matched UnityEngine after JIT values, not that I looked at the JIT compiled code but the values matched
                //after changing it. However, for some reason these do not line up like before. Operator overloads aren't equivalent to methods and something is happening
                //to make this not equivalent even though it's the same exact floating point math C# code.
                Assert.AreEqual(genericResultVec3[i], unityResultVec3[i], Math.Abs((((int)unityResultVec3[i]) * Vector3<float>.kEpsilon)));
        }
Ejemplo n.º 28
0
 public static void DrawMesh(UnityEngine.Mesh mesh, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Material material, System.Int32 layer, UnityEngine.Camera camera, System.Int32 submeshIndex, UnityEngine.MaterialPropertyBlock properties, System.Boolean castShadows, System.Boolean receiveShadows)
 {
 }
Ejemplo n.º 29
0
        public static void Test_Quat_Generic_QuatAndQuat_Multiplication_Against_Unity(float a, float b, float c, float d, float e, float f)
        {
            float g = (float)(new Random(System.DateTime.UtcNow.Millisecond).NextDouble());

            //arrange
            Quaternion<float> genericQuatOne = new Quaternion<float>(a, b, c, d);
            Quaternion<float> genericQuatTwo = new Quaternion<float>(d, e, f, g);

            UnityEngine.Quaternion unityQuatTwo = new UnityEngine.Quaternion(d, e, f, g);
            UnityEngine.Quaternion unityQuatOne = new UnityEngine.Quaternion(a, b, c, d);

            //act
            Quaternion<float> genericResult = genericQuatOne.MultiplyBy(genericQuatTwo);
            UnityEngine.Quaternion unityResult = unityQuatOne * unityQuatTwo;

            //assert
            for (int i = 0; i < 4; i++)//for some reason this works with precision. Maybe too much floating point math in the vector one.
                Assert.AreEqual(genericResult[i], unityResult[i]);
        }
Ejemplo n.º 30
0
 public static void DrawMesh(UnityEngine.Mesh mesh, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation)
 {
 }
Ejemplo n.º 31
0
        public static void UnPack(ObjectTranslator translator, RealStatePtr L, int idx, out UnityEngine.Quaternion val)
        {
            val = new UnityEngine.Quaternion();
            int top = LuaAPI.lua_gettop(L);

            if (Utils.LoadField(L, idx, "x"))
            {
                translator.Get(L, top + 1, out val.x);
            }
            LuaAPI.lua_pop(L, 1);

            if (Utils.LoadField(L, idx, "y"))
            {
                translator.Get(L, top + 1, out val.y);
            }
            LuaAPI.lua_pop(L, 1);

            if (Utils.LoadField(L, idx, "z"))
            {
                translator.Get(L, top + 1, out val.z);
            }
            LuaAPI.lua_pop(L, 1);

            if (Utils.LoadField(L, idx, "w"))
            {
                translator.Get(L, top + 1, out val.w);
            }
            LuaAPI.lua_pop(L, 1);
        }
Ejemplo n.º 32
0
 public static void DrawMesh(UnityEngine.Mesh mesh, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.Int32 materialIndex)
 {
 }
 /// <summary>
 /// Translation from basic BSEngine Types to UnityEnginge Types
 /// </summary>
 /// <param name="obj">Object to transfrom</param>
 /// <returns>Object with translated type</returns>
 private static object BSEngineToUnity(object obj)
 {
     if (obj.GetType() == typeof(BSEngine.Math.Vector2))
     {
         BSEngine.Math.Vector2 bse = (BSEngine.Math.Vector2)obj;
         UnityEngine.Vector2 v2 = new UnityEngine.Vector2(bse.x, bse.y);
         return v2;
     }
     else if (obj.GetType() == typeof(BSEngine.Math.Vector3))
     {
         BSEngine.Math.Vector3 bse = (BSEngine.Math.Vector3)obj;
         UnityEngine.Vector3 v3 = new UnityEngine.Vector3(bse.x, bse.y, bse.z);
         return v3;
     }
     else if (obj.GetType() == typeof(BSEngine.Math.Vector4))
     {
         BSEngine.Math.Vector4 bse = (BSEngine.Math.Vector4)obj;
         UnityEngine.Vector4 v4 = new UnityEngine.Vector4(bse.x, bse.y, bse.z, bse.w);
         return v4;
     }
     else if (obj.GetType() == typeof(BSEngine.Math.Quaternion))
     {
         BSEngine.Math.Quaternion bse = (BSEngine.Math.Quaternion)obj;
         UnityEngine.Quaternion q = new UnityEngine.Quaternion(bse.x, bse.y, bse.z, bse.w);
         return q;
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 34
0
        private void ProcessAssets()
        {
            Logger.Info("Process Assets...");


            Dictionary <Transform, UnityEngine.Transform> tfLookup  = new Dictionary <Transform, UnityEngine.Transform>();
            Dictionary <UnityEngine.Transform, Transform> tfLookup2 = new Dictionary <UnityEngine.Transform, Transform>();

            foreach (var assetsFile in assetsFileList)
            {
                foreach (var obj in assetsFile.Objects)
                {
                    if (obj is GameObject m_GameObject)
                    {
                        //unity parse
                        UnityEngine.GameObject go = new UnityEngine.GameObject();
                        go.name = m_GameObject.m_Name;

                        var goCmp = go.AddComponent <DumpedGameObject>();
                        goCmp.m_PathID = obj.m_PathID;

                        foreach (var pptr in m_GameObject.m_Components)
                        {
                            if (pptr.TryGet(out var m_Component))
                            {
                                switch (m_Component)
                                {
                                case Transform m_Transform:
                                    m_GameObject.m_Transform = m_Transform;
                                    //unity parse
                                    Vector3    v1 = m_Transform.m_LocalPosition;
                                    Quaternion v2 = m_Transform.m_LocalRotation;
                                    Vector3    v3 = m_Transform.m_LocalScale;
                                    go.transform.localPosition = new UnityEngine.Vector3(v1.X, v1.Y, v1.Z);
                                    go.transform.localRotation = new UnityEngine.Quaternion(v2.X, v2.Y, v2.Z, v2.W);
                                    go.transform.localScale    = new UnityEngine.Vector3(v3.X, v3.Y, v3.Z);

                                    tfLookup.Add(m_Transform, go.transform);
                                    tfLookup2.Add(go.transform, m_Transform);
                                    break;

                                case MeshRenderer m_MeshRenderer:
                                    m_GameObject.m_MeshRenderer = m_MeshRenderer;
                                    //unity parse
                                    var meshRenderer = go.AddComponent <UnityEngine.MeshRenderer>();
                                    meshRenderer.sharedMaterials = m_MeshRenderer.UnityMaterials;
                                    break;

                                case MeshFilter m_MeshFilter:
                                    m_GameObject.m_MeshFilter = m_MeshFilter;

                                    //unity parse
                                    var filter = go.AddComponent <UnityEngine.MeshFilter>();
                                    {
                                        if (m_MeshFilter.m_Mesh.TryGet(out var mesh))
                                        {
                                            filter.sharedMesh = mesh.UnityMesh;
                                        }
                                    }


                                    break;

                                case SkinnedMeshRenderer m_SkinnedMeshRenderer:
                                    m_GameObject.m_SkinnedMeshRenderer = m_SkinnedMeshRenderer;

                                    var skinnedMeshRenderer = go.AddComponent <UnityEngine.SkinnedMeshRenderer>();
                                    {
                                        if (m_SkinnedMeshRenderer.m_Mesh.TryGet(out var mesh))
                                        {
                                            skinnedMeshRenderer.sharedMesh = mesh.UnityMesh;
                                        }
                                        skinnedMeshRenderer.sharedMaterials = m_SkinnedMeshRenderer.UnityMaterials;
                                    }

                                    break;

                                case Animator m_Animator:
                                    m_GameObject.m_Animator = m_Animator;

                                    var animator = go.AddComponent <UnityEngine.Animator>();

                                    break;

                                case Animation m_Animation:
                                    m_GameObject.m_Animation = m_Animation;
                                    var animation = go.AddComponent <UnityEngine.Animation>();
                                    break;

                                case MonoBehaviour m_MonoBehaviour:
                                    var cmp = go.AddComponent <DumpedBehaviour>();

                                    if (m_MonoBehaviour.m_Script.TryGet(out var script))
                                    {
                                        if (!string.IsNullOrEmpty(script.m_Namespace))
                                        {
                                            cmp.m_ScriptName = string.Format("{0}.{1}.{2}", script.m_AssemblyName, script.m_Namespace, script.m_ClassName);
                                        }
                                        else
                                        {
                                            cmp.m_ScriptName = string.Format("{0}.{2}", script.m_AssemblyName, script.m_Namespace, script.m_ClassName);
                                        }
                                        cmp.m_ClassName = script.m_ClassName;
                                        cmp.m_PathID    = m_MonoBehaviour.m_PathID;

                                        var type = m_MonoBehaviour.ToType();
                                        if (type == null)
                                        {
                                            var nodes = m_MonoBehaviour.TypeTreeNodes;
                                            type = m_MonoBehaviour.ToType(nodes);
                                        }
                                        var str = JsonConvert.SerializeObject(type, Formatting.Indented);
                                        cmp.m_DumpedJson = str;
                                    }
                                    else
                                    {
                                        cmp.m_ScriptName = "null";
                                    }
                                    break;

                                default:

                                    break;
                                }
                            }
                        }
                    }
                    else if (obj is SpriteAtlas m_SpriteAtlas)
                    {
                        foreach (var m_PackedSprite in m_SpriteAtlas.m_PackedSprites)
                        {
                            if (m_PackedSprite.TryGet(out var m_Sprite))
                            {
                                if (m_Sprite.m_SpriteAtlas.IsNull)
                                {
                                    m_Sprite.m_SpriteAtlas.Set(m_SpriteAtlas);
                                }
                            }
                        }
                    }
                }
            }

            foreach (var item in tfLookup2)
            {
                var unityTf  = item.Key;
                var parsedTf = item.Value;

                if (parsedTf.m_Father.TryGet(out var father))
                {
                    UnityEngine.Vector3    pre1 = unityTf.transform.localPosition;
                    UnityEngine.Quaternion pre2 = unityTf.transform.localRotation;
                    UnityEngine.Vector3    pre3 = unityTf.transform.localScale;
                    unityTf.parent        = tfLookup[father];
                    unityTf.localPosition = pre1;
                    unityTf.localRotation = pre2;
                    unityTf.localScale    = pre3;
                }
            }
        }