Пример #1
0
        void ParseTags(ref GLTFExtensionGizmo gizmo, ref GLTF gltf, ref List <AsoboTag> tags)
        {
            GLTFExtensionAsoboTags asoboTagsExtension = new GLTFExtensionAsoboTags();

            asoboTagsExtension.tags = tags.ConvertAll(x => x.ToString());
            if (tags.Count > 0)
            {
                if (gizmo.extensions == null)
                {
                    gizmo.extensions = new GLTFExtensions();
                }
                gizmo.extensions.Add(GLTFExtensionAsoboTags.SerializedName, asoboTagsExtension);

                if (gltf.extensionsUsed == null)
                {
                    gltf.extensionsUsed = new List <string>();
                }
                if (!gltf.extensionsUsed.Contains(GLTFExtensionAsoboTags.SerializedName))
                {
                    gltf.extensionsUsed.Add(GLTFExtensionAsoboTags.SerializedName);
                }
            }
        }
Пример #2
0
        public object ExportGLTFExtension <T>(T babylonObject, ExportParameters parameters, ref GLTF gltf, ILoggingProvider logger)
        {
            var babylonMesh = babylonObject as BabylonMesh;

            if (babylonMesh != null)
            {
                GLTFExtensionAsoboGizmo   gltfExtensionAsoboGizmo = new GLTFExtensionAsoboGizmo();
                List <GLTFExtensionGizmo> collisions = new List <GLTFExtensionGizmo>();
                gltfExtensionAsoboGizmo.gizmos = collisions;

                Guid guid = Guid.Empty;
                Guid.TryParse(babylonMesh.id, out guid);
                IINode maxNode = Tools.GetINodeByGuid(guid);
                foreach (IINode node in maxNode.DirectChildren())
                {
                    IObject            obj   = node.ObjectRef;
                    List <AsoboTag>    tags  = new List <AsoboTag>();
                    GLTFExtensionGizmo gizmo = new GLTFExtensionGizmo();;
                    if (new MaterialUtilities.ClassIDWrapper(obj.ClassID).Equals(BoxColliderClassID))
                    {
                        GLTFExtensionAsoboBoxParams boxParams = new GLTFExtensionAsoboBoxParams();
                        float height = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "BoxGizmo", "height");
                        float width  = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "BoxGizmo", "width");
                        float length = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "BoxGizmo", "length");
                        gizmo.Translation = FlightSimExtensionUtility.GetTranslation(node, maxNode);
                        float[] rotation = FlightSimExtensionUtility.GetRotation(node, maxNode);
                        if (!FlightSimExtensionUtility.IsDefaultRotation(rotation))
                        {
                            gizmo.Rotation = rotation;
                        }

                        boxParams.width  = width;
                        boxParams.height = height;
                        boxParams.length = length;

                        gizmo.Params = boxParams;
                        gizmo.Type   = "box";

                        bool isRoad      = FlightSimExtensionUtility.GetGizmoParameterBoolean(node, "BoxCollider", "IsRoad", IsSubClass: false);
                        bool isCollision = FlightSimExtensionUtility.GetGizmoParameterBoolean(node, "BoxCollider", "IsCollision", IsSubClass: false);

                        if (isCollision)
                        {
                            tags.Add(AsoboTag.Collision);
                        }
                        if (isRoad)
                        {
                            tags.Add(AsoboTag.Road);
                        }

                        ParseTags(ref gizmo, ref gltf, ref tags);
                        collisions.Add(gizmo);
                    }
                    else if (new MaterialUtilities.ClassIDWrapper(obj.ClassID).Equals(CylinderColliderClassID))
                    {
                        GLTFExtensionAsoboCylinderParams cylinderParams = new GLTFExtensionAsoboCylinderParams();
                        float radius = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "CylGizmo", "radius");
                        float height = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "CylGizmo", "height");
                        gizmo.Translation = FlightSimExtensionUtility.GetTranslation(node, maxNode);
                        float[] rotation = FlightSimExtensionUtility.GetRotation(node, maxNode);
                        if (!FlightSimExtensionUtility.IsDefaultRotation(rotation))
                        {
                            gizmo.Rotation = rotation;
                        }
                        cylinderParams.height = height;
                        cylinderParams.radius = radius;
                        gizmo.Params          = cylinderParams;
                        gizmo.Type            = "cylinder";

                        bool isRoad      = FlightSimExtensionUtility.GetGizmoParameterBoolean(node, "CylCollider", "IsRoad", IsSubClass: false);
                        bool isCollision = FlightSimExtensionUtility.GetGizmoParameterBoolean(node, "CylCollider", "IsCollision", IsSubClass: false);

                        if (isCollision)
                        {
                            tags.Add(AsoboTag.Collision);
                        }
                        if (isRoad)
                        {
                            tags.Add(AsoboTag.Road);
                        }

                        ParseTags(ref gizmo, ref gltf, ref tags);
                        collisions.Add(gizmo);
                    }
                    else if (new MaterialUtilities.ClassIDWrapper(obj.ClassID).Equals(SphereColliderClassID))
                    {
                        GLTFExtensionAsoboSphereParams sphereParams = new GLTFExtensionAsoboSphereParams();
                        float radius = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "SphereGizmo", "radius");
                        gizmo.Translation   = FlightSimExtensionUtility.GetTranslation(node, maxNode);
                        sphereParams.radius = radius;
                        gizmo.Type          = "sphere";
                        gizmo.Params        = sphereParams;

                        bool isRoad      = FlightSimExtensionUtility.GetGizmoParameterBoolean(node, "SphereCollider", "IsRoad", IsSubClass: false);
                        bool isCollision = FlightSimExtensionUtility.GetGizmoParameterBoolean(node, "SphereCollider", "IsCollision", IsSubClass: false);

                        if (isCollision)
                        {
                            tags.Add(AsoboTag.Collision);
                        }
                        if (isRoad)
                        {
                            tags.Add(AsoboTag.Road);
                        }

                        ParseTags(ref gizmo, ref gltf, ref tags);
                        collisions.Add(gizmo);
                    }
                }
                if (collisions.Count > 0)
                {
                    return(gltfExtensionAsoboGizmo);
                }
            }
            return(null);
        }