Exemplo n.º 1
0
        private void Init()
        {
            m_UpAxis = UpAxisType.Y_UP;
            m_Nodes  = new List <CollisionGroupNode>();

            IsRendered = false;
            IsDirty    = true;
            Triangles  = new List <CollisionTriangle>();

            CreateShader();
        }
Exemplo n.º 2
0
 public Asset(Contributor[] contributor, DateTime created, DateTime modified, Unit unit, UpAxisType upAxis, string keywords = "", string revision = "", string subject = "", string title = "")
 {
     this.contributor = contributor;
     this.created     = created;
     this.modified    = modified;
     this.unit        = unit;
     this.up_axis     = UpAxisType.Y_UP;
     this.keywords    = keywords;
     this.revision    = revision;
     this.subject     = subject;
     this.title       = title;
 }
            public ColladaScene(COLLADA collada, DAE.ImportSettings settings)
            {
                Settings    = settings;
                geometries  = FindLibraryItem <library_geometries>(collada.Items);
                images      = FindLibraryItem <library_images>(collada.Items);
                scenes      = FindLibraryItem <library_visual_scenes>(collada.Items);
                effects     = FindLibraryItem <library_effects>(collada.Items);
                controllers = FindLibraryItem <library_controllers>(collada.Items);
                materials   = FindLibraryItem <library_materials>(collada.Items);

                if (collada.asset != null)
                {
                    UpAxisType = collada.asset.up_axis;
                    UintSize   = collada.asset.unit;
                }
            }
Exemplo n.º 4
0
        public void Load(TWXmlNode assetNode)
        {
            UpAxis       = UpAxisType.None;
            UnitName     = "Unknown";
            UnitInMeters = 1;

            string up_axis = assetNode.ReadChildNodeValue("up_axis", "");

            if (up_axis == "Z_UP")
            {
                UpAxis = UpAxisType.Z_UP;
            }

            TWXmlNode unitNode = assetNode.FindChildNode("unit");

            UnitName     = unitNode.GetAttribute("inch");
            UnitInMeters = float.Parse(unitNode.GetAttribute("meter"));
        }
Exemplo n.º 5
0
            public ColladaScene(COLLADA collada, DAE.ImportSettings settings)
            {
                Settings    = settings;
                geometries  = FindLibraryItem <library_geometries>(collada.Items);
                images      = FindLibraryItem <library_images>(collada.Items);
                scenes      = FindLibraryItem <library_visual_scenes>(collada.Items);
                effects     = FindLibraryItem <library_effects>(collada.Items);
                controllers = FindLibraryItem <library_controllers>(collada.Items);
                materials   = FindLibraryItem <library_materials>(collada.Items);

                if (effects != null)
                {
                    for (int i = 0; i < effects.effect.Length; i++)
                    {
                        effectLookup.Add(effects.effect[i].id, effects.effect[i]);
                    }
                }

                if (collada.asset != null)
                {
                    UpAxisType = collada.asset.up_axis;
                    UintSize   = collada.asset.unit;
                }
            }
Exemplo n.º 6
0
 public Asset()
 {
     this.up_axisField = UpAxisType.Y_UP;
 }
