private static void ImportCameras(List <AssetItem> assetReferences, UFile localPath, EntityInfo entityInfo, AssetItem entityAsset, AssetItem modelAsset) { if (entityInfo.Cameras == null) { return; } foreach (var camera in entityInfo.Cameras) { var cameraUrl = new UFile(localPath.GetFileName() + "_camera_" + camera.NodeName, null); var cameraEntityAsset = CreateTrackingEntity(entityAsset, modelAsset, cameraUrl, camera.NodeName); ((EntityAsset)cameraEntityAsset.Asset).Data.Components.Add(CameraComponent.Key, camera.Data); if (camera.TargetNodeName != null) { // We have a target, create an entity for it var cameraTargetUrl = new UFile(localPath.GetFileName() + "_cameratarget_" + camera.TargetNodeName, null); var cameraTargetEntityAsset = CreateTrackingEntity(entityAsset, modelAsset, cameraTargetUrl, camera.TargetNodeName); // Update target camera.Data.Target = new ContentReference <EntityData>(cameraTargetEntityAsset.Id, cameraTargetEntityAsset.Location); assetReferences.Add(cameraTargetEntityAsset); } assetReferences.Add(cameraEntityAsset); } }
public override IEnumerable <AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { // Creates the url to the texture var asset = new AssetImportObjectTest { Source = rawAssetPath, Name = rawAssetPath.GetFileName() + "Name" }; var assetUrl = new UFile(rawAssetPath.GetFileName(), null); // Emulate a change in a sub-asset var subAsset = new AssetObjectTestSub() { Value = value }; value++; var subAssetItem = new AssetItem(rawAssetPath.GetFileName() + "_SubAsset", subAsset); asset.References.Add("Test", new AssetReference <AssetObjectTestSub>(subAsset.Id, subAssetItem.Location)); var list = new List <AssetItem> { new AssetItem(assetUrl, asset), subAssetItem }; return(list); }
private static AssetItem ImportSkeleton(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo) { var asset = new SkeletonAsset { Source = assetSource }; if (entityInfo.Nodes != null) { foreach (var node in entityInfo.Nodes) { asset.Nodes.Add(new NodeInformation(node.Name, node.Depth, node.Preserve)); } } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) { asset.PreserveNodes(entityInfo.AnimationNodes); } var skeletonUrl = new UFile(localPath.GetFileName() + " Skeleton", null); var assetItem = new AssetItem(skeletonUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
/// <summary> /// Initializes a new instance of the <see cref="SettingsKey"/> class. /// </summary> /// <param name="name">The name of this settings key. Must be unique amongst the application.</param> /// <param name="group">The <see cref="SettingsGroup"/> containing this <see cref="SettingsKey"/>.</param> /// <param name="defaultValue">The default value associated to this settings key.</param> protected SettingsKey(UFile name, SettingsGroup group, object defaultValue) { Name = name; DisplayName = name.GetFileName(); DefaultObjectValue = defaultValue; Group = group; Group.RegisterSettingsKey(name, defaultValue, this); }
public void TestWithSimplePathWithExtension() { var assetPath = new UFile("/a/b/c.txt"); Assert.AreEqual("/a/b", assetPath.GetDirectory()); Assert.AreEqual("c", assetPath.GetFileName()); Assert.AreEqual(".txt", assetPath.GetFileExtension()); Assert.AreEqual("/a/b/c", assetPath.GetDirectoryAndFileName()); Assert.AreEqual("/a/b/c.txt", assetPath.FullPath); }
public override IEnumerable <AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { var asset = new SoundAsset { Source = rawAssetPath }; // Creates the url to the texture var textureUrl = new UFile(rawAssetPath.GetFileName()); yield return(new AssetItem(textureUrl, asset)); }
public void TestIsDirectoryOnly() { var dirPath = new UDirectory("/a/b/c"); Assert.Equal("/a/b/c", dirPath.GetDirectory()); var filePath = new UFile("/test.txt"); Assert.Equal("/", filePath.GetDirectory()); Assert.Equal("test.txt", filePath.GetFileName()); }
private static AssetItem ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName) { var asset = new ModelAsset { Source = assetSource }; if (entityInfo.Models != null) { var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList(); foreach (var material in entityInfo.Materials) { var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key, null)); if (foundMaterial != null) { asset.Materials.Add(new ModelMaterial { Name = material.Key, MaterialInstance = new MaterialInstance() { Material = AttachedReferenceManager.CreateSerializableVersion <Material>(foundMaterial.Id, foundMaterial.Location) } }); } } //handle the case where during import we imported no materials at all //todo Instead of null material add a default paradox material if (entityInfo.Materials.Count == 0) { asset.Materials.Add(new ModelMaterial { Name = "Material", MaterialInstance = new MaterialInstance() }); } } if (entityInfo.Nodes != null) { foreach (var node in entityInfo.Nodes) { asset.Nodes.Add(new NodeInformation(node.Name, node.Depth, node.Preserve)); } } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) { asset.PreserveNodes(entityInfo.AnimationNodes); } var modelUrl = new UFile(localPath.GetFileName() + (shouldPostFixName?" Model": ""), null); var assetItem = new AssetItem(modelUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
private static void ImportAnimation(List <AssetItem> assetReferences, UFile localPath, List <string> animationNodes) { if (animationNodes != null && animationNodes.Count > 0) { var assetSource = localPath; var animUrl = new UFile(localPath.GetFileName() + "_anim", null); var asset = new AnimationAsset { Source = assetSource }; assetReferences.Add(new AssetItem(animUrl, asset)); } }
private static void ImportAnimation(List <AssetItem> assetReferences, UFile localPath, List <string> animationNodes, bool shouldPostFixName) { if (animationNodes != null && animationNodes.Count > 0) { var assetSource = localPath; var asset = new AnimationAsset { Source = assetSource }; var animUrl = localPath.GetFileName() + (shouldPostFixName? " Animation": ""); assetReferences.Add(new AssetItem(animUrl, asset)); } }
private static void ImportTexture(List <AssetItem> assetReferences, UFile localPath, string textureFullPath) { var texturePath = new UFile(textureFullPath); var source = texturePath; var texture = new TextureAsset { Source = source, PremultiplyAlpha = false }; // Creates the url to the texture var textureUrl = GenerateFinalTextureUrl(localPath, texturePath.GetFileName()); // Create asset reference assetReferences.Add(new AssetItem(textureUrl, texture)); }
private static AssetItem ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo) { var frontAxis = Vector3.Cross(entityInfo.UpAxis, Vector3.UnitZ).Length() < MathUtil.ZeroTolerance ? Vector3.UnitY : Vector3.UnitZ; var asset = new ModelAsset { Source = assetSource, UpAxis = entityInfo.UpAxis, FrontAxis = frontAxis }; if (entityInfo.Models != null) { var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList(); foreach (var model in entityInfo.Models) { var meshParams = new MeshMaterialParameters { Parameters = model.Parameters, NodeName = model.NodeName }; var matId = model.MaterialName; var matName = GenerateFinalMaterialName(localPath, matId); var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(matName, null)); if (foundMaterial != null) { var matReference = new AssetReference <MaterialAsset>(foundMaterial.Id, foundMaterial.Location); meshParams.Material = matReference; } asset.MeshParameters.Add(model.MeshName, meshParams); } } if (entityInfo.Nodes != null) { foreach (var node in entityInfo.Nodes) { asset.Nodes.Add(new NodeInformation(node.Name, node.Depth, node.Preserve)); } } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) { asset.PreserveNodes(entityInfo.AnimationNodes); } var modelUrl = new UFile(localPath.GetFileName() + "_model", null); var assetItem = new AssetItem(modelUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
private static AssetItem ImportModel(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo, bool shouldPostFixName, AssetItem skeletonAsset) { var asset = new ModelAsset { Source = assetSource }; if (entityInfo.Models != null) { var loadedMaterials = assetReferences.Where(x => x.Asset is MaterialAsset).ToList(); foreach (var material in entityInfo.Materials) { var modelMaterial = new ModelMaterial { Name = material.Key, MaterialInstance = new MaterialInstance() }; var foundMaterial = loadedMaterials.FirstOrDefault(x => x.Location == new UFile(material.Key)); if (foundMaterial != null) { var reference = AttachedReferenceManager.CreateProxyObject <Material>(foundMaterial.Id, foundMaterial.Location); modelMaterial.MaterialInstance.Material = reference; } //todo Instead of null material add a default xenko material asset.Materials.Add(AttachId(modelMaterial)); } //handle the case where during import we imported no materials at all //todo Instead of null material add a default xenko material if (entityInfo.Materials.Count == 0) { var modelMaterial = new ModelMaterial { Name = "Material", MaterialInstance = new MaterialInstance() }; asset.Materials.Add(AttachId(modelMaterial)); } } if (skeletonAsset != null) { asset.Skeleton = AttachedReferenceManager.CreateProxyObject <Skeleton>(skeletonAsset.Id, skeletonAsset.Location); } var modelUrl = new UFile(localPath.GetFileName() + (shouldPostFixName?" Model": "")); var assetItem = new AssetItem(modelUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
private static void ImportLights(List <AssetItem> assetReferences, UFile localPath, EntityInfo entityInfo, AssetItem entityAsset, AssetItem modelAsset) { if (entityInfo.Lights == null) { return; } foreach (var light in entityInfo.Lights) { var lightUrl = new UFile(localPath.GetFileName() + "_light_" + light.NodeName, null); var cameraEntityAsset = CreateTrackingEntity(entityAsset, modelAsset, lightUrl, light.NodeName); ((EntityAsset)cameraEntityAsset.Asset).Data.Components.Add(LightComponent.Key, light.Data); assetReferences.Add(cameraEntityAsset); } }
private static AssetItem ImportSkeleton(List <AssetItem> assetReferences, UFile assetSource, UFile localPath, EntityInfo entityInfo) { var asset = new SkeletonAsset { Source = assetSource }; if (entityInfo.Nodes != null) { for (int i = 0; i < entityInfo.Nodes.Count; i++) { var node = entityInfo.Nodes[i]; var nodeInfo = new NodeInformation(node.Name, node.Depth, node.Preserve); // Try to keep identifier id consistent // TODO: We might remove this as we don't expect Skeleton asset to be inherited, but they could int sameNameAndDepthCount = 0; for (int j = 0; j < i; j++) { var againstNode = entityInfo.Nodes[i]; // If we found a node with the same name and depth, we use a increment a counter if (againstNode.Name == node.Name && againstNode.Depth == node.Depth) { sameNameAndDepthCount++; } } var nodeNameKey = nodeInfo.Name + nodeInfo.Depth + ((sameNameAndDepthCount > 0) ? "_" + sameNameAndDepthCount : string.Empty); var nodeId = ObjectId.FromBytes(Encoding.UTF8.GetBytes(nodeNameKey)).ToGuid(); IdentifiableHelper.SetId(nodeInfo, nodeId); asset.Nodes.Add(nodeInfo); } } if (entityInfo.AnimationNodes != null && entityInfo.AnimationNodes.Count > 0) { asset.PreserveNodes(entityInfo.AnimationNodes); } var skeletonUrl = new UFile(localPath.GetFileName() + " Skeleton"); var assetItem = new AssetItem(skeletonUrl, asset); assetReferences.Add(assetItem); return(assetItem); }
private static AssetItem ImportEntity(List <AssetItem> assetReferences, UFile localPath, AssetItem modelItem, EntityInfo entityInfo) { var entityUrl = new UFile(localPath.GetFileName(), null); var asset = new EntityAsset(); asset.Data.Name = entityUrl; // Use modelUrl.Path to get the url without the extension asset.Data.Components.Add(ModelComponent.Key, new ModelComponentData { Model = new ContentReference <ModelData>(modelItem.Id, modelItem.Location), Enabled = true }); var assetReference = new AssetItem(entityUrl, asset); assetReferences.Add(assetReference); return(assetReference); }
private static void ImportAnimation(List <AssetItem> assetReferences, UFile localPath, List <string> animationNodes, bool shouldPostFixName, AssetItem skeletonAsset) { if (animationNodes != null && animationNodes.Count > 0) { var assetSource = localPath; var asset = new AnimationAsset { Source = assetSource }; var animUrl = localPath.GetFileName() + (shouldPostFixName ? " Animation" : ""); if (skeletonAsset != null) { asset.Skeleton = AttachedReferenceManager.CreateSerializableVersion <Skeleton>(skeletonAsset.Id, skeletonAsset.Location); } assetReferences.Add(new AssetItem(animUrl, asset)); } }
private static void ImportTextures(IEnumerable <string> textureDependencies, List <AssetItem> assetReferences) { if (textureDependencies == null) { return; } foreach (var textureFullPath in textureDependencies.Distinct(x => x)) { var texturePath = new UFile(textureFullPath); var source = texturePath; var texture = new TextureAsset { Source = source, PremultiplyAlpha = false }; // Create asset reference assetReferences.Add(new AssetItem(texturePath.GetFileName(), texture)); } }
public void TestWithNormalization() { var assetPath = new UFile("/a/b/.././././//c.txt"); Assert.AreEqual("/a", assetPath.GetDirectory()); Assert.AreEqual("c", assetPath.GetFileName()); Assert.AreEqual(".txt", assetPath.GetFileExtension()); Assert.AreEqual("/a/c", assetPath.GetDirectoryAndFileName()); Assert.AreEqual("/a/c.txt", assetPath.FullPath); assetPath = new UFile("../.././././//c.txt"); Assert.AreEqual("../..", assetPath.GetDirectory()); Assert.AreEqual("c", assetPath.GetFileName()); Assert.AreEqual(".txt", assetPath.GetFileExtension()); Assert.AreEqual("../../c", assetPath.GetDirectoryAndFileName()); Assert.AreEqual("../../c.txt", assetPath.FullPath); assetPath = new UFile("a/../../../c.txt"); Assert.AreEqual("../../c.txt", assetPath.FullPath); }
private static AssetItem ImportEntity(List <AssetItem> assetReferences, UFile localPath, AssetItem modelItem) { var entityUrl = new UFile(localPath.GetFileName(), null); var asset = new EntityAsset { Source = localPath }; var rootEntityData = new Entity(); asset.Hierarchy.Entities.Add(rootEntityData); asset.Hierarchy.RootEntity = rootEntityData.Id; rootEntityData.Name = entityUrl; // Use modelUrl.Path to get the url without the extension rootEntityData.Add(ModelComponent.Key, new ModelComponent { Model = AttachedReferenceManager.CreateSerializableVersion <Rendering.Model>(modelItem.Id, modelItem.Location) }); var assetReference = new AssetItem(entityUrl, asset); assetReferences.Add(assetReference); return(assetReference); }
private static string GenerateFinalMaterialName(UFile localPath, string materialId) { return(localPath.GetFileName() + "_material_" + materialId); }
private static string GenerateSeparateTextureURL(UFile originalLocation, string suffixName) { return(originalLocation.GetDirectory() + "/" + SplittedTextureNamePrefix + originalLocation.GetFileName() + suffixName); }
private static UFile GenerateFinalTextureUrl(UFile localPath, string textureName) { return(new UFile(localPath.GetFileName() + '_' + textureName, null)); }
protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext) { const bool useCacheFonts = false; // compute the path of the cache files var cachedImagePath = assetAbsolutePath.GetFileName() + ".CachedImage"; var cachedFontGlyphs = assetAbsolutePath.GetFileName() + ".CachedGlyphs"; // try to import the font from the original bitmap or ttf file StaticSpriteFontData data; try { data = FontCompiler.Compile(asset); } catch (FontNotFoundException ex) { if (!useCacheFonts) { commandContext.Logger.Error("Font [{0}] was not found on this machine.", ex.FontName); return(Task.FromResult(ResultStatus.Failed)); } else { // If the original fo commandContext.Logger.Warning("Font [{0}] was not found on this machine. Trying to use cached glyphs/image", ex.FontName); if (!File.Exists(cachedFontGlyphs)) { commandContext.Logger.Error("Expecting cached glyphs [{0}]", cachedFontGlyphs); return(Task.FromResult(ResultStatus.Failed)); } if (!File.Exists(cachedImagePath)) { commandContext.Logger.Error("Expecting cached image [{0}]", cachedImagePath); return(Task.FromResult(ResultStatus.Failed)); } // read the cached glyphs using (var glyphStream = File.OpenRead(cachedFontGlyphs)) data = BinarySerialization.Read <StaticSpriteFontData>(glyphStream); // read the cached image data.Bitmaps = new[] { new ContentReference <Image>() }; using (var imageStream = File.OpenRead(cachedImagePath)) data.Bitmaps[0].Value = Image.Load(imageStream); } } // check that the font data is valid if (data == null || data.Bitmaps.Length == 0) { return(Task.FromResult(ResultStatus.Failed)); } // save the data into the database var imageUrl = Url + "__image"; data.Bitmaps[0].Location = imageUrl; var assetManager = new AssetManager(); assetManager.Save(Url, data); var image = data.Bitmaps[0].Value; // cache the generated data if (useCacheFonts) { try { // the image using (var imageStream = File.OpenWrite(cachedImagePath)) image.Save(imageStream, ImageFileType.Paradox); // the glyphs data.Bitmaps = null; using (var glyphStream = File.OpenWrite(cachedFontGlyphs)) BinarySerialization.Write(glyphStream, data); } catch (IOException ex) { commandContext.Logger.Warning("Cannot save cached glyphs [{0}] or image [{1}]", ex, cachedFontGlyphs, cachedImagePath); } } // free the objects image.Dispose(); return(Task.FromResult(ResultStatus.Successful)); }
/// <summary> /// Launch <paramref name="exePath"/> on remote host using credentials stored in EditorSettings. /// Before launching all the files requires by <paramref name="exePath"/> are copied over to host /// using the location specified in EditorSettings.Location. If <paramref name="isCoreCLR"/> is set /// all the Stride native libraries are copied over to the current directory of the game on the remote /// host via the `CoreCLRSetup` script. /// </summary> /// <param name="logger">Logger to show progress and any issues that may occur.</param> /// <param name="exePath">Path on the local machine where the executable was compiled.</param> /// <param name="isCoreCLR">Is <paramref name="exePath"/> executed against .NET Core?</param> /// <returns>True when launch was successful, false otherwise.</returns> internal static bool Launch([NotNull] LoggerResult logger, [NotNull] UFile exePath, bool isCoreCLR) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (exePath == null) { throw new ArgumentNullException(nameof(exePath)); } var host = StrideEditorSettings.Host.GetValue(); var username = StrideEditorSettings.Username.GetValue(); var port = StrideEditorSettings.Port.GetValue(); var password = Decrypt(StrideEditorSettings.Password.GetValue()); var location = new UDirectory(StrideEditorSettings.Location.GetValue()); var display = StrideEditorSettings.Display.GetValue(); var connectInfo = NewConnectionInfo(host, port, username, password); if (SyncTo(connectInfo, exePath.GetFullDirectory(), UPath.Combine(location, new UDirectory(exePath.GetFileNameWithoutExtension())), logger)) { var sshClient = new SshClient(connectInfo); try { sshClient.Connect(); if (sshClient.IsConnected) { string cmdString; SshCommand cmd; // Due to lack of Dllmap config for CoreCLR, we have to ensure that our native libraries // are copied next to the executable. The CoreCLRSetup script will check the 32-bit vs 64-bit // of the `dotnet` runner and copy the .so files from the proper x86 or x64 directory. if (isCoreCLR) { cmdString = "bash -c 'source /etc/profile ; cd " + location + "/" + exePath.GetFileNameWithoutExtension() + ";" + "sh ./CoreCLRSetup.sh'"; cmd = sshClient.CreateCommand(cmdString); cmd.Execute(); var err = cmd.Error; if (!string.IsNullOrEmpty(err)) { logger.Error(err); // We don't exit here in case of failure, we just print the error and continue // Users can then try to fix the issue directly on the remote host. } else { err = cmd.Result; if (!string.IsNullOrEmpty(err)) { logger.Info(err); } } } // Try to get the main IP of the machine var ipv4 = GetAllLocalIPv4().FirstOrDefault(); var connectionRouter = string.Empty; if (!string.IsNullOrEmpty(ipv4)) { connectionRouter = " StrideConnectionRouterRemoteIP=" + ipv4; } var dotnetEngine = StrideEditorSettings.UseCoreCLR.GetValue() ? " dotnet " : " mono "; if (!string.IsNullOrEmpty(display)) { display = " DISPLAY=" + display; } else { display = " DISPLAY=:0.0"; } cmdString = "bash -c 'source /etc/profile ; cd " + location + "/" + exePath.GetFileNameWithoutExtension() + ";" + display + connectionRouter + dotnetEngine + "./" + exePath.GetFileName() + "'"; cmd = sshClient.CreateCommand(cmdString); cmd.BeginExecute((callback) => { var res = cmd.Error; if (!string.IsNullOrEmpty(res)) { logger.Error(res); } else { res = cmd.Result; if (!string.IsNullOrEmpty(res)) { logger.Info(res); } } // Dispose of our resources as soon as we are done. cmd.Dispose(); sshClient.Dispose(); }); return(true); } } catch (Exception) { var message = Tr._p("Message", "Unable to launch {0} on host {1}"); logger.Error(string.Format(message, exePath, host)); } } return(false); }