0

A PlayerPrefs/mysql texture management for the Unity3d WebPlayer

Posted by admin on April 22, 2012 in mysql, Unity3d

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:

texture manager experiment

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.

The “alternative content” link at the bottom strip on the linked page is my that disappears after loading WebPlayer is my template element which allow the users which do not have the Unity3d plugin installed to access the alternative content which in this case is the picture gallery. The javascript enabled mobile devices that do not hawe the Unity3d WebPlayer support got automatically redirected.

 
2

Upload your texture to Unity and roll it

Posted by admin on February 3, 2012 in Unity3d

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.

 

 
0

Runtime user textures loading experiment

Posted by admin on January 7, 2012 in Unity3d

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.runtime textures experiment

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 example textures (54) are here.

 

 
0

SVG runtime importer for getting vector shapes into Unity

Posted by admin on August 8, 2011 in Unity3d

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.

In order to manipulate the colors which are specified in hexadecimal values as svg attributes, I have used two more scripts from the Wiki, i.e. HexConverter and HSBColor.

You can download the sources from here:

svg runtime importer (231)

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.

 
0

Runtime bounding boxes in Unity

Posted by admin on July 6, 2011 in Unity3d

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:

runtime bounding boxes (252)

The models used in this example come from here: http://www.3dmodelfree.com

 
0

Rubics cube

Posted by admin on May 30, 2011 in Unity3d

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.

 

You can download the sources from here (208)

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.  There are also two php scripts for communication with mysql databases for reading and storing the scores.

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

 
0

Space configurator template

Posted by admin on May 3, 2011 in Unity3d

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.

What do you think of the idea of making the space configurator to share?

View Results

Loading ... Loading ...

 
2

My Unity3d experiments

Posted by admin on March 7, 2011 in Unity3d

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.

What is your navigation preference in virtual world?

View Results

Loading ... Loading ...

 

Copyright © 2011-2012 virtualPlayground All rights reserved.
VP based on Desk Mess Mirrored v1.8.3 theme from BuyNowShop.com.

NextGEN Public Uploader by WebDevStudios