Exemplo n.º 7
0
        List <ModelPrim> Parse()
        {
            var Prims = new List <ModelPrim>();

            float DEG_TO_RAD = 0.017453292519943295769236907684886f;

            if (Model == null)
            {
                return(Prims);
            }

            Matrix4 transform = Matrix4.Identity;

            UpAxisType upAxis = UpAxisType.Y_UP;

            var asset = Model.asset;

            if (asset != null)
            {
                upAxis = asset.up_axis;
                if (asset.unit != null)
                {
                    float meter = (float)asset.unit.meter;
                    transform[0, 0] = meter;
                    transform[1, 1] = meter;
                    transform[2, 2] = meter;
                }
            }

            Matrix4 rotation = Matrix4.Identity;

            if (upAxis == UpAxisType.X_UP)
            {
                rotation = Matrix4.CreateFromEulers(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
            }
            else if (upAxis == UpAxisType.Y_UP)
            {
                rotation = Matrix4.CreateFromEulers(90.0f * DEG_TO_RAD, 0.0f, 0.0f);
            }

            rotation  = rotation * transform;
            transform = rotation;

            ParseVisualScene();
            ParseMaterials();

            foreach (var item in Model.Items)
            {
                if (item is library_geometries)
                {
                    var geometries = (library_geometries)item;
                    foreach (var geo in geometries.geometry)
                    {
                        var mesh = geo.Item as mesh;
                        if (mesh == null)
                        {
                            continue;
                        }

                        var nodes = Nodes.FindAll(n => n.MeshID == geo.id);     // Find all instances of this geometry
                        if (nodes != null)
                        {
                            ModelPrim firstPrim = null;         // The first prim is actually calculated, the others are just copied from it.

                            Vector3 asset_scale  = new Vector3(1, 1, 1);
                            Vector3 asset_offset = new Vector3(0, 0, 0);            // Scale and offset between Collada and OS asset (Which is always in a unit cube)

                            foreach (var node in nodes)
                            {
                                var prim = new ModelPrim();
                                prim.ID = node.ID;
                                Prims.Add(prim);

                                // First node is used to create the asset. This is as the code to crate the byte array is somewhat
                                // erroneously placed in the ModelPrim class.
                                if (firstPrim == null)
                                {
                                    firstPrim = prim;
                                    AddPositions(out asset_scale, out asset_offset, mesh, prim, transform);     // transform is used only for inch -> meter and up axis transform.

                                    foreach (var mitem in mesh.Items)
                                    {
                                        if (mitem is triangles)
                                        {
                                            AddFacesFromPolyList(Triangles2Polylist((triangles)mitem), mesh, prim, transform);  // Transform is used to turn normals according to up axis
                                        }
                                        if (mitem is polylist)
                                        {
                                            AddFacesFromPolyList((polylist)mitem, mesh, prim, transform);
                                        }
                                    }

                                    prim.CreateAsset(UUID.Zero);
                                }
                                else
                                {
                                    // Copy the values set by Addpositions and AddFacesFromPolyList as these are the same as long as the mesh is the same
                                    prim.Asset     = firstPrim.Asset;
                                    prim.BoundMin  = firstPrim.BoundMin;
                                    prim.BoundMax  = firstPrim.BoundMax;
                                    prim.Positions = firstPrim.Positions;
                                    prim.Faces     = firstPrim.Faces;
                                }

                                // Note: This ignores any shear or similar non-linear effects. This can cause some problems but it
                                // is unlikely that authoring software can generate such matrices.
                                node.Transform.Decompose(out prim.Scale, out prim.Rotation, out prim.Position);
                                float roll, pitch, yaw;
                                node.Transform.GetEulerAngles(out roll, out pitch, out yaw);

                                // The offset created when normalizing the mesh vertices into the OS unit cube must be rotated
                                // before being added to the position part of the Collada transform.
                                Matrix4 rot    = Matrix4.CreateFromQuaternion(prim.Rotation);           // Convert rotation to matrix for for Transform
                                Vector3 offset = Vector3.Transform(asset_offset * prim.Scale, rot);     // The offset must be rotated and mutiplied by the Collada file's scale as the offset is added during rendering with the unit cube mesh already multiplied by the compound scale.
                                prim.Position += offset;
                                prim.Scale    *= asset_scale;                                           // Modify scale from Collada instance by the rescaling done in AddPositions()
                            }
                        }
                    }
                }
            }

            return(Prims);
        }
Exemplo n.º 8
0
 public asset()
 {
     up_axisField = UpAxisType.Y_UP;
 }
Exemplo n.º 9
0
 public Asset(Contributor contributor, DateTime created, DateTime modified, Unit unit, UpAxisType upAxis, string keywords = "", string revision = "", string subject = "", string title = "")
     : this(new Contributor[] { contributor }, created, modified, unit, upAxis, keywords, revision, subject, title)
 {
 }
Exemplo n.º 10
0
        List <ModelPrim> Parse()
        {
            var Prims = new List <ModelPrim>();

            float DEG_TO_RAD = 0.017453292519943295769236907684886f;

            if (Model == null)
            {
                return(Prims);
            }

            Matrix4 transform = Matrix4.Identity;

            UpAxisType upAxis = UpAxisType.Y_UP;

            var asset = Model.asset;

            if (asset != null)
            {
                upAxis = asset.up_axis;
                if (asset.unit != null)
                {
                    float meter = (float)asset.unit.meter;
                    transform[0, 0] = meter;
                    transform[1, 1] = meter;
                    transform[2, 2] = meter;
                }
            }

            Matrix4 rotation = Matrix4.Identity;

            if (upAxis == UpAxisType.X_UP)
            {
                rotation = Matrix4.CreateFromEulers(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
            }
            else if (upAxis == UpAxisType.Y_UP)
            {
                rotation = Matrix4.CreateFromEulers(90.0f * DEG_TO_RAD, 0.0f, 0.0f);
            }

            rotation  = rotation * transform;
            transform = rotation;

            ParseVisualScene();
            ParseMaterials();

            foreach (var item in Model.Items)
            {
                if (item is library_geometries)
                {
                    var geometries = (library_geometries)item;
                    foreach (var geo in geometries.geometry)
                    {
                        var mesh = geo.Item as mesh;
                        if (mesh == null)
                        {
                            continue;
                        }

                        var nodes = Nodes.FindAll(n => n.MeshID == geo.id);
                        if (nodes != null)
                        {
                            byte[] mesh_asset = null;
                            foreach (var node in nodes)
                            {
                                var prim = new ModelPrim();
                                prim.ID = node.ID;
                                Prims.Add(prim);
                                Matrix4 primTransform = transform;
                                primTransform = primTransform * node.Transform;

                                AddPositions(mesh, prim, primTransform);

                                foreach (var mitem in mesh.Items)
                                {
                                    if (mitem is triangles)
                                    {
                                        AddFacesFromPolyList(Triangles2Polylist((triangles)mitem), mesh, prim, primTransform);
                                    }
                                    if (mitem is polylist)
                                    {
                                        AddFacesFromPolyList((polylist)mitem, mesh, prim, primTransform);
                                    }
                                }

                                if (mesh_asset == null)
                                {
                                    prim.CreateAsset(UUID.Zero);
                                    mesh_asset = prim.Asset;
                                }
                                else
                                {
                                    prim.Asset = mesh_asset;
                                }
                            }
                        }
                    }
                }
            }

            return(Prims);
        }
Exemplo n.º 11
0
 public asset()
 {
     this.up_axisField = UpAxisType.Y_UP;
 }