/// <summary> /// Takes in a <see cref="string"/> filepath and loads its data. It then returns the loaded model and all of its descendants as a list of <see cref="Model3D"/> instances. /// </summary> /// <param name="sourceFile">The original base-level file that contains the reference.</param> /// <param name="filePathRelativeToRsrc">The path of the referenced file, relative to the rsrc directory.</param> /// <param name="modelCollection">A list of every model that has been loaded recursively.</param> /// <param name="dataTreeParent">For cases where the GUI is used, this is the data tree representation.</param> /// <param name="globalTransform">The transformation to apply to all loaded models.</param> /// <param name="appendModelsToModelCollection">If true, the loaded models will be appended to <paramref name="modelCollection"/>.</param> /// <param name="extraData">Any extra data that should be included. This is mainly used by references (e.g. a reference is a <see cref="StaticSetConfig"/>, the target model in the set may be included as extra data)</param> private static List <Model3D> HandleConfigReferenceFromLiteralPath(FileInfo sourceFile, string filePathRelativeToRsrc, List <Model3D> modelCollection, DataTreeObject dataTreeParent, Transform3D globalTransform, bool appendModelsToModelCollection = true, Dictionary <string, dynamic> extraData = null) { if (filePathRelativeToRsrc == null) { return(null); } if (filePathRelativeToRsrc.StartsWith("/")) { filePathRelativeToRsrc = filePathRelativeToRsrc.Substring(1); } FileInfo referencedModel = new FileInfo(ResourceDirectoryGrabber.ResourceDirectoryPath + filePathRelativeToRsrc); if (!referencedModel.Exists) { throw new ClydeDataReadException($"ConfigReference within model at [{ResourceDirectoryGrabber.GetFormattedPathFromRsrc(sourceFile, false, false, '/')}] attempted to reference [{filePathRelativeToRsrc}], but this file could not be found!"); } List <Model3D> referencedTree = new List <Model3D>(); ClydeFileHandler.HandleClydeFile(referencedModel, referencedTree, false, dataTreeParent, false, globalTransform, extraData); if (appendModelsToModelCollection) { modelCollection.AddRange(referencedTree); } return(referencedTree); }
/// <summary> /// Attempts to resolve this <see cref="ConfigReference"/>, which is expected to point to a file, and returns the Clyde object that it points to.<para/> /// This is intended for use in cases where data must absolutely be loaded in-line. Most cases are better suited for <see cref="ConfigReferenceUtil"/> and its methods. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cfgRef"></param> /// <returns></returns> public static T ResolveFile <T>(this ConfigReference cfgRef) where T : class { if (!cfgRef.IsFileReference()) { throw new InvalidOperationException("Cannot resolve this ConfigReference as a file because the file it points to does not exist (or it references an actual config object)!"); } object clydeObject = ClydeFileHandler.GetRaw(new FileInfo(ResourceDirectoryGrabber.ResourceDirectoryPath + cfgRef.getName())); if (clydeObject == null) { throw new NullReferenceException("Failed to load Clyde file!"); } // Apply any arguments. if (clydeObject is ParameterizedConfig paramCfg) { paramCfg.ApplyArguments(cfgRef.getArguments() ?? new ArgumentMap()); } return(clydeObject as T); }
public void HandleModelConfig(FileInfo sourceFile, ModelConfig baseModel, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null, Dictionary <string, dynamic> extraData = null) { ViewerAffecterConfig vac = (ViewerAffecterConfig)baseModel.implementation; ViewerEffectConfig effect = vac.effect; SetupCosmeticInformation(vac, dataTreeParent); SKAnimatorToolsProxy.IncrementEnd(); if (effect is Skybox skybox) { string filePathRelativeToRsrc = skybox.model?.getName(); if (filePathRelativeToRsrc != null) { // If this is null, it is okay! // Certain implementations, (for instance, schemed implementations) use this to define their render scheme. if (filePathRelativeToRsrc.StartsWith("/")) { filePathRelativeToRsrc = filePathRelativeToRsrc.Substring(1); } FileInfo referencedModel = new FileInfo(ResourceDirectoryGrabber.ResourceDirectoryPath + filePathRelativeToRsrc); if (!referencedModel.Exists) { throw new ClydeDataReadException($"ViewerEffectConfig::Skybox at [{ResourceDirectoryGrabber.GetFormattedPathFromRsrc(sourceFile, false)}] attempted to reference [{filePathRelativeToRsrc}], but this file could not be found!"); } // Note to self: DO NOT USE SCALE. // The scale value of skyboxes is used for a parallax effect (the scale = "how much does the skybox move relative to the camera") // Applying this scale is not proper. Transform3D newTrs = new Transform3D(skybox.translationOrigin, Quaternion.IDENTITY); // Now one thing to note is that transforms do NOT affect skyboxes. // As such, the new translation should NOT be affected by the global transform. ClydeFileHandler.HandleClydeFile(referencedModel, modelCollection, false, dataTreeParent, false, newTrs); } } SKAnimatorToolsProxy.IncrementProgress(); }
/// <summary> /// Takes in a <see cref="ComponentModel"/> and loads its data. It then returns the loaded model and all of its descendants as a list of <see cref="Model3D"/> instances.<para/> /// WARNING: This will return <see langword="null"/> if the configreference does not reference anything! /// </summary> /// <param name="sourceFile">The original base-level file that contains the reference.</param> /// <param name="model">The reference itself, stored within a <see cref="ComponentModel"/>.</param> /// <param name="modelCollection">A list of every model that has been loaded recursively.</param> /// <param name="dataTreeParent">For cases where the GUI is used, this is the data tree representation.</param> /// <param name="globalTransform">The transformation to apply to all loaded models.</param> /// <param name="appendModelsToModelCollection">If true, the loaded models will be appended to <paramref name="modelCollection"/>.</param> /// <param name="extraData">Any extra data that should be included. This is mainly used by references (e.g. a reference is a <see cref="StaticSetConfig"/>, the target model in the set may be included as extra data)</param> public static List <Model3D> HandleComponentModel(FileInfo sourceFile, ComponentModel model, List <Model3D> modelCollection, DataTreeObject dataTreeParent, Transform3D globalTransform, bool appendModelsToModelCollection = true, Dictionary <string, dynamic> extraData = null) { if (model == null) { return(null); } if (model.model?.getName() == null) { return(null); } // This needs to be kept here since it has transform data. string filePathRelativeToRsrc = model.model.getName(); if (filePathRelativeToRsrc.StartsWith("/")) { filePathRelativeToRsrc = filePathRelativeToRsrc.Substring(1); } FileInfo referencedModel = new FileInfo(ResourceDirectoryGrabber.ResourceDirectoryPath + filePathRelativeToRsrc); if (!referencedModel.Exists) { throw new ClydeDataReadException($"ConfigReference within model at [{ResourceDirectoryGrabber.GetFormattedPathFromRsrc(sourceFile, false, false, '/')}] attempted to reference [{filePathRelativeToRsrc}], but this file could not be found!"); } List <Model3D> referencedTree = new List <Model3D>(); Transform3D newTrs = model.transform; newTrs = globalTransform.compose(newTrs); ClydeFileHandler.HandleClydeFile(referencedModel, referencedTree, false, dataTreeParent, false, newTrs, extraData); if (appendModelsToModelCollection) { modelCollection.AddRange(referencedTree); } return(referencedTree); }
public void HandleModelConfig(FileInfo sourceFile, ModelConfig baseModel, List <Model3D> modelCollection, DataTreeObject dataTreeParent = null, Transform3D globalTransform = null, Dictionary <string, dynamic> extraData = null) { MergedStaticConfig mergedStatic = (MergedStaticConfig)baseModel.implementation; ComponentModel[] componentModels = mergedStatic.models; SKAnimatorToolsProxy.IncrementEnd(componentModels.Length); foreach (ComponentModel model in componentModels) { string filePathRelativeToRsrc = model.model.getName(); if (filePathRelativeToRsrc.StartsWith("/")) { filePathRelativeToRsrc = filePathRelativeToRsrc.Substring(1); } FileInfo referencedModel = new FileInfo(ResourceDirectoryGrabber.ResourceDirectoryPath + filePathRelativeToRsrc); if (!referencedModel.Exists) { throw new ClydeDataReadException($"CompoundConfig at [{ResourceDirectoryGrabber.GetFormattedPathFromRsrc(sourceFile, false)}] attempted to reference [{filePathRelativeToRsrc}], but this file could not be found!"); } Transform3D newTrs = model.transform; newTrs = globalTransform.compose(newTrs); ClydeFileHandler.HandleClydeFile(referencedModel, modelCollection, false, dataTreeParent, transform: newTrs); SKAnimatorToolsProxy.IncrementProgress(); } }