Beispiel #1
0
        public object ExportGLTFExtension <T1, T2>(T1 babylonObject, ref T2 gltfObject, ref GLTF gltf, GLTFExporter exporter, ExtensionInfo extInfo)
        {
            var babylonMesh = babylonObject as BabylonMesh;

            if (babylonMesh != null)
            {
                GLTFExtensionAsoboFade   fade        = new GLTFExtensionAsoboFade();
                List <GLTFExtensionFade> fadeObjects = new List <GLTFExtensionFade>();
                fade.fades = fadeObjects;
                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;
                    if (new MaterialUtilities.ClassIDWrapper(obj.ClassID).Equals(SphereFadeClassID))
                    {
                        GLTFExtensionFade fadeSphere = new GLTFExtensionFade();
                        GLTFExtensionAsoboFadeSphereParams sphereParams = new GLTFExtensionAsoboFadeSphereParams();
                        float radius = FlightSimExtensionUtility.GetGizmoParameterFloat(node, "SphereGizmo", "radius");
                        fadeSphere.Translation = FlightSimExtensionUtility.GetTranslation(node, maxNode);
                        sphereParams.radius    = radius;
                        fadeSphere.Type        = "sphere";
                        fadeSphere.Params      = sphereParams;
                        fadeObjects.Add(fadeSphere);
                    }
                }
                if (fadeObjects.Count > 0)
                {
                    return(fade);
                }
            }
            return(null);
        }
Beispiel #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);
        }