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.
The link to the demo is here and the
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
The Unity has its own bounding boxes buit in editor which show up when you manipulate the objects, like transform boxes and collider boxes, but those are unavailable at runtime.
This project can help you to draw the bounding boxes ingame, using GL.Lines. The boxes get aligned to the local space of the GameObjects where they are attached.
The points calculation is taken from the renderers.bounds from all renderers in the GameObject hierarchy.
Alternatively if you wanted some other size – than calculated from the renderers bounds – for your bounding box, the script contains a functionality to use the box collider instead. You can attach and size a box collider to the GameObject, check the “colliderbased” variable on the script in the inspector – and the calculation will follow the box collider.
Obviously in order to get a mouse-click interaction on the objects – like in the demo scene – there have to be colliders attached to GameObject.
If the parent GameObject itself has no collider and the colliders are attached to the child objects only, it is necessary to attach a rigidbody to the parent GameObject in order to pass on the mouse-click collider interaction to parent.
The below screenshot links to the webplayer demo.
You can download the complete package, containing the demo scene from the picture above from here:
Some of the models used in the scene come from here: http://www.3dmodelfree.com
A version with simpler scene – if you prefer not to clutter your disk too much – is available on the AssetStoreas the BoundBoxes package.
A bit advanced version of this package is also available at the Unity AssetStore as the DimBoxes package. That will also let you place the dimensions and extension lines, here is the demo:
The demo scene in the DimBoxes package is a bit simplified, but the scripts used are the same. All the above should work fine both in Unity Indie as well as Unity Pro.
You can also have a look at the 3d object viewer that I created with that in the link below.:
This however uses the Unity Pro feature of dynamic loading of the streamed scenes. The WebPlayer itself has 150 kB or even less of data only and subsequent scenes are loaded/unloaded into it.
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
FPS games are fascinating, but unfortunately I feel I haven’t got enough creative capabilities I could to rely on to make any attempts to make a game on my own. Instead, I would prefer to make some utility applications. The simplest ones to make with Unity are the architectural walkthroughs and I have already done some of them. Possibly mine are not impressive enough and I do not experience much demand for it. And that is why I have to reach for the other, similar, but more difficult category, that are various 3d space configurators that begin to appear on webpages of furniture or interior stores and property developers. Those configurators usually have libraries of items from the store. They allow a user to sign in, register ant place the library items in the specified space and then explore it.
For someone like me it could be a next step in experimenting in Unity and sounds like a challenge. So I am going to make the space configurator template and publish here the state of development and the end result when I finish it.
At the moment I have some steps already done, but I have to sort out the basic functionalities and setup the user interface which has to include all of them. I have an idea of four basic functionalities:
- navigation: walk/orbit
- creation – and here the mentioned earlier library list should appear
- edition – will allow to move, rotate, delete and texture faces of created objects
- file – for opening and saving projects and textures import
When I am done with graphic user interface I will publish the application. Some of its elements will be inactive at the beginning and I will activate them in the course of progress.
I am also going to make the source code of the whole project or some parts of it available here for download and sharing. If it sounds interesting to you, please vote in the below poll to motivate me.
A walkthrough navigation example
Here is an example of a myth style kids game environmnent. There are two navigation modes embedded in. One is a walk mode and the other is an orbit mode. You can switch between them by double clicking the in the game window. The other choice is the way of mouse interaction which is set here to MouseDrag as default and can be switched to MouseMove by clicking the “hand” icon at the bottom left corner.