This is a simple lod testing example. It is based on Unity3d v.4 Pro buit-in LODGroups and the runtime access to that.
I was just making an automated tool for the creation of the big LOD based scenes from thousands of mesh pieces and just needed an experimental way to determine the LOD ranges to put into LODs.
Here is what I have ended up with:
Click on the image to open the WebPlayer.
Move the slider and see what is going on. Obviously the ranges can not overlap and that is why manipulating with the top sliders is also moving the positions of the sliders below.
Of course in the normal work scenario the mesh swaps should run in the invisible way. In this case the meshed have been deliberately coloured to make the swaps visible.
All the movable scene objects are groupped into the categories and attached to the array of lists in the animation script.
The lists gets sorted by the objects positions and the script loops through the subsequent lists applying the animation with incremented delay.
And that is what I have got. Click on the image to open the WebPlayer.
I just got accustomed for baking and using the lightmaps, but because these are inappriopriate for this case, I tried Screen Space Ambient Occlusion to simulate the shadows.
The runtime shadows available in Deferred Lighting rendering path are decrease the FPS quite much and lack antialiasing, but could be an option in I wanted to make just the every frame screenhots to combine them into video file at lower resolution, what I was actually going to do.
I got recently asked by a friend to create a 3d vision of Faculty of Physics at AGH University of Science and Technology in Krakow, PL to be laser engraved inside a glass cuboid. This is just an artistic form of the boron atom. It has to be artistic and as close as possible to the scientific model. Here it is:Then I just could not resist a temptation to animate the electrones on their orbits. You can use the top left button to controll the animation.
The animation trails use Unity3d trail renderer and the static trails – made of the alpha-mapped mesh for the purpose of engraving are switched off for the time of animation.
I just can not wait to see that engraved in glass and I am going to publish the picture of that engraved once I get it.
And here are the screenshots:
And ones with TrailRenderer on:
And ones with camera MotionBlurr on:
And ones with ParticleSystems:
And al last it comes. Pictures and video taken in a quite rudimentary conditions in the hotel. The tradesmen had ordered the data to be delivered in the .obj format and they had got it that way. Apparently were not able to imitate the diverse colour intensities and alpha-textures on the orbit toruses which I was hoping.
Here is a video.
The most common fluid layout for embedding the Unity3d WebPlayer is the full browser window one.
However to enable some user – browser communication and user data uploads I needed other ones with constant size elements to display info, links and data upload forms.
Here are the examples:
You can download all the three html files zipped from here:
In this experiment I have created a simple two level edition system for online edits of the WebPlayer content.
The specially tagged geometry elements have a script attached, which displays a name label on hovering upon them. Clicking on them invokes the texture menu, which depends on number and kind of materials.
There are two edition levels simply depending on the authorisation level of the current user. The basic level is simply just unlogged user, while admin level is equivalent with the logged one. Both allow for the edits of the content, but in case of of unlogged user these are saved to the PlayerPrefs, while in the admin case are saved to mysql database and retrieved after the loading the scene.
The PlayerPrefs is the way for local storage of littleweight data on the local user computer, while mysql can serve for a global one.
If any mysql data given, the WebPlayer loads them first, and then loads the PlayerPrefs data, if any.
If you want to share the edits – you have of course to use the second option.
At the moment the solution supports the texture management and is basically aimed at visualisation of scenes, that share the same geometry, but differ with texture sets.
The base example is here:
In this blog I have used the WordPress blog login system. If you wanted to test how it works to edit and share the above example, Please register (if not registered) and log in to get the acces to the record manager.
The record manager serves to add and delete records to the database and generate the links.
The whole idea came from a friend of mine, who is an event organizer and organizes outdoor events, offering several scene setups with repetitive geometry, but individual graphics. This way he would get those setups with fixed geometry from me and then would be able tu put the individual graphic himself and send the links for his clients. Then the clients would still be able to experiment with the textures on their own – on the player prefs level – if he leaves this feature enabled for them.
This tiny Unity3d application could be aimed to help the people to imagine how the flat graphic would look when printed on a coffe mug, pencil or anything cylindric.
There is a square mesh in the window centre and you can put any .jpg, or .png texture up to 4 Mb from your local filesystem onto it. After that the square turns into a rectangle of image proportions.
There is the vertical slider for adjustment of the bending angle and and the knob for turning the transformation axis. The basics of mesh modifier script comes from here.
The more are the proportions distant from square, the more interesting is the effect.
The direct link to the application is here.
Below are some screenhots.
This is my second experiment related to loading of user textures. The first one is simpler one and can be found here.
The idea of this experiment is to allow the user to put his own textures from the local computer filesystem into the virtual environment and take the pictures of that. The example scene is constituted from a simple exhibition stand placed inside the exhibition hall.
On pressing on to a selection/textures button you enter the object selection mode and you can select the objects that were specially tagged indside the Unity3d editor. The selected object displays materials/textures window for it. The walls of this example exhibiton stand have the color texture palette assigned and the user is allowed to select between the palette colors or to put his own texture from the local computer filesystem. The floors of this stand have the floor covering texture palette assigned and the user has the choice within this palette only. I have assumed the pallette textures to cover the 1×1 area and they are tiled, while the user textures are supposed to be untileable and they stretch to the object size.
You are of course warmly welcome to try my example. Once you have put your bitmaps and done your selections and settings, you can save it and then retrieve when you play again. You can also take virtual shots with the special virtual camera. The shots are sent to server and generate a gallery. To save on the loading time I have applied the RGB565 format, using 64k color (High Color) palette.
The “Load your own texture” button opens the texture loadning form at the bottom strip of the page. When you select a file with that, the uploading of the file to the server starts and once this is completed the WebPlayer downloads it back from the server, showing the progress on the download info window.
The camera button generates a screenshot. The megapixel size of it can take two values: 1,3 or 5,2 depending on the selection, while the proportions are copied from the browser window. The screenshot then is sent to server in the png format and the uploading info window appears. The uploaded screenshots make the galleries. In order to access them, just click a galleries button below the camera, and that will display links to the galleries in the bottom strip of the page.
I needed to load some basic simple polygon shapes into Unity at runtime and get it there in form of the meshes. There are already some resources on Unity Community Wiki on import of svg files, but they regard to rendering those files to textures. I was wondering whether I could rex make the scripts by making them just to generate the sequences of points instead of rendering the whole images, but they seemed too complicated and to make things worse I got discouraged, because they were written in C#. On the other hand svg polygon specification seemed very simple, so my final choice was to write it from sctratch. The next step was to triangulate the polygons i.e. to fill them with triangles. I didn’t intend to go beyond the simple basic shapes so I have chosen the ear clipping method of triangulation which supports supports concave polygons, but not polygons with holes, or multiple polygons combined. This method is followed by the Triangulator script from Unify Community Wiki.
I have learned soon that a simple polygon shapes of identical appearance can take forms of various svg elements like “polygon”, “polyline”, “rect” (as rectangle) and “path”. From the above the “path” is most complicated, because can contain a number of internal commands.
All the elements can have attributes like name (“id”), color, opacity, transform, style, etc. I have selected to support in my simple importer only name, color, opacity and transform on rectangle element only. The color and opacity of the element transforms into properties of material in Unity.
You can download the sources from here:
I have tested it with files saved from Inkscape, Coreldraw and Illustrator. Please let me know if you get any errors or have some suggestions for improvement. The download contains the complete Unity3d project folder.
The tree image used in this example come from here: http://www.allfreevectors.com
Because my simple importer doesn’t support multiple/combined paths, the closed shape letters in the lettering example had to be opened by cutting them.
Recently I have added some interaction to this example, mouse clicking at the front side ot the graphic toggles the fill/outline display.
A Runtime bounding boxes example
I needed a runtime bounding box for usage as dimension lines recently. The Unity has its own bounding boxes buit in editor and you can see them when you manipulate the objects, like transform boxes and collider boxes, but those are unavailable at runtime. I could not find any satisfactory solutions on the web and decided to create my own.
I started from a lineDraw method, but I could not get satisfactory results with that and finally ended up with GL.LINES.
My solution comes out in form of two scripts, one is CalculateBounds.js, which you have to tie to the object, and the other is RenderBounds.js, which you have to tie to the camera. You can download them from here:
The models used in this example come from here: http://www.3dmodelfree.com
A Rubik’s cube scripting example
I have recently came to an idea of a Rubic’s cube as a nice scripting example.
Rubik® and Rubik’s Cube® are registered trademarks throughout the world of Seven Towns Limited. Seven Towns Limited is the exclusive licensee of copyright in the Rubik’s Cube puzzle. This post regards to Unity3d cube mechanism scripting example, not the game itself.
My idea of scripting the cube movement is based on selecting the relevant rows of cubes, placing them in rotation container, rotating container and putting it back from the container to the cube.
In my example I made use of the fact that the same script can run cubes of different sizes and you can also set it here to any integer starting from 2.
People cope with with Rubic’s with at various levels of ease and the script lets them to train on small sizes to slowly work out the algoritmh and then move to bigger sizes.
After setting the size you need to reset the cube in order to apply the new size.
You can adjust the view of the cube by dragging the mouse over the application window and scrolling the mouse in order to zoom in/out.
All the meshes are created dynamically and uv-mapped, and there is a possibility to add to the difficulty level by texturing the individual tiles or the whole sides of the cube. When the tiles are individually mappped (with arrows in this case), then – for the inside tiles – not only the color but also the rotation matters. When the sides are mappped with picture, then – for the inside tiles – not only the color and rotation, but also the strict position matters.
The settings and textures can be customized by image and xml data held in separate data folder.
In the web version there are also two php scripts for communication with mysql databases for reading and storing the scores.
In the standalone versions the scores are stored on the local computer in PlayerPrefs.
The above download is obviously targeted at Unity3d enthusiast interested in this game setup. In order to try to play the game just click the picture on the top so that opens the link to the WebPlayer or download any of the standalone versions below:
The deployments contains a customizable xml file pointing to the texture. By the modification of this you can easily put your own logo or custom graphics on the cube.
I have also utilised an interesting Unity3d ability to pick a localization based on the user’s system language with the Application.systemLanguage method. The default GUI language is English, but on the detection of Polish, the application reads that from the attached XML file.
The script could of course be also applied to other geometric regular and non-regular forms like pyramids.
This is a cube mechanism script. A far more challenging would be to create a general solving algoritmh for n-cube, that would be able to find the optimal solution in minimal number of steps. I have found some considerations on that subject here: http://kociemba.org/cube.htm
and there: http://www.wrongway.org