/// <summary> /// The handle. /// </summary> /// <param name="assetManager"> /// The asset manager. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="IAsset"/>. /// </returns> public IAsset Handle(IAssetManager assetManager, string name, IRawAsset data) { if (data is CompiledAsset) { return(new ModelAsset(_modelSerializer, name, null, null, data.GetProperty <PlatformData>("PlatformData"), false, string.Empty, null)); } PlatformData platformData = null; if (data.GetProperty <PlatformData>("PlatformData") != null) { platformData = new PlatformData { Platform = data.GetProperty <PlatformData>("PlatformData").Platform, Data = data.GetProperty <PlatformData>("PlatformData").Data }; } var model = new ModelAsset( _modelSerializer, name, ByteReader.ReadAsByteArray(data.GetProperty <object>("RawData")), data.GetProperty <System.Collections.Generic.Dictionary <string, byte[]> >("RawAdditionalAnimations"), platformData, data.GetProperty <bool>("SourcedFromRaw"), data.GetProperty <string>("Extension"), data.GetProperty <string[]>("ImportOptions")); return(model); }
public GoalEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary <string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f + 0.4f; this.Z = y / 16f + 0.4f; this.CanPickup = false; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.Width = 0.2f; this.Depth = 0.2f; this.m_GoalTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.Goal"); this.m_GoalModel = assetManagerProvider.GetAssetManager().Get <ModelAsset>("model.Goal"); }
public CrateEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary <string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f; this.Z = y / 16f; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.CanPush = true; this.Width = 0.8f; this.Depth = 0.8f; this.m_BlueCrateTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.BlueCrate"); this.m_RedCrateTexture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.RedCrate"); this.m_CrateModel = assetManagerProvider.GetAssetManager().Get <ModelAsset>("model.Crate"); }
public CrateEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary<string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f; this.Z = y / 16f; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.CanPush = true; this.Width = 0.8f; this.Depth = 0.8f; this.m_BlueCrateTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.BlueCrate"); this.m_RedCrateTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.RedCrate"); this.m_CrateModel = assetManagerProvider.GetAssetManager().Get<ModelAsset>("model.Crate"); }
public GoalEntity( I2DRenderUtilities twodRenderUtilities, ICubeRenderer cubeRenderer, IAssetManagerProvider assetManagerProvider, INetworkAPI networkAPI, int id, int x, int y, Dictionary<string, string> attributes) : base(twodRenderUtilities, cubeRenderer, assetManagerProvider, networkAPI, Convert.ToInt32(attributes["NetworkID"])) { this.X = x / 16f + 0.4f; this.Z = y / 16f + 0.4f; this.CanPickup = false; this.JoinShouldOwn = Convert.ToBoolean(attributes["JoinOwns"]); this.Width = 0.2f; this.Depth = 0.2f; this.m_GoalTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.Goal"); this.m_GoalModel = assetManagerProvider.GetAssetManager().Get<ModelAsset>("model.Goal"); }
public ModelAssetControl(ModelAsset asset) { InitializeComponent(); Handler = new ModelAssetControlHandler(asset, this); Data.DataContext = asset; }
protected override Asset getOrCreateResourceRefObj(string name) { var lname = name.ToLower(); Asset res = null; if (!assets.TryGetValue(lname, out res)) { assets[lname] = (res = new ModelAsset(this, lname)); } return(res); }
/// <summary> /// Initialise the browser. /// </summary> /// <param name="asset"></param> public GlareModelAssetBrowser(ModelAsset asset) { if (asset == null) { throw new ArgumentNullException("asset"); } ModelAsset = asset; ViewLookAtDistance = Model.Bounds.Radius * 3; WorldTranslation = -Model.Bounds.Position; }
public void Initialize(ModelAsset asset) { TextureName.Text = asset.AssetName; //DefaultVertexCount.Text = asset.DefaultVertexCount; //DefaultIndexCount.Text = asset.DefaultIndexCount; bool isPathValid = asset.EditorPath.IsPathValid(); FileName.Text = isPathValid ? Path.GetFileName(asset.EditorPath) : asset.EditorPath; if (isPathValid) { // TODO: Open in OBJ Viewer } }
void SetModel(ModelAsset asset) { var go = asset.Root; // cleanup var loaded = m_loaded; m_loaded = null; if (loaded != null) { Debug.LogFormat("destroy {0}", loaded); GameObject.Destroy(loaded.gameObject); } if (go != null) { var lookAt = go.GetComponent <VRMController>(); if (lookAt != null) { m_loaded = go.AddComponent <HumanPoseTransfer>(); m_loaded.Source = m_src; m_loaded.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; m_lipSync = go.AddComponent <AIUEO>(); m_blink = go.AddComponent <Blinker>(); lookAt.Gaze = m_target.transform; // lookAt.UpdateType = VRMController.UpdateTypes.LateUpdate; // after HumanPoseTransfer's setPose } var animation = go.GetComponent <Animation>(); if (animation && animation.clip != null) { animation.Play(animation.clip.name); } // show mesh foreach (var r in asset.Renderers) { r.enabled = true; } } }
public MenuWorld( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ISkin skin) { this.m_2DRenderUtilities = twodRenderUtilities; this.AssetManager = assetManagerProvider.GetAssetManager(); this.m_BackgroundCubeEntityFactory = backgroundCubeEntityFactory; this.m_TitleFont = this.AssetManager.Get<FontAsset>("font.Title"); this.m_PlayerModel = this.AssetManager.Get<ModelAsset>("model.Character"); this.m_PlayerModelTexture = this.AssetManager.Get<TextureAsset>("model.CharacterTex"); this.Entities = new List<IEntity>(); this.m_CanvasEntity = new CanvasEntity(skin) { Canvas = new Canvas() }; this.m_CanvasEntity.Canvas.SetChild(this.m_TitleMenu = new TitleMenu()); // Don't add the canvas to the entities list; that way we can explicitly // order it's depth. }
IEnumerator LoadModelAsync(string path) { Debug.LogFormat("{0}", path); var task = Task.Run(() => { if (!File.Exists(path)) { return(null); } var vrmModel = VrmLoader.CreateVrmModel(path); return(vrmModel); }); while (!task.IsCompleted) { // 終了待ち yield return(null); } var model = task.Result; if (model == null) { yield break; } m_texts.UpdateMeta(model); // UniVRM-0.XXのコンポーネントを構築する var assets = new ModelAsset(); // build async yield return(AsyncUnityBuilder.ToUnityAssetAsync(model, assets)); UniVRM10.ComponentBuilder.Build10(model, assets); SetModel(assets); }
private void LoadModel(string path) { try { // If BVH trigger is still on if (_bvhLoadingTrigger == true) { LoadMotion(_bvhPathSaved); } if (!File.Exists(path)) { return; } Debug.LogFormat("{0}", path); var vrmModel = VrmLoader.CreateVrmModel(path); // Call License Update function _licensePanel.LicenseUpdatefunc(vrmModel); // UniVRM-0.XXのコンポーネントを構築する var assets = new ModelAsset(); // build UnityBuilder.ToUnityAsset(vrmModel, assets); UniVRM10.ComponentBuilder.Build10(vrmModel, assets); // Set up Model SetModel(assets); } catch (Exception e) { _errorMessagePanel.SetMessage(MultipleLanguageSupport.VrmLoadErrorMessage + "\nError message: " + e.Message); throw; } }
public static IEnumerator ToUnityAssetAsync(VrmLib.Model model, ModelAsset asset) { // texture for (int i = 0; i < model.Textures.Count; ++i) { var src = model.Textures[i]; var name = !string.IsNullOrEmpty(src.Name) ? src.Name : string.Format("{0}_img{1}", model.Root.Name, i); if (src is VrmLib.ImageTexture imageTexture) { var texture = RuntimeUnityBuilder.CreateTexture(imageTexture); texture.name = name; asset.Map.Textures.Add(src, texture); asset.Textures.Add(texture); } else { Debug.LogWarning($"{name} not ImageTexture"); } // next frame yield return(null); } // material foreach (var src in model.Materials) { // TODO: material has VertexColor var material = RuntimeUnityMaterialBuilder.CreateMaterialAsset(src, hasVertexColor: false, asset.Map.Textures); material.name = src.Name; asset.Map.Materials.Add(src, material); asset.Materials.Add(material); // next frame yield return(null); } // mesh for (int i = 0; i < model.MeshGroups.Count; ++i) { var src = model.MeshGroups[i]; if (src.Meshes.Count == 1) { // submesh 方式 var mesh = new Mesh(); mesh.name = src.Name; mesh.LoadMesh(src.Meshes[0], src.Skin); asset.Map.Meshes.Add(src, mesh); asset.Meshes.Add(mesh); } else { // 頂点バッファの連結が必用 throw new NotImplementedException(); } // next frame yield return(null); } // node: recursive yield return(CreateNodesAsync(model.Root, null, asset.Map.Nodes)); asset.Root = asset.Map.Nodes[model.Root]; // next frame yield return(null); // renderer var map = asset.Map; foreach (var(node, go) in map.Nodes) { if (node.MeshGroup is null) { continue; } if (node.MeshGroup.Meshes.Count > 1) { throw new NotImplementedException("invalid isolated vertexbuffer"); } var renderer = RuntimeUnityBuilder.CreateRenderer(node, go, map); renderer.enabled = false; map.Renderers.Add(node, renderer); asset.Renderers.Add(renderer); // next frame yield return(null); } // humanoid var boneMap = map.Nodes .Where(x => x.Key.HumanoidBone.GetValueOrDefault() != VrmLib.HumanoidBones.unknown) .Select(x => (x.Value.transform, x.Key.HumanoidBone.Value)).AsEnumerable(); // next frame yield return(null); asset.HumanoidAvatar = HumanoidLoader.LoadHumanoidAvatar(asset.Root.transform, boneMap); asset.HumanoidAvatar.name = "VRM"; // next frame yield return(null); var animator = asset.Root.AddComponent <Animator>(); animator.avatar = asset.HumanoidAvatar; }
private List <Asset> LoadDirectory(string path) { List <Asset> loadedAssets = new List <Asset>(); string[] files = Directory.GetFiles(path); for (int i = 0; i < files.Length; i++) { string extension = Path.GetExtension(files[i]); if (Path.GetFileName(files[i]) == "addon.info" || extension == ".meta") { continue; } Asset asset; switch (extension) { case ".fbx": asset = new ModelAsset() { files = new string[] { files[i] }, source = this }; if (asset.Load()) { loadedAssets.Add(asset); } else { Debug.LogWarning($"Failed to load ModelAsset (does it need to be done in main thread?), Path: {files[i]}"); } break; case ".png": case ".jpg": case ".jpeg": asset = new ImageAsset { files = new string[] { files[i] }, source = this }; if (asset.Load()) { loadedAssets.Add(asset); } else { Debug.LogWarning($"Failed to load ImageAsset (does it need to be done in main thread?), Path: {files[i]}"); } break; case ".mp3": case ".ogg": case ".wav": asset = new SoundAsset { files = new string[] { files[i] }, source = this }; if (asset.Load()) { loadedAssets.Add(asset); } else { Debug.LogWarning($"Failed to load SoundAsset, Path: {files[i]}"); } break; case ".txt": case ".cs": case ".scss": case ".html": asset = new TextAsset { files = new string[] { files[i] }, source = this }; if (asset.Load()) { loadedAssets.Add(asset); } else { Debug.LogWarning($"Failed to load TextAsset, Path: {files[i]}"); } break; default: Debug.LogWarning($"Got unknown extension: {extension}"); break; } } string[] directories = Directory.GetDirectories(path); for (int i = 0; i < directories.Length; i++) { loadedAssets.AddRange(LoadDirectory(directories[i])); } return(loadedAssets); }
/// <summary> /// The handle. /// </summary> /// <param name="assetManager"> /// The asset manager. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="data"> /// The data. /// </param> /// <returns> /// The <see cref="IAsset"/>. /// </returns> public IAsset Handle(IAssetManager assetManager, string name, IRawAsset data) { if (data is CompiledAsset) { return new ModelAsset(name, null, null, data.GetProperty<PlatformData>("PlatformData"), false, string.Empty); } PlatformData platformData = null; if (data.GetProperty<PlatformData>("PlatformData") != null) { platformData = new PlatformData { Platform = data.GetProperty<PlatformData>("PlatformData").Platform, Data = data.GetProperty<PlatformData>("PlatformData").Data }; } var model = new ModelAsset( name, ByteReader.ReadAsByteArray(data.GetProperty<object>("RawData")), data.GetProperty<System.Collections.Generic.Dictionary<string, byte[]>>("RawAdditionalAnimations"), platformData, data.GetProperty<bool>("SourcedFromRaw"), data.GetProperty<string>("Extension")); return model; }
/// <summary> /// Initializes a new instance of the <see cref="AnimationController"/> class. /// </summary> /// <param name="model"> /// The model whose animations will be played. /// </param> /// <param name="script"> /// The script instance. /// </param> public AnimationController(ModelAsset model, ScriptAsset script) { this.m_Model = model; this.m_ScriptInstance = script.CreateInstance(); }
static void ImportFile(string path, string relativePath, string output) { string[] arr = relativePath.Split('.'); string name = Path.GetFileNameWithoutExtension(relativePath); switch (arr[arr.Length - 1]) { case "jpg": case "jpeg": case "dds": case "tiff": case "tif": case "psd": case "tga": case "bmp": case "gif": case "png": break; if ((name.ToLower().EndsWith("bump") && !name.ToLower().StartsWith("bump")) || (name.ToLower().EndsWith("normal") && !name.ToLower().StartsWith("normal"))) { TextureAsset tex = NormalMapTextureFactory.Create(); tex.Source = new UFile(relativePath); if (!overwrite && File.Exists($"{output}/{name}{TextureAsset.FileExtension}")) { Console.WriteLine($"{output}/{name}{TextureAsset.FileExtension} exists - not writing."); break; } else { AssetFileSerializer.Save($"{output}/{name}{TextureAsset.FileExtension}", tex, null); } } else { TextureAsset tex = ColorTextureFactory.Create(); tex.Source = new UFile(relativePath); if (!overwrite && File.Exists($"{output}/{name}{TextureAsset.FileExtension}")) { Console.WriteLine($"{output}/{name}{TextureAsset.FileExtension} exists - not writing."); break; } AssetFileSerializer.Save($"{output}/{name}{TextureAsset.FileExtension}", tex, null); MaterialAsset mat = DiffuseMaterialFactory.Create(); ((ComputeTextureColor)((MaterialDiffuseMapFeature)mat.Attributes.Diffuse).DiffuseMap).Texture = GetTexture(tex); AssetFileSerializer.Save($"{output}/{name}{MaterialAsset.FileExtension}", mat, null); } break; case "dae": case "3ds": case "obj": case "blend": case "x": case "md2": case "md3": case "dxf": case "fbx": if (!overwrite && File.Exists($"{output}/{name}{ModelAsset.FileExtension.Split(';')[0]}")) { Console.WriteLine($"{output}/{name}{ModelAsset.FileExtension.Split(';')[0]} exists - not writing."); break; } ModelAsset model = DefaultAssetFactory <ModelAsset> .Create(); model.Source = new UFile(relativePath); Scene scene = ctx.ImportFile(path, PostProcessSteps.None); Dictionary <string, Stride.Rendering.Material> materials = new Dictionary <string, Stride.Rendering.Material>(); for (int i = 0; i < scene.MaterialCount; i++) { if (materials.ContainsKey(scene.Materials[i].Name)) { model.Materials.Add(new ModelMaterial() { Name = scene.Materials[i].Name, MaterialInstance = new MaterialInstance(materials[scene.Materials[i].Name]) }); continue; } if (!overwrite && File.Exists($"{output}/{scene.Materials[i].Name}{MaterialAsset.FileExtension}")) { Console.WriteLine($"{output}/{scene.Materials[i].Name}{MaterialAsset.FileExtension} exists - not writing parent mesh."); break; } MaterialAsset materialAsset = DiffuseMaterialFactory.Create(); // set diffuse (if possible) if (scene.Materials[i].HasTextureDiffuse) { string diffPath = Path.GetRelativePath(output, Path.Combine(Path.GetDirectoryName(path), scene.Materials[i].TextureDiffuse.FilePath)); TextureAsset asset = ImportTexture(diffPath, TextureType.Diffuse); if (!overwrite && File.Exists($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}")) { Console.WriteLine($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension} exists - not writing parent mesh."); break; } AssetFileSerializer.Save($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}", asset, null); Texture tex = GetTexture(asset); SetTexture(materialAsset, tex, TextureType.Diffuse); } // normals if (scene.Materials[i].HasTextureNormal) { string normPath = Path.GetRelativePath(output, Path.Combine(Path.GetDirectoryName(path), scene.Materials[i].TextureNormal.FilePath)); TextureAsset asset = ImportTexture(normPath, TextureType.Normals); if (!overwrite && File.Exists($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}")) { Console.WriteLine($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension} exists - not writing parent mesh."); break; } AssetFileSerializer.Save($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}", asset, null); Texture tex = GetTexture(asset); SetTexture(materialAsset, tex, TextureType.Normals); } AssetFileSerializer.Save($"{output}/{scene.Materials[i].Name}{MaterialAsset.FileExtension}", materialAsset, null); Stride.Rendering.Material material = GetMaterial(materialAsset, scene.Materials[i].Name); model.Materials.Add(new ModelMaterial() { Name = scene.Materials[i].Name, MaterialInstance = new MaterialInstance(material) }); materials.Add(scene.Materials[i].Name, material); } AssetFileSerializer.Save($"{output}/{name}{ModelAsset.FileExtension.Split(';')[0]}", model, null); break; default: Console.WriteLine($"The file extension \".{arr[arr.Length - 1]}\" is not supported. ({path})"); break; } }
private void SetModel(ModelAsset assets) { var vrmModel = _vrmModel; vrmModel = assets.Root; // Cleanup var loaded = _loadedBvhSourceOnAvatar; _loadedBvhSourceOnAvatar = null; if (loaded != null) { Debug.LogFormat("destroy {0}", loaded); Destroy(loaded.gameObject); } if (vrmModel != null) { // Set up expressions _facialExpressionPanel.CreateDynamicObject(vrmModel); _informationUpdate.SetVRM(vrmModel); SkinnedMeshRenderer[] skinnedMeshes = vrmModel.GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (var skinMesh in skinnedMeshes) { skinMesh.updateWhenOffscreen = true; } // Set up LookAt var lookAt = vrmModel.GetComponent <VRMBlendShapeProxy>(); if (lookAt != null) { _loadedBvhSourceOnAvatar = vrmModel.AddComponent <HumanPoseTransfer>(); _loadedBvhSourceOnAvatar.Source = _bvhSource; _motionControlPanel.LoadedBvhSourceOnAvatar = _loadedBvhSourceOnAvatar; if (_toggleMotionBVH.isOn) { _loadedBvhSourceOnAvatar.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseTransfer; } if (_toggleMotionTPose.isOn) { _loadedBvhSourceOnAvatar.SourceType = HumanPoseTransfer.HumanPoseTransferSourceType.HumanPoseClip; } if (_faceViewToggle.isOn) { _closeGameObject.FaceCameraPropertyActivateVRM(); } _motionControlPanel.AssignAutoPlay(vrmModel); if (_lookAtSphere.isOn) { lookAt.Gaze = _targetSphere.transform; } else if (_lookAtCamera.isOn) { lookAt.Gaze = _targetCamera.transform; } else { lookAt.Gaze = _referenceObject.transform; } // Check the model's LookAt type var animator = vrmModel.GetComponent <Animator>(); var leftEye = OffsetOnTransform.Create(animator.GetBoneTransform(HumanBodyBones.LeftEye)).Transform; var rightEye = OffsetOnTransform.Create(animator.GetBoneTransform(HumanBodyBones.RightEye)).Transform; if (leftEye == null && rightEye == null) { _lookAtBlendShapeFlag = true; lookAt.LookAtType = VRMBlendShapeProxy.LookAtTypes.BlendShape; } // Send information _informationUpdate.SetVRM(vrmModel); _informationUpdate.SetLookAtType(_lookAtBlendShapeFlag); } // Set up animation var animation = vrmModel.GetComponent <Animation>(); if (animation && animation.clip != null) { animation.Play(animation.clip.name); } // Show mesh foreach (var r in assets.Renderers) { r.enabled = true; } // VRMFirstPerson initialization var m_firstPerson = vrmModel.GetComponent <VRMFirstPerson>(); if (m_firstPerson != null) { m_firstPerson.Setup(); } if (_freeViewpointToggle.isOn) { _closeGameObject.EnableFirstPersonModeOption(); } } }
private async void OnKeyDown(object?sender, KeyEventArgs e) { Entity?cameraEntity = SceneSystem.CurrentCamera?.Entity; Entity scene = await Content.GetAsync <Entity>("Assets\\Scenes\\Scene1"); switch (e.Key) { case VirtualKey.Number0 when GraphicsDevice?.Presenter != null: GraphicsDevice.Presenter.PresentationParameters.SyncInterval = 0; break; case VirtualKey.Number1 when GraphicsDevice?.Presenter != null: GraphicsDevice.Presenter.PresentationParameters.SyncInterval = 1; break; case VirtualKey.D: Entity?customCliffhouse = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "CustomCliffhouse"); if (customCliffhouse != null) { if (customCliffhouse.Get <ModelComponent>()?.Model?.Materials[2].Descriptor?.Attributes.Diffuse is MaterialDiffuseMapFeature diffuseMapFeature) { if (diffuseMapFeature.DiffuseMap is DissolveShader dissolveShader && dissolveShader.DissolveStrength is ScalarShader strength) { strength.Value = 0.8f; } } } break; case VirtualKey.T: Entity?cliffhouse1 = Entity?.EntityManager?.FirstOrDefault(m => m.Name == ""); cliffhouse1?.Remove <ModelComponent>(); break; case VirtualKey.A: Entity newCliffhouse = new Entity("Cliffhouse") { new TransformComponent { Position = new Vector3(-200.0f, 120.0f, 500.0f) }, new ModelComponent(await Services.GetRequiredService <IContentManager>().LoadAsync <Model>("Assets\\Models\\Cliffhouse_Model")) }; SceneSystem.RootEntity?.Children.Add(newCliffhouse); break; case VirtualKey.P: Entity?child1 = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "Child1"); if (child1 != null && child1.Parent != null) { child1.Transform.Parent = null; SceneSystem.RootEntity?.Children.Add(child1); } break; case VirtualKey.Q: Entity?child2 = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "Child1"); if (child2 != null && child2.Parent != null) { child2.Parent = null; child2.Transform.Parent = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "Parent1").Transform; } break; case VirtualKey.S: Entity?previousRootScene = SceneSystem.RootEntity; if (previousRootScene != null && cameraEntity != null) { cameraEntity.Parent = null; SceneSystem.RootEntity = new Entity { new TransformComponent { Position = new Vector3(500.0f, 0.0f, 0.0f) } }; SceneSystem.RootEntity.Children.Add(cameraEntity); SceneSystem.RootEntity.Children.Add(previousRootScene); } break; case VirtualKey.O: Entity?entity = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "Cliffhouse"); if (entity != null) { await Content.SaveAsync(@"Assets\Cliffhouse", entity); } break; case VirtualKey.I: if (scene != null) { await Content.SaveAsync(@"Assets\CustomScene", scene); } break; case VirtualKey.U: Model?model = await Content.GetAsync <Model?>(@"Assets\Models\SwimmingShark_Model"); if (model != null) { await Content.SaveAsync(@"Assets\CustomSwimmingSharkModel", model); } break; case VirtualKey.X: Model?sharkModel = await Content.GetAsync <Model?>(@"Assets\Models\SwimmingShark_Model"); if (sharkModel != null) { ModelAsset modelAsset = new ModelAsset { Source = @"Assets\Resources\Models\SwimmingShark.glb" }; foreach (Material material in sharkModel.Materials) { modelAsset.Materials.Add(material); } await Content.SaveAsync(@"Assets\CustomSwimmingSharkModelAsset", modelAsset); } break; case VirtualKey.G: GC.Collect(); break; case VirtualKey.C: Entity?tRex = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "T-Rex"); var rigidBody = new RigidBodyComponent { ColliderShape = new SphereColliderShape(50.0f), Mass = 100.0f }; tRex?.Add(rigidBody); Entity?child = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "Child2"); var rigidBody2 = new RigidBodyComponent { ColliderShape = new SphereColliderShape(100.0f), Mass = 50.0f }; child?.Add(rigidBody2); Entity?childBelow = Entity?.EntityManager?.FirstOrDefault(m => m.Name == "Child1"); var staticCollider = new StaticColliderComponent { ColliderShape = new SphereColliderShape(80.0f) }; childBelow?.Add(staticCollider); break; case VirtualKey.R: PhysicsSimulation?simulation = this.GetSimulation(); Matrix4x4 cameraMatrix = cameraEntity !.Transform.WorldMatrix; Vector3 forwardVector = new Vector3(-cameraMatrix.M31, -cameraMatrix.M32, -cameraMatrix.M33); if (simulation != null && simulation.RayCast(cameraMatrix.Translation, forwardVector, float.MaxValue, out RayHit hit)) { hit.Collider.Entity?.Parent?.Children.Remove(hit.Collider.Entity !); } break; } }