public override void SetReference(int i, IReferenceTarget rtarg)
 {
     if (i != 0)
     {
         return;
     }
     if (rtarg == null)
     {
         target = null;
     }
     else
     {
         target = Animatable.CreateWrapper <ReferenceTarget>(rtarg);
     }
 }
Beispiel #2
0
        T CreatePlugin <T>(ulong id) where T : Animatable
        {
            if (anims.ContainsKey(id))
            {
                return(anims[id] as T);
            }

            if (!plugins.ContainsKey(id))
            {
                return(null);
            }

            var        sp = plugins[id];
            Animatable a  = PluginMgr.Create(sp.scid, sp.cid);

            anims.Add(id, a);

            return(a as T);
        }
Beispiel #3
0
        public void Export(string outputFile)
        {
            RaiseMessage("Exportation started");
            ReportProgressChanged(25);
            var babylonScene = new BabylonScene(Path.GetDirectoryName(outputFile));
            var maxScene     = Kernel.Scene;

            alreadyExportedTextures.Clear();

            if (!Directory.Exists(babylonScene.OutputPath))
            {
                RaiseError("Exportation stopped: Output folder does not exist");
                ReportProgressChanged(100);
                return;
            }

            // Global
            babylonScene.autoClear    = true;
            babylonScene.clearColor   = Loader.Core.GetBackGround(0, Interval.Forever._IInterval).ToArray();
            babylonScene.ambientColor = Loader.Core.GetAmbient(0, Interval.Forever._IInterval).ToArray();

            babylonScene.gravity = maxScene.RootNode._Node.GetVector3Property("babylonjs_gravity");

            // Cameras
            BabylonCamera mainCamera = null;

            RaiseMessage("Exporting cameras");
            foreach (var cameraNode in maxScene.NodesListBySuperClass(SuperClassID.Camera))
            {
                var babylonCamera = ExportCamera(cameraNode, babylonScene);

                if (mainCamera == null)
                {
                    mainCamera = babylonCamera;
                    babylonScene.activeCameraID = mainCamera.id;
                    RaiseMessage("Active camera set to " + mainCamera.name, true, true);
                }
            }

            if (mainCamera == null)
            {
                RaiseWarning("No camera defined", true);
            }

            // Fog
            for (var index = 0; index < Loader.Core.NumAtmospheric; index++)
            {
                var atmospheric = Loader.Core.GetAtmospheric(index);

                if (atmospheric.Active(0) && atmospheric.ClassName == "Fog")
                {
                    RaiseMessage("Exporting fog");
                    var reference  = atmospheric.GetReference(0);
                    var parameters = Animatable.CreateWrapper <ParameterBlock1>(reference);

                    babylonScene.fogColor   = (parameters["fog color"].Value as IColor).ToArray();
                    babylonScene.fogDensity = (float)parameters["density"].Value;
                    babylonScene.fogMode    = ((int)parameters["fog type"].Value) == 0 ? 3 : 1;

                    if (mainCamera != null)
                    {
                        babylonScene.fogStart = mainCamera.minZ * (float)parameters["near %"].Value;
                        babylonScene.fogEnd   = mainCamera.maxZ * (float)parameters["far %"].Value;
                    }
                }
            }

            // Meshes
            RaiseMessage("Exporting meshes");
            foreach (var meshNode in maxScene.NodesListBySuperClass(SuperClassID.GeometricObject))
            {
                ExportMesh(meshNode, babylonScene);
            }

            // Materials
            RaiseMessage("Exporting materials");
            var matsToExport = referencedMaterials.ToArray(); // Snapshot because multimaterials can export new materials

            foreach (var mat in matsToExport)
            {
                ExportMaterial(mat, babylonScene);
            }

            // Lights
            RaiseMessage("Exporting lights");
            foreach (var lightNode in maxScene.NodesListBySuperClass(SuperClassID.Light))
            {
                ExportLight(lightNode, babylonScene);
            }

            // Output
            babylonScene.Prepare(false);
            var jsonSerializer = JsonSerializer.Create();
            var sb             = new StringBuilder();
            var sw             = new StringWriter(sb, CultureInfo.InvariantCulture);

            using (var jsonWriter = new JsonTextWriterOptimized(sw))
            {
                jsonWriter.Formatting = Formatting.None;
                jsonSerializer.Serialize(jsonWriter, babylonScene);
            }
            File.WriteAllText(outputFile, sb.ToString());

            ReportProgressChanged(100);

            RaiseMessage("Exportation done");
        }
Beispiel #4
0
 internal Scene(IInterface13 x)
 {
     scene          = x.Scene;
     sceneRootNode  = Animatable.CreateWrapper <Node>(x.RootNode);
     sceneRefTarget = Animatable.CreateWrapper <ReferenceTarget>(x.ScenePointer);
 }
 public Target(Animatable a)
 {
     id = (ulong)a.AnimHandle;
 }
Beispiel #6
0
 public override Modifier Create()
 {
     return(Animatable.CreatePluginInstance <Modifier>(scid, cid));
 }
Beispiel #7
0
 public static Animatable Create(SuperClassID scid, ClassID cid)
 {
     return(Animatable.CreatePluginInstance <Animatable>(scid, cid));
 }
Beispiel #8
0
 public Animatable Create()
 {
     return(Animatable.CreateWrapper <Animatable>(_cd.Create(false) as IAnimatable));
 }
Beispiel #9
0
 public AppData GetAppData(Animatable plugin)
 {
     return(new AppData(_Anim, plugin.ClassID, plugin.SuperClassID));
 }
Beispiel #10
0
 public static ParameterBlock2 Create(IIParamBlock2 x)
 {
     return(Animatable.CreateWrapper <ParameterBlock2>(x));
 }