public CModelEditor(string AssetName) { _viewDirection = EViewDirection.VD_FRONT; mAssetName = AssetName; _asset = CGame.AssetManager.GetAsset <CModelAsset>(AssetName); _vectorModel = _asset.mVectorModel; }
private void ProcessLoadRequest(SAssetLoadRequest loadRequest) { Scene scene = m_importer.ImportFile(loadRequest.filename, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessPreset.ConvertToLeftHanded); if (loadRequest.type == EAssetType.Mesh) { if (scene.HasMeshes) { CMeshAsset meshAsset = (CMeshAsset)loadRequest.targetAsset; CMeshLoadingJob loadingJob = new CMeshLoadingJob(scene, Path.GetDirectoryName(loadRequest.filename)); LoadMeshInternal(0, meshAsset, loadingJob, loadRequest.assetPath, Path.GetFileNameWithoutExtension(loadRequest.filename)); } } else if (loadRequest.type == EAssetType.Model) { if (scene.HasMeshes) { CModelAsset modelAsset = (CModelAsset)loadRequest.targetAsset; LoadModelInternal(loadRequest.filename, scene, modelAsset, loadRequest.assetPath); modelAsset.Name = Path.GetFileNameWithoutExtension(loadRequest.filename); if (CAssetRegistry.Instance.RequestRegisterAsset(modelAsset, loadRequest.assetPath + "Models/", out CModelAsset existingAsset)) { existingAsset.WaitUntilLoaded(); modelAsset.CopyFrom(existingAsset); } } } AssetLoadedCallback(loadRequest); }
public void LoadAsset() { CAsset asset = null; if (mType == EAssetType.AT_BRUSH) { asset = new CBrushAsset(); } else if (mType == EAssetType.AT_MODEL) { asset = new CModelAsset(); } else if (mType == EAssetType.AT_LEVEL) { asset = new CLevelAsset(); } else if (mType == EAssetType.AT_ITEM) { asset = new CItemAsset(); } if (asset != null) { asset.mName = mName; asset.mFileName = mFileName; asset.mType = mType; asset.Load(); mAsset = asset; } else { Debug.LogError("Could not load asset: " + mName); } }
private void AddMeshes(Node node, CModelAsset asset, string assetPath, CMeshLoadingJob loadingJob, ref Matrix transform) { Matrix previousTransform = transform; transform = Matrix.Multiply(previousTransform, FromAssimpMatrix(node.Transform)); if (node.HasMeshes) { foreach (int meshIndex in node.MeshIndices) { CMeshAsset meshAsset = new CMeshAsset(); // We always import all meshes in a file so we use always import here LoadMeshInternal(meshIndex, meshAsset, loadingJob, assetPath, null, true); meshAsset.LoadFinished(); SMeshChild modelChild = new SMeshChild() { meshAsset = meshAsset, relativeTransform = transform }; asset.MeshChildren.Add(modelChild); } } for (int i = 0; i < node.ChildCount; i++) { AddMeshes(node.Children[i], asset, assetPath, loadingJob, ref transform); } transform = previousTransform; }
private string _GetPrimaryModelName(CModelAsset Model) { if (Model != null) { return(Model.mName); } return("(None)"); }
private void _CreatePaperModel(GameObject Parent, Vector3 Position, Vector3 Rotation) { CModelAsset paperModel = CGame.AssetManager.GetAsset <CModelAsset>("default_contract_paper"); GameObject paper = paperModel.mVectorModel.CreateGameObject(); paper.transform.SetParent(Parent.transform); paper.transform.localPosition = Position; paper.transform.localRotation = Quaternion.Euler(Rotation); }
private void LoadModelInternal(string filename, Scene scene, CModelAsset asset, string assetPath) { string modelPath = Path.GetDirectoryName(filename); Matrix identity = Matrix.Identity; CMeshLoadingJob loadingJob = new CMeshLoadingJob(scene, modelPath); loadingJob.LoadedTextures = new Dictionary <string, CTextureAsset>(); loadingJob.LoadedMaterials = new Dictionary <string, CMaterialAsset>(); AddMeshes(scene.RootNode, asset, assetPath, loadingJob, ref identity); }
private void RecreateRenderData(float deltaTime) { if (Model == null) { CRenderScene scene = CRenderer.Instance.ActiveScene; for (int i = 0; i < m_renderNodes.Length; i++) { scene.UnregisterRenderNode(m_renderNodes[i]); } return; } CModelAsset modelAsset = Model.GetAsset(); if (modelAsset != null && modelAsset.IsLoaded) { CRenderScene scene = CRenderer.Instance.ActiveScene; for (int i = 0; i < m_renderNodes.Length; i++) { scene.UnregisterRenderNode(m_renderNodes[i]); } int meshCount = modelAsset.MeshChildren.Count; m_renderNodes = new CMeshRenderNode[meshCount]; m_overrideMaterials.SetMinSize(meshCount); m_materialAssets.SetMinSize(meshCount); for (int i = 0; i < meshCount; i++) { Transform childTransform = new Transform(); childTransform.SetFromMatrix(modelAsset.MeshChildren[i].relativeTransform); childTransform.Parent = m_transform; CMeshRenderNode newRenderNode; if (m_overrideMaterials[i] != null) { newRenderNode = new CMeshRenderNode(this, modelAsset.MeshChildren[i].meshAsset, null, childTransform); newRenderNode.SetMaterialOverride(m_overrideMaterials[i]); } else { newRenderNode = new CMeshRenderNode(this, modelAsset.MeshChildren[i].meshAsset, m_materialAssets[i], childTransform); } m_renderNodes[i] = newRenderNode; scene.RegisterRenderNode(newRenderNode); } m_updateRenderDataScope?.Disconnect(); m_updateRenderDataScope = null; } }
private void _OnClickCreateNewAssetWindow(GameObject Window, EAssetType Type, string AssetName) { string errorStr; if (CGame.AssetManager.IsAssetNameValid(AssetName, out errorStr)) { GameObject.Destroy(Window); CTUITreeViewItem treeItem = null; CAsset asset = null; if (Type == EAssetType.AT_MODEL) { treeItem = _tviModels; asset = new CModelAsset(); } else if (Type == EAssetType.AT_BRUSH) { treeItem = _tviBrushes; asset = new CBrushAsset(); } else if (Type == EAssetType.AT_LEVEL) { treeItem = _tviLevels; asset = new CLevelAsset(); } else if (Type == EAssetType.AT_ITEM) { treeItem = _tviItems; asset = new CItemAsset(); } asset.mName = AssetName; asset.mFileName = CGame.DataDirectory + asset.mName + "." + CAssetManager.ASSET_FILE_EXTENSION; Debug.Log("New Asset Path: " + asset.mFileName); asset.Save(); CAssetDeclaration decl = CGame.AssetManager.CreateAssetDeclaration(asset); treeItem.AddItem(decl.mName, () => OnClickAsset(decl.mName), () => mToolkit.EditAsset(decl.mName)); treeItem.RebuildEntireTree(); mToolkit.EditAsset(AssetName); } else { Debug.Log("Asset creation failed: " + errorStr); } }
public CModelAsset LoadModelAsync(string filename, bool bAlwaysImport = false) { CModelAsset outAsset = new CModelAsset(); if (!bAlwaysImport && TryGetExistingAsset(filename, "Assets/Models/", outAsset, out CModelAsset existingAsset)) { return(existingAsset); } SAssetLoadRequest loadRequest = new SAssetLoadRequest() { filename = filename, targetAsset = outAsset, assetPath = "Assets/", type = EAssetType.Model }; m_loadRequests.Enqueue(loadRequest); StartNextLoadRequest(); return(outAsset); }
public bool Import(string filename, string importPath, bool bAlwaysImport = false) { // Block new loads and wait for our current load to finish m_bIsLoading = true; m_currentLoadTask?.Wait(); // Load the asset synchronous Scene scene = m_importer.ImportFile(filename, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessPreset.ConvertToLeftHanded); if (scene.HasMeshes) { if (scene.MeshCount > 1) { CModelAsset outModel = new CModelAsset(); LoadModelInternal(filename, scene, outModel, importPath); outModel.LoadFinished(); outModel.Name = Path.GetFileNameWithoutExtension(filename); if (CAssetRegistry.Instance.RequestRegisterAsset(outModel, importPath + "Models/", out CModelAsset existingModel, bAlwaysImport)) { existingModel.WaitUntilLoaded(); } } else { string basePath = Path.GetDirectoryName(filename); CMeshLoadingJob loadingJob = new CMeshLoadingJob(scene, basePath); CMeshAsset outMesh = new CMeshAsset(); LoadMeshInternal(0, outMesh, loadingJob, importPath, Path.GetFileNameWithoutExtension(filename), bAlwaysImport); outMesh.LoadFinished(); } } // Unblock loader m_bIsLoading = false; // Continue loading request StartNextLoadRequest(); return(true); }
public CModelAsset LoadModelAsset(string filename, bool bAlwaysImport = false) { // Block new loads and wait for our current load to finish m_bIsLoading = true; m_currentLoadTask?.Wait(); // Load the asset synchronous CModelAsset outAsset = new CModelAsset(); if (!bAlwaysImport && TryGetExistingAsset(filename, "Assets/Models", outAsset, out CModelAsset existingAsset)) { m_bIsLoading = false; return(existingAsset); } Scene scene = m_importer.ImportFile(filename, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessPreset.ConvertToLeftHanded); if (scene.HasMeshes) { LoadModelInternal(filename, scene, outAsset, "Assets/"); } outAsset.Name = Path.GetFileNameWithoutExtension(filename); if (CAssetRegistry.Instance.RequestRegisterAsset(outAsset, "Assets/Models/", out CModelAsset existingModel, bAlwaysImport)) { existingModel.WaitUntilLoaded(); outAsset.CopyFrom(existingModel); } outAsset.LoadFinished(); // Unblock loader m_bIsLoading = false; // Continue loading request StartNextLoadRequest(); return(outAsset); }
/// <summary> /// Display the in & out contract stack queues. /// </summary> public void RefreshContractVisuals() { // TODO: Cleanup punchout mesh? if (_paperInGob != null) { GameObject.Destroy(_paperInGob); _paperInGob = null; } CModelAsset paperModel = CGame.AssetManager.GetAsset <CModelAsset>("default_contract_paper"); if (mPaperStackCount > 0) { GameObject.Destroy(_paperInGob); _paperInGob = new GameObject(); _paperInGob.transform.parent = _Gob.transform; _paperInGob.transform.localPosition = mAsset.mPaperInPosition; for (int i = 0; i < mPaperStackCount; ++i) { GameObject paperGob = paperModel.mVectorModel.CreateGameObject(EViewDirection.VD_FRONT); paperGob.transform.SetParent(_paperInGob.transform); paperGob.transform.localPosition = new Vector3(0, i * 0.15f, 0); paperGob.GetComponent <MeshRenderer>().material.SetColor("_FloorColor", CGame.GameUIStyle.ThemeColorA); } } if (mPaperStackOutCount > 0) { GameObject.Destroy(_paperOutGob); _paperOutGob = new GameObject(); _paperOutGob.transform.parent = _Gob.transform; _paperOutGob.transform.localPosition = mAsset.mPaperOutPosition; for (int i = 0; i < mPaperStackOutCount; ++i) { GameObject paperGob = paperModel.mVectorModel.CreateGameObject(EViewDirection.VD_FRONT); paperGob.transform.SetParent(_paperOutGob.transform); paperGob.transform.localPosition = new Vector3(0, i * 0.15f, 0); paperGob.GetComponent <MeshRenderer>().material.SetColor("_FloorColor", CGame.GameUIStyle.ThemeColorA); } } /* * if (mOutPapers > 0) * { * GameObject.Destroy(_gobOut); * _gobOut = new GameObject(); * _gobOut.transform.parent = _Gob.transform; * _gobOut.transform.localPosition = mDefinition.mPapersOutPos; * _gobOut.transform.localRotation = Quaternion.identity; * _CreateContractPapers(_gobOut.transform, mOutPapers); * } * else * { * if (_gobOut != null) * { * GameObject.Destroy(_gobOut); * _gobOut = null; * } * } */ }
public void GenerateLevel() { int width = _map.mWidth; int height = _map.mWidth; CTile[,] tiles = _map.mTiles; Destroy(); Transform oldParent = null; if (_gob != null) { oldParent = _gob.transform.parent; GameObject.Destroy(_gob); } _gob = new GameObject("level mesh"); if (oldParent != null) { _gob.transform.SetParent(oldParent); } CModelAsset doorFrame = CGame.AssetManager.GetAsset <CModelAsset>("default_door_frame"); for (int iX = 0; iX < width; ++iX) { for (int iY = 0; iY < height; ++iY) { CTile tile = tiles[iX, iY]; if (tile.mWallX.mType >= 100) { GameObject door = doorFrame.mVectorModel.CreateGameObject(EViewDirection.VD_FRONT); door.transform.position = new Vector3(iX + 0.5f, 0.0f, iY); door.transform.rotation = CUtility.FacingTable[2]; door.transform.parent = _gob.transform; } else if (tile.mWallX.mType >= 10) { } if (tile.mWallZ.mType >= 100) { GameObject door = doorFrame.mVectorModel.CreateGameObject(EViewDirection.VD_FRONT); door.transform.position = new Vector3(iX, 0.0f, iY + 0.5f); door.transform.rotation = CUtility.FacingTable[1]; door.transform.parent = _gob.transform; } else if (tile.mWallZ.mType >= 10) { } } } // Floor Mesh _gobFloor = new GameObject("floorTiles"); _gobFloor.transform.parent = _gob.transform; _meshFloor = _gobFloor.AddComponent <MeshFilter>().mesh = new Mesh(); if (mFloorAlwaysVisible) { _gobFloor.AddComponent <MeshRenderer>().material = CGame.WorldResources.FloorVisibleMat; } else { _gobFloor.AddComponent <MeshRenderer>().material = CGame.WorldResources.FloorMat; } // Count Flat Tiles int tileCount = width * height; int[] tris = new int[tileCount * 6]; Vector3[] verts = new Vector3[tileCount * 4]; Vector2[] uvs = new Vector2[tileCount * 4]; Vector4[] tanList = new Vector4[tileCount * 4]; Color32[] cols = new Color32[tileCount * 4]; int t = 0; int v = 0; for (int iX = 0; iX < width; ++iX) { for (int iY = 0; iY < height; ++iY) { verts[v + 0] = new Vector3(iX + 0.0f, 0.0f, iY + 0.0f); verts[v + 1] = new Vector3(iX + 0.0f, 0.0f, iY + 1.0f); verts[v + 2] = new Vector3(iX + 1.0f, 0.0f, iY + 1.0f); verts[v + 3] = new Vector3(iX + 1.0f, 0.0f, iY + 0.0f); float texScale = 0.5f; uvs[v + 0] = new Vector2(iX * texScale, iY * texScale); uvs[v + 1] = new Vector2(iX * texScale, (iY + 1) * texScale); uvs[v + 2] = new Vector2((iX + 1) * texScale, (iY + 1) * texScale); uvs[v + 3] = new Vector2((iX + 1) * texScale, iY * texScale); cols[v + 0] = tiles[iX, iY].mTint; cols[v + 1] = tiles[iX, iY].mTint; cols[v + 2] = tiles[iX, iY].mTint; cols[v + 3] = tiles[iX, iY].mTint; tanList[v + 0] = new Vector4(1.0f, 0.0f, 0.0f, -1.0f); tanList[v + 1] = new Vector4(1.0f, 0.0f, 0.0f, -1.0f); tanList[v + 2] = new Vector4(1.0f, 0.0f, 0.0f, -1.0f); tanList[v + 3] = new Vector4(1.0f, 0.0f, 0.0f, -1.0f); tris[t + 0] = v + 0; tris[t + 1] = v + 1; tris[t + 2] = v + 2; tris[t + 3] = v + 0; tris[t + 4] = v + 2; tris[t + 5] = v + 3; v += 4; t += 6; } } _meshFloor.vertices = verts; _meshFloor.uv = uvs; _meshFloor.triangles = tris; _meshFloor.tangents = tanList; _meshFloor.colors32 = cols; _meshFloor.RecalculateNormals(); _CreateWallMesh(); }
private void _ChangeModel(ref CModelAsset Model, string Name) { Model = CGame.AssetManager.GetAsset <CModelAsset>(Name); _ModifyAsset(); }
public override void Deserialize(BinaryReader R) { base.Deserialize(R); int version = R.ReadInt32(); mVersion = version; if (version == 11) { mItemType = (EItemType)R.ReadInt32(); mFriendlyName = R.ReadString(); mFlavourText = R.ReadString(); mWidth = R.ReadInt32(); mLength = R.ReadInt32(); mTiles = new STile[mWidth * 2, mLength * 2]; for (int iX = 0; iX < mWidth * 2; ++iX) { for (int iY = 0; iY < mLength * 2; ++iY) { mTiles[iX, iY].mSolid = R.ReadBoolean(); } } mDurability = R.ReadInt32(); mCost = R.ReadInt32(); mValue = R.ReadSingle(); mStress = R.ReadSingle(); mAreaOfEffect = R.ReadSingle(); mSheetsInMax = R.ReadInt32(); mSheetsOutMax = R.ReadInt32(); string modelName = R.ReadString(); if (modelName != "") { mPMAsset = CGame.AssetManager.GetAsset <CModelAsset>(modelName); } mPMPosition = CUtility.ReadVec3(R); mPMRotation = CUtility.ReadVec3(R); modelName = R.ReadString(); if (modelName != "") { mSMAsset = CGame.AssetManager.GetAsset <CModelAsset>(modelName); } mSMPosition = CUtility.ReadVec3(R); mSMRotation = CUtility.ReadVec3(R); int usageSlotCount = R.ReadInt32(); mUsageSlots.Clear(); for (int i = 0; i < usageSlotCount; ++i) { CUsageSlot s = new CUsageSlot(); s.mEntryPosition = CUtility.ReadVec3(R); s.mEntryRotation = CUtility.ReadVec3(R); s.mEntrySize = CUtility.ReadVec3(R); s.mUsePosition = CUtility.ReadVec3(R); s.mUseRotation = CUtility.ReadVec3(R); mUsageSlots.Add(s); } // Desk mPaperInPosition = CUtility.ReadVec3(R); mPaperInRotation = CUtility.ReadVec3(R); mPaperOutPosition = CUtility.ReadVec3(R); mPaperOutRotation = CUtility.ReadVec3(R); // Icon mIconCameraPostion = CUtility.ReadVec3(R); mIconViewDirection = (EViewDirection)R.ReadInt32(); } else { Debug.LogError("Can't load item asset '" + mName + "' with version " + version); } }
public void Init(CInitializer initializer) { UpdateScheduler = new CUpdateScheduler(); CreateLevel(); GameConsole.Init(); PhysicsWorld.Init(this); #region Sponza CModelAsset sponzaAsset = CImportManager.Instance.MeshImporter.LoadModelAsync("TestResources/SponzaAtrium/sponza.obj"); m_sponzaEntity = SpawnEntity <CEntity>(); CModelComponent modelComponent = m_sponzaEntity.AddComponent <CModelComponent>(true, true); m_sponzaEntity.SetWorldPosition(new Vector3(0, -5, -5)); m_sponzaEntity.SetWorldRotation(Quaternion.RotationAxis(Axis.Up, MathUtil.DegreesToRadians(90))); m_sponzaEntity.SetWorldScale(new Vector3(0.03f)); CStaticModelColliderComponent staticModelCollider = m_sponzaEntity.AddComponent <CStaticModelColliderComponent>(true, true); staticModelCollider.ModelAsset = sponzaAsset; modelComponent.Model = sponzaAsset; m_sponzaEntity.IsPhysicsStatic = true; m_sponzaEntity.IsPhysicsEnabled = true; #endregion CMeshAsset cubeAsset = CImportManager.Instance.MeshImporter.LoadMeshAsync("EngineResources/DefaultMeshes/DefaultCube.obj"); CEntity floorEntity = SpawnEntity <CEntity>(); floorEntity.AddComponent <CSceneComponent>(true, true); CMeshComponent floorMesh = floorEntity.AddComponent <CMeshComponent>(true, true); floorMesh.Mesh = cubeAsset; floorMesh.LocalScale = new Vector3(500, 1, 500); CBoxColliderComponent floorCollider = floorEntity.AddComponent <CBoxColliderComponent>(true, true); floorCollider.Height = 1; floorCollider.Width = 500; floorCollider.Length = 500; floorEntity.SetLocalPosition(new Vector3(0, -15, 0)); floorEntity.IsPhysicsStatic = true; floorEntity.IsPhysicsEnabled = true; floorEntity.PhysicalStatic.Material = new Material(1, 0.8f, 1f); #region LightSetup m_lightEntity = SpawnEntity <CEntity>(); m_lightEntity.AddComponent <CSceneComponent>(true, true); CDirectionalLightComponent directionalLight = m_lightEntity.AddComponent <CDirectionalLightComponent>(true, true); directionalLight.LocalRotation = MathUtilities.CreateLookAtQuaternion(Vector3.Normalize(new Vector3(0.2f, -0.5f, 0.2f)), Axis.Up); directionalLight.LightColor = Color4.White * 0.8f; CSpotLightComponent spotLight = m_lightEntity.AddComponent <CSpotLightComponent>(true, true); spotLight.ConstantAttenuation = 0.01f; spotLight.LinearAttenuation = 0.3f; spotLight.QuadraticAttenuation = 0.0f; spotLight.Enabled = true; spotLight.SpotAngle = MathUtil.DegreesToRadians(30.0f); spotLight.LightColor = new Color4(0.1f, 0.8f, 0.1f, 1.0f); spotLight.Range = 100.0f; Quaternion deltaRotation = Quaternion.RotationAxis(Axis.Right, MathUtil.DegreesToRadians(10)); spotLight.LocalRotation = deltaRotation; spotLight.LocalPosition = new Vector3(0, 1, -4); CPointLightComponent pointLight1 = m_lightEntity.AddComponent <CPointLightComponent>(true, true); pointLight1.ConstantAttenuation = 1; pointLight1.LinearAttenuation = 0.2f; pointLight1.Enabled = true; pointLight1.Range = 100.0f; pointLight1.LightColor = new Color4(0.8f, 0.1f, 0.1f, 1.0f); pointLight1.LocalPosition = new Vector3(0, 0, 3.0f); CPointLightComponent pointLight2 = m_lightEntity.AddComponent <CPointLightComponent>(true, true); pointLight2.ConstantAttenuation = 1; pointLight2.LinearAttenuation = 0.4f; pointLight2.Enabled = true; pointLight2.Range = 100.0f; pointLight2.LightColor = new Color4(0.1f, 0.1f, 0.8f, 1.0f); pointLight2.LocalPosition = new Vector3(0, -3, -8.0f); CAmbientLightComponent ambientLight = m_lightEntity.AddComponent <CAmbientLightComponent>(true, true); ambientLight.LightColor = Color4.White * 0.15f; #endregion }
public CCreateModelNodesCommand(object outer, CModelAsset modelAsset, Transform modelTransform) { m_outer = outer; m_sourceAsset = modelAsset; m_modelTransform = modelTransform; }