コード例 #1
0
        public static RotateTransform3D GetRotateTransform3D(this XbimMatrix3D m)
        {
            RotateTransform3D r  = new RotateTransform3D();
            XbimQuaternion    xq = m.GetRotationQuaternion();

            r.Rotation = new QuaternionRotation3D(new Quaternion(xq.X, xq.Y, xq.Z, xq.W * (180.0 / Math.PI)));
            return(r);
        }
コード例 #2
0
ファイル: XbimMesher.cs プロジェクト: szyyoung/XbimGltf
        internal void AddMesh(byte[] mesh, XbimMatrix3D?transform = null)
        {
            int            indexBase      = Positions.Count;
            bool           needRotate     = false;
            bool           needTransform  = false;
            XbimQuaternion xq             = new XbimQuaternion(0.0, 0.0, 0.0, 1.0);
            XbimMatrix3D   transformValue = XbimMatrix3D.Identity;

            if (transform.HasValue)
            {
                transformValue = transform.Value;
                needTransform  = !transformValue.IsIdentity;
                xq             = transformValue.GetRotationQuaternion();
                // we have to build a rotation transform from the quaternion (to tranform normals later on)
                needRotate = !xq.IsIdentity();
            }
            using (var ms = new MemoryStream(mesh))
                using (var br = new BinaryReader(ms))
                {
                    var            t = br.ReadShapeTriangulation();
                    List <float[]> pts;
                    List <int>     idx;
                    t.ToPointsWithNormalsAndIndices(out pts, out idx);

                    // add to lists
                    //
                    // Commented because of https://github.com/xBimTeam/XbimGltf/issues/2
                    //Positions.Capacity += pts.Count;
                    //Normals.Capacity += pts.Count;
                    //Indices.Capacity += idx.Count;
                    foreach (var floatsArray in pts)
                    {
                        var tmpPosition = new XbimPoint3D(floatsArray[0], floatsArray[1], floatsArray[2]);
                        if (needTransform)
                        {
                            tmpPosition = transformValue.Transform(tmpPosition);
                        }
                        Positions.Add(tmpPosition);

                        var tmpNormal = new XbimVector3D(floatsArray[3], floatsArray[4], floatsArray[5]);
                        if (needRotate) //transform the normal if we have to
                        {
                            XbimQuaternion.Transform(ref tmpNormal, ref xq, out tmpNormal);
                        }
                        Normals.Add(tmpNormal);
                    }
                    foreach (var index in idx)
                    {
                        Indices.Add(index + indexBase);
                    }
                }
        }
コード例 #3
0
        public void QuaternionTests()
        {
            var q = new XbimQuaternion();

            Assert.AreEqual(true, q.IsIdentity(), "Uninitialised quaternion should be identity.");

            q = new XbimQuaternion(0.0f, 0.0f, 0.0f, 1.0f);
            Assert.AreEqual(true, q.IsIdentity(), "Should be identity when initialised with floats.");

            var mat = new XbimMatrix3D();

            q = mat.GetRotationQuaternion();
            Assert.AreEqual(true, q.IsIdentity(), "Quaternion from identity matrix shold be identity.");
        }
コード例 #4
0
        public static IfcLocalPlacement NewIfc4FullPlacement(this IModel s, XbimMatrix3D transform, bool scaleUp = false)
        {
            var localPlacement = s.Instances.New <IfcLocalPlacement>();
            var placement      = s.Instances.New <IfcAxis2Placement3D>();

            placement.Location = s.NewIfcPoint <IfcCartesianPoint>(transform.Translation, scaleUp);

            if (!transform.GetRotationQuaternion().IsIdentity())
            {
                placement.RefDirection = s.NewIfcDirection <IfcDirection>(transform.Backward, false);
                placement.Axis         = s.NewIfcDirection <IfcDirection>(transform.Up, false);
            }
            localPlacement.RelativePlacement = placement;
            return(localPlacement);
        }
コード例 #5
0
        public static Bitub.Dto.Scene.Transform ToQuaternion(this XbimMatrix3D t, double scale = 1.0)
        {
            var q = t.GetRotationQuaternion();

            return(new Bitub.Dto.Scene.Transform
            {
                Q = new Quaternion
                {
                    X = q.X,
                    Y = q.Y,
                    Z = q.Z,
                    W = q.W
                },
                T = t.Translation.ToXYZ(scale)
            });
        }
コード例 #6
0
        public void QuaternionAndMatrixOrientationTests()
        {
            var t = new XbimMatrix3D(new XbimVector3D(1, 1, 0));

            t.RotateAroundZAxis(Math.PI / 2);
            // Left chaining matrix operation => transposed in Xbim
            Assert.AreEqual(new XbimVector3D(0, 1, 0), t.Right);
            Assert.AreEqual(new XbimVector3D(-1, 0, 0), t.Up);
            Assert.AreEqual(new XbimVector3D(0, 0, 1), t.Backward);

            var q = t.GetRotationQuaternion();

            Assert.AreEqual(Math.Sqrt(2) / 2, q.W, 1e-5);
            Assert.AreEqual(Math.Sqrt(2) / 2, q.Z, 1e-5);
            Assert.AreEqual(0, q.X, 1e-8);
            Assert.AreEqual(0, q.Y, 1e-8);
        }