Flyff World Editor in Unity3d ?
Should I continue with this and make a whole new FlyFF editor in Unity3d?
So far I can load all kinds of worlds in without objects and without water/sfx/textures
http://i.imgur.com/BGCMCbV.jpg
For the interested ones here is how I read a .LND file :)
If you are going to attempt this, generate your own mesh instead of using the unity terrain.
It will make stuff easier later on:)
Code:
using UnityEngine;
using System.Collections;
using System.IO;
public class FlyFFLND
{
//private float[,] terrainHeight;
//private RestrictionType[,] moveRestriction;
public TerrainData terrainData;
public WaterData waterData;
private int MAP_SIZE = 128;
public FlyFFLND()
{
terrainData = new TerrainData(MAP_SIZE);
waterData = new WaterData(16);
}
public void LoadData(BinaryReader file)
{
uint version = file.ReadUInt32();
uint offset_x = 0;
uint offset_y = 0;
//Get X and Y offset
if (version >= 1)
{
offset_x = file.ReadUInt32();
offset_y = file.ReadUInt32();
}
// float[,] unityHeights = new float[MAP_SIZE + 1, MAP_SIZE + 1];
for (int x = 0; x < MAP_SIZE + 1; x++)//X axes
{
for (int y = 0; y < MAP_SIZE + 1; y++)//Y axes
{
float height = file.ReadSingle();
if (height >= 4000.0f) // Die
{
height -= 4000.0f;
terrainData.moveRestriction[x, y] = TerrainData.RestrictionType.Die;
}
if (height >= 3000.0f) // NoMove
{
height -= 3000.0f;
terrainData.moveRestriction[x, y] = TerrainData.RestrictionType.NoMove;
}
if (height >= 2000.0f) // NoFly
{
height -= 2000.0f;
terrainData.moveRestriction[x, y] = TerrainData.RestrictionType.NoFly;
}
if (height >= 1000.0f) // NoWalk
{
height -= 1000.0f;
terrainData.moveRestriction[x, y] = TerrainData.RestrictionType.NoWalk;
}
terrainData.terrainHeight[x, y] = height;
}
}
//Water/Cloud
for (int x = 0; x < 16; x++)//X axes
{
for (int y = 0; y < 16; y++)//Y axes
{
byte waterHeight = file.ReadByte();//Height
waterData.waterHeight[x, y] = waterHeight;
byte waterType = file.ReadByte();// 1,2,3 What is it none? Cloud? Water?
WaterData.WaterType waterEnum = WaterData.WaterType.None;
switch (waterType)
{
case 0:
waterEnum = WaterData.WaterType.None;
break;
case 1:
waterEnum = WaterData.WaterType.Cloud;
break;
case 2:
waterEnum = WaterData.WaterType.Water;
break;
default:
Debug.LogError("something gone wrong");
break;
}
waterData.waterType[x, y] = waterEnum;
}
}
if (version >= 2)
{
for (int x = 0; x < 16; x++)//X axes
{
for (int y = 0; y < 16; y++)//Y axes
{
byte aLocation = file.ReadByte();//skip
}
}
}
byte layer_count = file.ReadByte();
for (int i = 0; i < layer_count; i++)
{
short tile_id = file.ReadInt16();
for (int x = 0; x < 16; x++)//X axes
{
for (int y = 0; y < 16; y++)//Y axes
{
uint isVisible = file.ReadUInt32();//Patch visible? Help
}
}
for (int x = 0; x < MAP_SIZE; x++)//X axes
{
for (int y = 0; y < MAP_SIZE; y++)//Y axes
{
byte r = file.ReadByte();
byte g = file.ReadByte();
byte b = file.ReadByte();
byte a = file.ReadByte();
}
}
}
uint object_count = file.ReadUInt32();
for (int i = 0; i < object_count; i++)
{
uint type = file.ReadUInt32(); // Must be 0
float angle = file.ReadSingle();
float axis_x = file.ReadSingle();
float axis_y = file.ReadSingle();
float axis_z = file.ReadSingle();
float position_x = file.ReadSingle();
float position_y = file.ReadSingle();
float position_z = file.ReadSingle();
float scale_x = file.ReadSingle();
float scale_y = file.ReadSingle();
float scale_z = file.ReadSingle();
uint m_dwType = file.ReadUInt32();
uint mesh_id = file.ReadUInt32();
uint motion = file.ReadUInt32();
uint AIIInterface = file.ReadUInt32();
uint dwAI2 = file.ReadUInt32();
}
int sfx_count = file.ReadInt32();
for (int i = 0; i < sfx_count; i++)
{
uint type = file.ReadUInt32(); // Must be 3
float angle = file.ReadSingle();
float axis_x = file.ReadSingle();
float axis_y = file.ReadSingle();
float axis_z = file.ReadSingle();
float position_x = file.ReadSingle();
float position_y = file.ReadSingle();
float position_z = file.ReadSingle();
float scale_x = file.ReadSingle();
float scale_y = file.ReadSingle();
float scale_z = file.ReadSingle();
uint m_dwType = file.ReadUInt32();
uint mesh_id = file.ReadUInt32();
uint motion = file.ReadUInt32();
uint AIIInterface = file.ReadUInt32();
uint dwAI2 = file.ReadUInt32();
}
file.Close();
// return unityHeights;//Return total height
}
}
public class WaterData
{
public enum WaterType
{
None,
Cloud,
Water
}
public byte[,] waterHeight;
public WaterType[,] waterType;
public WaterData(int size)
{
}
}
public class TerrainData
{
public enum RestrictionType
{
Die,
NoMove,
NoFly,
NoWalk
}
public float[,] terrainHeight;
public RestrictionType[,] moveRestriction;
public TerrainData(int MapSize)
{
moveRestriction = new RestrictionType[MapSize + 1, MapSize + 1];
terrainHeight = new float[MapSize + 1, MapSize + 1];
}
}
A example to load all .LND files
Code:
void SetTerrainLNDHeight(string path)
{
//ToDo Read WLD
string tempLNDNAME;
//Doesnt really seem to work I need to set the right size!!
int newTerrainSize = (MAP_SIZE * wldSizeX);//times bigger then normal
terrain.terrainData.heightmapResolution = MAP_SIZE * wldSizeX;//(newTerrainSize * wldSizeX);
terrain.terrainData.size = new Vector3(newTerrainSize, 1000, newTerrainSize);
for (int y = 0; y < wldSizeY; y++)
{
for (int x = 0; x < wldSizeX; x++)
{
tempLNDNAME = string.Format("{0}\\{1}{2:d2}-{3:d2}.lnd", path,worldName, x, y);
try
{
BinaryReader binaryReader = new BinaryReader(new FileStream(tempLNDNAME, FileMode.Open));
terrain.terrainData.SetHeights(x * MAP_SIZE, y * MAP_SIZE, GenerateLND(binaryReader));
terrain.Flush();
}
catch(Exception ex)
{
Debug.Log(ex);
}
}
}
}
Re: Flyff World Editor in Unity3d ?
Hmm that sounds not that bad. However is unity 3D enough compatible to load also the models etc. Or do you need to re-program it.
Re: Flyff World Editor in Unity3d ?
Not sure you can have the same algorithm to render terrain's texture (and load models) =/ But if it works why not =)
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
Aishiro
Not sure you can have the same algorithm to render terrain's texture (and load models) =/ But if it works why not =)
Well I can pretty much load the textures is no problem since Unity3d can load .dds files just fine :thumbup:
Only problem is loading it from the .lnd file. I made a mistake somewhere which I will find out and fix.
It will just be a lot of work
Re: Flyff World Editor in Unity3d ?
I don't talk about texture loading but the way to render layers... I think you'll need to write code for openGL or DirectX, that's why I'm not sure Unity is a good idea for making a world editor. I tried with XNA and I was limited so I never finished it... Good luck ;)
Re: Flyff World Editor in Unity3d ?
I'm not really putting much time on this at the moment I'm kinda working on my own game :P
But I managed to load the lnd files correctly now and well grab the data and keep them.
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
MisterKid
I'm not really putting much time on this at the moment I'm kinda working on my own game :P
But I managed to load the lnd files correctly now and well grab the data and keep them.
Then why bother to make this post?
It will most likely be another "never will finish" project.
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
WebSpider
Then why bother to make this post?
It will most likely be another "never will finish" project.
To show that it can be done and this is a showcase section I can show whatever I want when I want that have to do with FlyFF.
If you have a problem with me/my things then don't bother looking
Quote:
Originally Posted by
Aishiro
I don't talk about texture loading but the way to render layers... I think you'll need to write code for openGL or DirectX, that's why I'm not sure Unity is a good idea for making a world editor. I tried with XNA and I was limited so I never finished it... Good luck ;)
You can really modify alot in Unity :P I do have to think about how to do several things tough. Like those clouds/water and the coloring of the terrain textures. Also the NoMove things I will have to find something for that aswell
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
MisterKid
To show that it can be done and this is a showcase section I can show whatever I want when I want that have to do with FlyFF.
If you have a problem with me/my things then don't bother looking
You can really modify alot in Unity :P I do have to think about how to do several things tough. Like those clouds/water and the coloring of the terrain textures. Also the NoMove things I will have to find something for that aswell
I don't have a problem with you, but seeing thousands of projects that will never be finished is a bit annoying. A fail/sad attempt to acquire acknowledgement in my opinion.
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
WebSpider
I don't have a problem with you, but seeing thousands of projects that will never be finished is a bit annoying. A fail/sad attempt to acquire acknowledgement in my opinion.
If you find it annoying that projects wont get finished then how about you start your own project ?
I will continue working on it but as I said I won't put much time in it since it won't be necessary/Don't have much time.
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
MisterKid
If you find it annoying that projects wont get finished then how about you start your own project ?
I will continue working on it but as I said I won't put much time in it since it won't be necessary/Don't have much time.
I have my own projects, I just don't make a topic to show something that will never be finished/released just to get attention with questions like "ohh, Should I continue with this??" or whatever.
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
WebSpider
I have my own projects, I just don't make a topic to show something that will never be finished/released just to get attention with questions like "ohh, Should I continue with this??" or whatever.
I don't care what you think I post whatever I want and think people find interesting.
What are you doing here anyway? You don't even share things I think you only leech.
Re: Flyff World Editor in Unity3d ?
Quote:
Originally Posted by
MisterKid
I don't care what you think I post whatever I want and think people find interesting.
What are you doing here anyway? You don't even share things I think you only leech.
Ok then, good luck with your posts.
Very useful, thanks for sharing! :D:
Re: Flyff World Editor in Unity3d ?
Added a example how I load .lnd files :rolleyes: