Thursday, September 17, 2015

Lund1658: Project setup

Creating the project

The very first step is to create a new project and define its structure. First I created several folders under "Assets" (right-click on the folder and select "Create > Folder") and a scene called "Main" under the folder "Scenes" ("File > New Scene" and then "File > Save Scene As").

Assets folders structure
Next I created a basic hierarchy that will allow me to find and work easily with all the objects in the scene. My approach has been to create an empty component "Museum" with a child for each of the sections in it (right-click on the Hierarchy view and select "Create Empty". Select the component and press F2 to rename). As children of these sections I created empty components for each of the tables in them, which will hold the meshes of the exhibits. At the same level as the sections I created another child called "Building" that will hold the mesh of the museum.

Main Scene's hierarchy

Importing the assets

The Blender file can be imported directly into Unity by dragging and dropping it into the Assets folder in the Project window. Another option is to export the meshes as FBX, OBJ or any other suitable format, then right-click on the assets folder and select "Import > New asset".

In  my case I went through with the first option and dropped the file into my "Assets/Models/Environment folder". The mesh objects are created automatically and all the materials are placed in a sub-folder called "Materials".

Assets created by Unity after importing the Blender file
Next I needed to import the textures and assign them manually. First I created a folder called "Textures" and imported all the image files by right-clicking on it and selecting "Import > New asset". Then I visualized each of the materials on the inspector and assigned the corresponding texture to the Albedo Map property.

Assigning textures to materials (standard shader)
In the cases in which the material in Blender had not been named, the same default material was created and assigned to the meshes. To solve this situation I created new materials manually and assigned them to the meshes by dragging and dropping them onto the mesh prefabs. Next I assigned the corresponding texture as explained previously.

In the case of the cupola Unity assigned a Transparent/Diffuse shader to the material. In this case we assign the image to the only texture slot available on its properties.

Assigning textures to materials (transparent diffuse shader)
Once all the materials have been assigned the museum looks like this:

Museum building after import and application of textures
In the case of the exhibits I had them exported to OBJ and then I imported them into Unity by using the "Import > New asset" contextual menu. The objects happened to be too big in proportion to the size of the museum and so they needed to be resized. This can be done in several ways and I chose to do it at import time.

To do this we just need to select the imported asset and visualize it on the inspector. Here there is an option "Scale factor" (located under the section "Meshes" of the tab "Model") that can be used to change the size of the mesh. After setting it to the desired value we need to click on "Apply" to make the changes effective.
Imported OBJ as seen on the inspector

Placing the assets in the scene

The next step is to fill our scene with objects. To do this we first drag and drop the "Museum" prefab from the "Assets > Models > Environment" folder into the "Environment" folder in the hierarchy. The prefabs for the Tables and Chairs can then be dragged into their corresponding section, leaving only the "Building" prefab inside the "Environment" folder. The exhibits are dropped next into their corresponding tables and renamed for clarification.

Placing objects in the scene
The objects can then be placed on their final locations by using their Transform. Simply select the object and set the desired location coordinates and rotation on the inspector.

Setting Transform parameters for the exhibits
To simplify the placement of the objects and scripting later on, I have applied the location coordinates of the tables to the Transforms of the Table components (Table_Inh_1, Table_Ind_1, etc.) holding the prefabs instead of to the prefabs themselves. The reason is that the transforms applied to their children will be local to these components, and it will be much easier to work with local coordinates than with global ones. For instance, when I place a Table mesh at (0, 0, 0) inside the "Table_Inh_1" component the former will be placed at the right location. Then if I want to place an exhibit on top of this table, right at the center, I can simply drag it into the same component "Table_Inh_1" and place it at (0, HEIGHT, 0).

Following a similar reasoning, all the transforms used to place the exhibits on their initial locations on the tables have been applied to the mesh objects instead of the parent component that holds them (for example, to "Tobacco_mesh" instead of its parent "Tobacco"). The reason is that I will want to provide the user with the option to inspect the exhibits closely and apply rotation, and I will want the exhibits to go back to their original transforms (location, rotation and scale) when exiting the inspection mode. My idea is to apply all of these "user transforms" to the parent component (e.g. "Tobacco") when in inspection mode, so that I will always be able to reset the exhibit to its original position by setting its parent's Transform back to rotation (0, 0, 0), no matter what the exhibit's initial condition was.

Finally, table rotations have also been applied to their meshes.

The following schema is an attempt to illustrate the previous explanation taking the Industry section as an example. The first table in this area of the museum holds two exhibits, a tobacco package and a mouthpiece. The corresponding transforms are indicated next to each of the components:

Industry - Position (0, 0, 0), Rotation (0, 0, 0)
|-- Table_Ind_1 - Position (X, Y, Z), Rotation (0, 0, 0)
     |-- Table_mesh - Rotation (X, 0, 0), Position (0, 0, 0)
     |-- Tobacco - Position (-POS, HEIGHT, 0), Apply User Transforms during inspection
          |-- Tobacco_mesh - Position (X, Y, Z), Rotation (X, Y, Z) = default position
     |-- Mouthpiece - Position (POS, HEIGHT, 0), Apply User Transforms during inspection
          |-- Mouthpiece_mesh - Position (X, Y, Z), Rotation (X, Y, Z) = default position

X, Y, Z indicate any transform values, since the real ones that I used are irrelevant for the explanation.
POS and -POS are lateral displacements relative to the center of the table (0, 0) that allow the two exhibits to be placed one next to the other.
HEIGHT is the value needed to elevate the exhibits from the floor to the table's surface.

Tobacco package and mouthpiece

Tuesday, September 8, 2015

Lund after 1658 (remastered)

As I mentioned on my first post, back in 2009 I created a small virtual museum as my Master Thesis. The project was called "Improving the experience of exploring a virtual museum: Lund after 1658" and included laser scanning of several objects ceded by the Kulturen museum in Lund (Sweden), and implementation of an interactive application. It was my first time at many things: laser scanning, 3D modelling, writing a long report in English... :-) So some of the things that I wrote now hurt my eyes, plus the modelling was quite poor since it was (and still is) out of the scope of my expertise. But even so it turned out to be an enjoyable experience and a very interesting and exciting project to me.

Some views of the original virtual museum

The application was implemented in EON Studio and is no longer available due to license restrictions. Because of this and the poor quality of the models, something that I have been willing to do since then is to re-implement the application and improve it. I'm not sure I can do much to improve the meshes of the scanned objects without having the originals, plus my modelling skills at the time are not much better than before, but at least I can bring the application back to life by using Unity this time.

So far I have started with the modelling of the new environment. It's too bad that I don't have anyone to help me with the assets, so I apologize in advance for any visual pain caused :-)

Distribution of exhibits by subject in the original virtual museum
3D model of the new museum building

The shape and distribution of the new museum has been redesigned to resemble more closely that of a real museum and to enhance communication between the different rooms. Additionally there are now more decorative elements such as arches, a garden or the use of a stained-glass texture for the cupola. As for the models of the exhibits, for now I will use the original ones.

Some of the objects exhibited in the virtual museum

Next I will focus on the creation of the project in Unity, importing all the assets and implementing a basic walk-through with collision and proximity detection.