/// <summary> /// Create an LBD tilemap GameObject from an LSD level tileset. /// </summary> /// <param name="lbd">The loaded LBD file.</param> /// <returns>A GameObject containing loaded meshes for all tiles in their layout.</returns> public GameObject CreateLBDTileMap(LBD lbd, Dictionary <TMDObject, Mesh> cache) { GameObject lbdTilemap = new GameObject("LBD TileMap"); List <CombineInstance> meshesCreated = new List <CombineInstance>(); // we're combining meshes into a collision mesh // for each tile in the tilemap int tileNo = 0; foreach (LBDTile tile in lbd.TileLayout) { int x = tileNo / lbd.Header.TileWidth; int y = tileNo % lbd.Header.TileWidth; // create an LBD tile if we should draw it if (tile.DrawTile) { GameObject lbdTile = createLBDTile(tile, lbd.ExtraTiles, x, y, lbd.Tiles, meshesCreated, cache); lbdTile.transform.SetParent(lbdTilemap.transform); } tileNo++; } // combine all tiles into mesh for efficient collision Mesh combined = new Mesh(); combined.CombineMeshes(meshesCreated.ToArray(), true); MeshCollider mc = lbdTilemap.AddComponent <MeshCollider>(); mc.sharedMesh = combined; lbdTilemap.tag = "Linkable"; return(lbdTilemap); }
public LBDDocument CreateDocument(LBD lbd) { TMDDocument tileTmd = _tmdController.CreateDocument(lbd.Tiles); List <IRenderable> tileLayout = new List <IRenderable>(); int tileNo = 0; foreach (LBDTile tile in lbd.TileLayout) { int x = tileNo / lbd.Header.TileWidth; int y = tileNo % lbd.Header.TileWidth; if (tile.DrawTile) { tileLayout.AddRange(LibLSDUtil.CreateLBDTileMesh(tile, lbd.ExtraTiles, x, y, lbd.Tiles, _shader, _vramController.VRAMTexture)); } tileNo++; } List <MOMDocument> entities = null; if (lbd.Header.HasMML) { entities = new List <MOMDocument>(); foreach (MOM mom in lbd.MML?.MOMs) { entities.Add(_momController.CreateDocument(mom)); } } return(new LBDDocument(lbd, tileTmd, tileLayout, entities)); }
/// <summary> /// Load an LBD file from disk. /// </summary> /// <param name="path">The path to the LBD file.</param> /// <param name="span">The span ID for how long this resource should be cached.</param> public void Load(string path, int span) { LBD lbd; using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open))) { lbd = new LBD(br); } Resource <LBD> resource = new Resource <LBD>(lbd, span); ResourceManager.RegisterResource(path, resource); }
public static LBD LoadLBD(string filePath) { Log.Information($"Loading LBD from: {filePath}"); LBD lbd; using (BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open))) { lbd = new LBD(br); } Log.Information("Successfully loaded LBD"); return(lbd); }
public static GameObject Create(LBD lbd, int momIndex, Material material, string objName, int idleAnimation = 0, bool playIdleAnimation = false, string scriptPath = null) { if (!lbd.MML.HasValue) { throw new ArgumentException("Provided LBD did not have entities!", nameof(lbd)); } if (momIndex >= lbd.MML.Value.MOMs.Length) { throw new ArgumentException( $"LBD only has {lbd.MML.Value.NumberOfMOMs} entities, can't load entity '{momIndex}'"); } if (idleAnimation >= lbd.MML.Value.MOMs[momIndex].MOS.TODs.Length) { Debug.LogWarning( $"Entity only has {lbd.MML.Value.MOMs[momIndex].MOS.TODs.Length} animations, " + $"can't set idle animation to animation '{idleAnimation}'. Defaulting to '0' instead."); idleAnimation = 0; } GameObject obj = new GameObject(objName); var objData = new InteractiveObjectData(lbd.MML.Value.MOMs[momIndex], material); var animator = obj.AddComponent <TODAnimator>(); animator.SetAnimation(objData.Animations[idleAnimation]); if (playIdleAnimation) { animator.Resume(); } var objScript = obj.AddComponent <InteractiveObject>(); objScript.Data = objData; // load the Lua script if it's given if (!string.IsNullOrEmpty(scriptPath)) { objScript.Script = InteractiveObjectLuaScript.Load(scriptPath, objScript); } return(obj); }
private void spawnObject() { LBD lbd = ResourceManager.Load <LBD>(PathUtil.Combine(Application.streamingAssetsPath, "original", "STG00", "M000.LBD")); var texSetOpts = TextureSetOptions.GetFromLBDPath( PathUtil.Combine(Application.streamingAssetsPath, "original", "STG00"), Shader.Find("LSDR/ClassicDiffuse"), Shader.Find("LSDR/RevampedDiffuse")); Material mat = new Material(DreamSystem.GetShader(alpha: false)); DreamSystem.TextureSetSystem.RegisterMaterial(mat, texSetOpts); InteractiveObject.Create(lbd, 0, mat, "Head guy", 1, false, "lua/test.lua"); }
public void LoadLBD(string lbdPath) { Logger.Log()(LogLevel.INFO, $"Loading LBD from: {lbdPath}"); LBD lbd; using (BinaryReader br = new BinaryReader(File.Open(lbdPath, FileMode.Open))) { lbd = new LBD(br); } Logger.Log()(LogLevel.INFO, "Successfully loaded LBD"); LBDDocument document = CreateDocument(lbd); _treeController.PopulateTreeWithDocument(document, Path.GetFileName(lbdPath)); }
public void LoadLBD(string lbdFolder, LegacyTileMode tileMode, int lbdWidth) { lbdFolder = PathUtil.Combine(Application.streamingAssetsPath, lbdFolder); TextureSetSystem.DeregisterMaterial(LBDDiffuse); TextureSetSystem.DeregisterMaterial(LBDAlpha); TextureSetSystem.RegisterMaterial(LBDDiffuse, TextureSetOptions.GetFromLBDPath(lbdFolder, Classic, Revamped)); TextureSetSystem.RegisterMaterial(LBDAlpha, TextureSetOptions.GetFromLBDPath(lbdFolder, ClassicAlpha, RevampedAlpha)); GameObject lbdRenderer = new GameObject("LBD Renderer"); LBDTileMap tileMap = lbdRenderer.AddComponent <LBDTileMap>(); GameObject lbdColliders = new GameObject("LBD Colliders"); string[] lbdFiles = Directory.GetFiles(lbdFolder, "*.LBD", SearchOption.AllDirectories); LBDColliders = new GameObject[lbdFiles.Length]; for (int i = 0; i < lbdFiles.Length; i++) { string lbdFile = lbdFiles[i]; Vector3 posOffset = Vector3.zero; if (tileMode == LegacyTileMode.Horizontal) { int xPos = i % lbdWidth; int yPos = i / lbdWidth; int xMod = 0; if (yPos % 2 == 1) { xMod = 10; } posOffset = new Vector3(xPos * 20 - xMod, 0, yPos * 20); } LBD lbd = ResourceManager.Load <LBD>(lbdFile); GameObject lbdCollider = createLBDTileMap(lbd, posOffset, tileMap.TileCache); lbdCollider.transform.SetParent(lbdColliders.transform); LBDColliders[i] = lbdCollider; } foreach (var m in tileMap.TileCache.Values) { m.Submit(); } }
private void spawnObject() { if (SpawnedObject != null) { return; } var lbdPath = PathUtil.Combine(Application.streamingAssetsPath, LBDFile); LBD lbd = ResourceManager.Load <LBD>(lbdPath, "scene"); var texSetOpts = TextureSetOptions.GetFromLBDPath(Path.GetDirectoryName(lbdPath), Shader.Find("LSDR/ClassicDiffuse"), Shader.Find("LSDR/RevampedDiffuse")); Material mat = new Material(DreamSystem.GetShader(alpha: false)); DreamSystem.TextureSetSystem.RegisterMaterial(mat, texSetOpts); SpawnedObject = InteractiveObject.Create(lbd, EntityNumber, mat, EntityID, IdleAnimation, PlayIdleAnimation, LuaScript); SpawnedObject.transform.position = transform.position; }
/// <summary> /// Create an LBD tilemap GameObject from an LSD level tileset. /// </summary> /// <param name="lbd">The loaded LBD file.</param> /// <returns>A GameObject containing loaded meshes for all tiles in their layout.</returns> public GameObject CreateLBDTileMap(LBD lbd, Dictionary <TMDObject, Mesh> cache) { Profiler.BeginSample("AN LBD!!!"); GameObject lbdTilemap = new GameObject("LBD TileMap"); List <CombineInstance> meshesCreated = new List <CombineInstance>(); // we're combining meshes into a collision mesh // for each tile in the tilemap int tileNo = 0; foreach (LBDTile tile in lbd.TileLayout) { int x = tileNo / lbd.Header.TileWidth; int y = tileNo % lbd.Header.TileWidth; // create an LBD tile if we should draw it if (tile.DrawTile) { GameObject lbdTile = createLBDTile(tile, lbd.ExtraTiles, x, y, lbd.Tiles, meshesCreated, cache); lbdTile.transform.SetParent(lbdTilemap.transform); } tileNo++; } // combine all tiles into mesh for efficient collision Mesh combined = new Mesh(); combined.CombineMeshes(meshesCreated.ToArray(), true); MeshCollider mc = lbdTilemap.AddComponent <MeshCollider>(); mc.sharedMesh = combined; // add LBDSlab component for controlling fog/culling // LBDSlab slab = lbdTilemap.AddComponent<LBDSlab>(); // slab.MeshFog = lbdTilemap.GetComponentsInChildren<MeshFog>(); // slab.CullMesh = lbdTilemap.GetComponentsInChildren<CullMeshOnDistance>(); // slab.MeshRenderers = lbdTilemap.GetComponentsInChildren<MeshRenderer>(); Profiler.EndSample(); return(lbdTilemap); }
public void CreateObject() { if (SpawnedObject != null) { return; } var lbdPath = PathUtil.Combine(Application.streamingAssetsPath, LBDFile); LBD lbd = ResourceManager.Load <LBD>(lbdPath, "scene"); var texSetOpts = TextureSetOptions.GetFromLBDPath(Path.GetDirectoryName(lbdPath), Shader.Find("LSDR/ClassicDiffuse"), Shader.Find("LSDR/RevampedDiffuse")); Material mat = new Material(Shader.Find("LSDR/RevampedDiffuse")); TIXTexture2D tex = ResourceManager.Load <TIXTexture2D>(texSetOpts.APath); mat.mainTexture = tex; SpawnedObject = InteractiveObject.Create(lbd, EntityNumber, mat, EntityID, IdleAnimation, PlayIdleAnimation, LuaScript); SpawnedObject.transform.SetParent(transform); SpawnedObject.transform.localPosition = Vector3.zero; }
private GameObject createLBDTileMap(LBD lbd, Vector3 posOffset, Dictionary <TMDObject, FastMesh> tileCache) { List <CombineInstance> colliderMeshes = new List <CombineInstance>(); int tileNo = 0; for (int i = 0; i < lbd.TileLayout.Length; i++) { int x = tileNo % lbd.Header.TileWidth; int y = tileNo / lbd.Header.TileWidth; LBDTile tile = lbd.TileLayout[x, y]; // create an LBD tile if we should draw it if (tile.DrawTile) { FastMesh mesh = createTileMesh(tile, lbd.Tiles, tileCache); var matrix = mesh.AddInstance(new Vector3(x, -tile.TileHeight, y) + posOffset, tileRotation(tile)); colliderMeshes.Add(new CombineInstance { mesh = mesh.Mesh, transform = matrix, subMeshIndex = 0 }); if (mesh.Mesh.subMeshCount > 1) { colliderMeshes.Add(new CombineInstance { mesh = mesh.Mesh, transform = matrix, subMeshIndex = 1 }); } // now do extra tiles LBDTile curTile = tile; int j = 0; while (curTile.ExtraTileIndex >= 0 && j <= 1) { LBDTile extraTile = lbd.ExtraTiles[curTile.ExtraTileIndex]; FastMesh extraTileMesh = createTileMesh(extraTile, lbd.Tiles, tileCache); var extraMatrix = extraTileMesh.AddInstance(new Vector3(x, -extraTile.TileHeight, y) + posOffset, tileRotation(extraTile)); colliderMeshes.Add(new CombineInstance { mesh = extraTileMesh.Mesh, transform = extraMatrix, subMeshIndex = 0 }); if (extraTileMesh.Mesh.subMeshCount > 1) { colliderMeshes.Add(new CombineInstance { mesh = extraTileMesh.Mesh, transform = extraMatrix, subMeshIndex = 1 }); } curTile = extraTile; j++; } } tileNo++; } return(createLBDCollider(colliderMeshes, posOffset)); }
private void createLBDTileMap(LBD lbd, Dictionary <TMDObject, FastMesh> tileCache) { createLBDTileMap(lbd, Vector3.zero, tileCache); }