I’m making good progress with my improved terrain editing tools. Right now I can right click to select the terrain and a goofy cone shows up. The cone points down and shows the area that will be affected by clicking the mouse. You can scroll the mouse wheel to move the cone up or down, changing the size of the circle within which vertices will be affected. Right after I finished implementing all this I realized that a scaleable sphere centered on the mouse cursor makes so much more sense, so I’ll have to fix that. In any case, if you have the magical cone up and click the left mouse button, any vertices within the circle of influence™ will move along the y-axis by 5 units. You can then save the scene and the changes persist. There are lots of things that need to be improved here but the basic functionality of being able to select a group of vertices with the mouse and change them with a click is totally working. I honestly didn’t think I would get this far this fast, so hopefully I can polish this up a bit then make a real scene very soon.
Planning and Development
Still more editor updates
Planning and DevelopmentI’m getting really close to a functional tool with the world editor. I can now load a scene, add objects, select objects, translate, rotate, and scale objects, and save the scene. The editor saves the scene in two passes. First it writes a .png to the server that is a height map built from the scene’s terrain, then it writes a .json file that contains the name, location, rotation, and scale of each object in the scene. Those two files can then be used to load the scene later. There are just a few more abilities I want to add.
- Remove objects
- This should be really straightforward, but it will definitely be handy to be able to remove objects that are no longer needed without having to manually edit the .json file.
- Add lights
- I might actually save this one till later since it’s easy enough to just add a sunlight lamp or some ambient light to the whole world, but it would be nice for things like lamp posts or other cool atmospheric effects.
- Edit terrain
- I had a simple terrain editing tool in place but I was only able to select one vertex at a time and move it up or down. For managing a large scene this really isn’t practical. I want to have a scale-able circle projected onto the terrain where clicking raises all of the vertices in the circle and shift-clicking lowers them. I’m hoping this will be relatively easy to implement.
Once these basic abilities are in place I will start adding to the library of objects that can be placed into a scene. After I have the basic assets for Penrith Forest available, I’ll make the very first iteration of that area. Hopefully I can release a small demo shortly after that. I’m pretty excited to be at this point.
Editor – add assets!
Planning and DevelopmentCheck this out:What’s that on top of the hill? A flower? How did that get there, you may ask. Through that nifty little button at the top of the screen that says “Add Assets” would be the answer. I can now add objects to a scene using the world editor, then move them into place wherever they belong. Next I’ll need to implement the scene saving function, and then we’ll be cooking with gas.
Raycasting
Planning and DevelopmentRaycasting has been giving me fits. The problems I was having with raycasting are what really pushed me to switch to a perspective camera in the world editor but it turns out that wasn’t really the issue. I’m not completely sure what was causing the problem but after a fair amount of digging I discovered that rays were always being shot just below the pointer’s location on the screen. No matter which way the camera was oriented, rays were always just low. I really banged my head against a wall on this one but finally figured out that the menu at the top of the editor was throwing off something. I had the <div> containing the menu nested inside the <div> to which THREE.js adds a canvas for rendering. This was messing up some kind of calculation and making THREE.js think the screen was shorter than reality and consistently pushing rays down. To fix this I just moved the nav bar <div> beside the display <div> and set its location to “absolute” with CSS. This fixed the issue with raycasting and also made the background of the menu not stretch all the way across the screen, which I kind of like, so that was a happy accident. Now that raycasting is working again, I can work on selecting objects and improving the tools to manipulate them in a scene.
Editor camera
Planning and DevelopmentI’ve been struggling with the camera in the world editor for the last few days. I had an orthographic camera as the primary view and I liked that look but it came with some complications. What it really comes down to is that I don’t 100% understand how orthographic cameras work but in any case I was having trouble getting it to act the way I wanted. The near and far clipping planes confused me and even when it worked the way I wanted it to I wasn’t exactly sure why. Zooming the view versus moving the camera seemed to cause problems with raycasting, which I need for selecting objects in the scene.
For some reason I was worried that a perspective camera would be more difficult to work with for editing. I guess I thought it would distort things that are far away or off to the side in the view, but I changed the primary camera over to a perspective camera and it works fine. It’s different from an orthographic view, of course, but not drastically so. It may actually work out well because the native view in the editor will be closer to what players will see in the actual game.
At some point I may add the ability to the editor to switch between perspective and orthographic cameras, but that’s definitely a bonus feature for some time down the road. Now I can get back to working on things that will actually help me get content created, instead of ridiculous, minor issues with the way things are rendered to the screen.
More editor update
Planning and DevelopmentThe world editor is really starting to come together. Here’s the latest:
It’s still pretty rudimentary, I realize, but in the editor I can now hit the little “Load Scene” button in the menu at the top and it opens a box that lists scenes that are available to load. It then reads the scene file and the associated height map and creates a terrain and adds any objects from the scene file to the scene itself. That white thing is a light helper that will probably eventually go away. Once the scene is loaded you can rotate around, pan, and zoom to your heart’s content. Again, I know this is pretty basic stuff but it’s cool to me that I’m emulating some of the basic functionality of Blender but in a browser. I now need to implement that button that says “Add Asset” so that I can actually add stuff to the scene. I also need improve the tools to manipulate objects in the scene, add lights, improve the terrain editor, etc., etc., etc.
Also, GIMP 2.10.0 is out and looks great so far.
Also, happy birthday Josh!
Editor update
Planning and DevelopmentI’m still working on the world editor. I got the camera rotation, panning, and zooming working pretty much exactly the way I want, and I put a little octahedron at the point of the camera target just so I can tell where it’s looking. Now I’m working on a UI design for the editor. So far I’ve created a little menu at the top of the screen with a few options and some drop-down options too. I also added a dynamic box so that I can select which chunk I want to edit. As a side note I’ve finalized that the chunks are 1,024 x 1,024 meters, and the center of the world is at chunk [127, 127]. Assuming that the world extends out equally from this point, which is not strictly a requirement moving forward, it is 256 x 256 chunks. That’s a square world that is 262,144 meters on a side, or 162 miles. The total potential area is over 26,000 square miles. That’s actually way, way too big to fit within the lore of Tright. Lyridia will actually be closer to the size of Jamaica, maybe around 4,000 square miles. That’s still almost 100 x 100 chunks. There’s is absolutely no way I would be able to create 10,000 chunks of content by myself, but that’s ok. If I make a settlement on the east edge of the island and then one on the west edge I don’t necessarily have to create all 98 chunks in between them, so long as players can’t venture into areas that don’t exist.
World editor improvements
Planning and DevelopmentI started to not work on the game tonight but I’m really glad I did. In the world editor now you can pan, rotate, and zoom the camera. Rotate and zoom both work pretty much perfectly at this point. Panning also works, but doing so moves you along the x and z axes no matter the camera’s orientation. Obviously I want the camera to pan along the axes of the camera’s viewport, but I think that should be relatively easy to implement. Other than that it is really quite cool to be able to zoom in and out and rotate around the scene to see things from any angle. Of course, there’s nothing to really see at this point other than a really basic test terrain, but it’s a start and I like it.
Terrain testing
Planning and DevelopmentI thought a good way to get back into development would be to re-familiarize myself with the height map system. It turned out to be a good place to start because I wasn’t 100% on how it all worked but now I think I am. Small changes in the red value on the maps make huge differences in the terrain height. Changes to the green value are mid-range. Changes to the blue value as pretty minuscule. This was the intended design, but I may have had the blue and green values switched. I’m not really sure, but in any case it is correct now. Also, it turned out my game code works just fine with the newly created height maps. So I can make something in GIMP, upload it, then run around on that terrain in the game world.
Since I’m clear on the terrain system, my next step is to improve my terrain editing tools. I can use an image editor like GIMP, but it’s not practical. The difference between [r,g,b] values of [128, 0, 0] and [129, 0, 0] (or 0x800000 and 0x810000 in hex) is virtually invisible to the human eye, but it’s a height difference of 256 meters in the game world, which is a pretty big deal. I already have a mechanism to raise and lower individual terrain vertices, but I need to develop something more like a brush tool that can be resized and dragged across the terrain to raise or lower multiple points simultaneously. This will be a little complicated to implement, but with that tool I’ll have a real terrain editing system and I can move into asset placement tools, which will be much more fun.
I’m still here
Planning and DevelopmentThe last few weeks have been unproductive from a development standpoint but I’m going to start back up soon. Since I’ve worked out the basics of the height map system my next step is to polish the world editor so that I can make a real terrain and put some actual assets into it. It will be rudimentary at first but I need a somewhat finished product produced by the world editor to keep me motivated to stay moving ahead.