technical architecture.

Unity3D

Architecture – Revit to Max to Unity

by on Dec.01, 2011, under Architecture, Interactive, Interactive, Portfolio, Unity3D

Here is a Revit -> 3dsmax -> Unity project that we worked on earlier this year.

the videos below are captured in HD in unity directly from some premade itween paths

Exterior axo from Dave Buck on Vimeo.

Realtime HD Architecture, Captured in Unity3D from Dave Buck on Vimeo.

Basic workflow was to export out the WorkSets from Revit as individual FBX files
Import them into 3dsmax with the file link manager, usually set to combine objects by material
from there run a set of scripts that collapsed / welded / AutoSmoothed / split meshes that were too large (65k verts is a pain) cleans up the layers, replaces materials, and exports the now unity friendly layers into different FBX’s for unitys consumption

Inside unity there are a few small steps needed, done mostly with AssetPostProcessors that hook up any external lightmaps that we generated in max, replace/reconnect any materials that are in our standard material library, and attach any components that are supplied in the max user properties fields.

bake the lighting to suit, (In this case, just give us some AO and Sunlight since we needed to be able to turn around revit design changes -> working webplayer overnight with minimal user babysitting.)

this workflow allowed the building owner to ‘walk’ around the design very rapidly after it was changed.

There are a few more captures up at http://vimeo.com/vsai/videos/ for anyone interested.

Leave a Comment more...

Unity per project compiler options, -unsafe

by on Nov.28, 2011, under csharp, Unity3D

I had to integrate a small set of third party code that calls down to some win32 dllimport bits, to do this I needed to be able to work with some pointers. which in c# need to be declared in an unsafe function, so that it knows to be unmanaged.

Slightly awkward, but it turns out that there is an -unsafe compiler option that needs to be turned on in unity/mono, and that you can do this very easily on a per project basis by adding a file ‘smcs.rsp’ to the root of your assets dir, and in there you can add the text ‘-unsafe’ to add this to the compiler commandline.

Reference threads: Setting Compiler Options, Unsafe code in Unity, How To: Set Project-Wide #pragma Directives with JavaScript

Other apparent uses stated in the threads are setting project wide defines and pragmas

2 Comments more...

ignore file for Mercurial and Unity

by on Nov.15, 2011, under Scripting, Unity, Unity3D

here’s a working ignore file for use of Unity and Mercurial simple, but slightly different from the instructions posted in the current docs, so figured i’d pass it on for anyone else who cares to check it out.

placed in a plain text file named .htignore in your project directory

syntax: glob

*.tmproj
*.pidb
*.sln
*.userprefs
*.csproj
*.unityproj

AnnotationManager
assetDatabase3
AssetImportState
assetservercachev3
AssetVersioning.db
BuildPlayer.prefs
BuildSettings.asset
EditorSettings.asset
EditorUserBuildSettings.asset
expandedItems
FailedAssetImports.txt
guidmapper
InspectorExpandedItems.asset
MonoManager.asset
ScriptMapper

cache/*
Temp/*
metadata/*
ScriptAssemblies/*
previews/*

The Mercurial in Daily Use guide seems to be a good list of things that you might wish to do

 

Some notes for myself, but might be useful to someone else getting started also.

edit: To start a local serve on my workstation that my laptop can push to, use the command line

hg serve –config web.push_ssl=No –config “web.allow_push=*”

to pass your changes up from the laptop to the workstation:

hg push http://workstationname:8000

and on the workstation use:

hg update

to get the latest updated file revisions locally..

and you’re sync’d. fun times.

 

3 Comments more...

What have you done for me lately?

by on Jun.01, 2011, under Interactive, Interactive, Portfolio, Unity3D

I’ve been working on this tool for a while now, here’s a quick captured demo of some of the features of my hospital room design application in action.

Interactive 3D OR/ICU design tool from Dave Buck on Vimeo.

here’s a current video of my OR/ICU design project, created in unity3d, with fully configurable parametric models rigged with both IK and FK, and a tool to quickly draw out any layout of walls, windows and doors to spatially visualize the placement and reach of equipment needed in an operating room space.

3 Comments more...

Some Useful Unity3D resources

by on Feb.16, 2011, under Unity, Unity3D

Since I’m doing a lot of unity here lately, and starting to lay down some teaching to coworkers, here are a couple useful references for unity3d stuff that aren’t too commonly thrown out there.

http://feedity.com/rss.aspx/unifycommunity-com/UVtQUlVb – RSS feed that updates when new scripts are added to the community WIKI (And feedity in general is pretty nifty.)

http://www.google.com/cse/home?cx=002470491425767499270:iugs1ezlsfq a google custom search engine maintained by some anonymous saint, searches the unity references, answers, forums, and a few other popular blogs.

http://www.google.com/cse/home?cx=001712401338047450041:csfhqk-trfa a second google CSE that includes MSDN and the wiki among others, for when you need that extra bit of microsoft reference.

Also, don’t neglect the boys in irc.freenode.net #unity3d, definitely the single most useful resource @ http://webchat.freenode.net/ or your friendly neighborhood irc client.

*Oops! bolger fail. edit to fix the links.

Leave a Comment : more...

Unity: toying with Scriptable Objects

by on Oct.19, 2010, under Architecture, csharp, Scripting, Unity3D

In architecture there is often a need to keep track of and have handy many different viewpoints of a model at a time. with my early unity experiments, I made the mistake of creating a Camera for every Viewpoint that I wanted to have available in my scene. this was faulty for several reasons, not the least of which was that every ‘Camera’ object in a scene is actually rendering everything in the scene at once. Each camera has a few fun/useful options in the Clear Flags that makes this useful for things like rendering UI overlays with 3d objects and other assorted multipass ideas, but thats a whole ‘nother story.

Next attempt was to just import a large list of dummy objects in from 3dsmax that would represent camera orientations and allow the end user to select from these dummys and align the camera with the dummy objects using some UI bits in unity. This worked fine, but there is the base problem that the user cannot modify/edit these objects easily and have the changes save across play sessions.

This is where Scriptable Objects started to come in to play. (Taken partly from the unity Character Demo where they were explaining some of the joys of AssetBundles if you wish to look up more in depth examples.) this may not be the most useful demo of Scriptable objects, but this is a case study for when you are trying to store Runtime data for use at editortime.

There are several parts: First and probably the only important part is the Holder, this is really just a list of ‘Somethings’ that we save to disk. in our case, CameraLocations.

//CameraLocationHolder.cs
using System.Collections.Generic;
using UnityEngine;
 
public class CameraLocationHolder : ScriptableObject {
    public List<CameraLocation> content;
    public CameraLocationHolder(List<CameraLocation> content)
    {
        this.content = content;
    }
}

the above empty list consists of ‘CameraLocation’s which is just a simple class I used to store a few variables that are needed to re-create a Viewpoint. Camera locations is a Serializable Class (Serializable in this case means that its viewable in the inspector in Unity the same way you would view for instance a Vector3..) and it has some default values in there of pulling the maincameras location/rotation and field of view.

1
2
3
4
5
6
7
8
9
10
11
12
//CameraLocation.cs
using UnityEngine;
using System.Collections;
 
[System.Serializable]
public class CameraLocation
{
    public string name = "New Camera";
    public float fov = Camera.main.fov;
    public Vector3 position = Camera.main.transform.position;
    public Quaternion rotation = Camera.main.transform.rotation;
}

Now, we create an asset in the editor where we will store our list of CameraLocation’s, this can be placed anywhere, its a small file so i tend to just store it in Resources for easy finding later.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//CreateCameraLocationAsset.cs
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
 
public class CreateCameraLocationAsset
{
    [MenuItem("Custom/Cameras/Create camera location holder")]
    public static void CreateMyAsset()
    {
        List<CameraLocation> content = new List<CameraLocation>();
        CameraLocationHolder asset = new CameraLocationHolder(content);  //scriptable object 
        AssetDatabase.CreateAsset(asset, "CameraLocationDatabase");
        AssetDatabase.SaveAssets();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
    }
}

Now you have an ‘Asset’ where you can store/load/erase/whatever in a list of CameraLocations at runtime, and the results will still be available at Editor time, and at future Runs of the application.

For instance, you can browse around your scene as you would normally with your FlyingCameraScriptOfDoom, and occasionally call a script to add your current camera.main viewpoint to the list.

or accessing it as a runtime resource for use by a normal GUI pulldown:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Excerpts from CameraListBox.cs
 
//declaring a list of stuff
            public List<CameraLocation> camList = new List<CameraLocation>(); //Declare our list of stuff
 
//....
 
//somewhere in Start() we load the list from the DB
            Object o = Resources.Load("CameraLocationDatabase", typeof(CameraLocationHolder));
            CameraLocationHolder CameraLocationDB = (CameraLocationHolder)o;
//fill our list of stuff, with the content from the Holder in the asset
            camList = CameraLocationDB.content;
 
//....
 
//and somewhere in our OnGUI()
            GUILayout.BeginVertical(GUILayout.Width(120));
            for (int i = 0; i < camList.Count; i++)
            {
                if (GUILayout.Button(camList[i].name))
                {
                    SelectedListItem = i;//Set the index for our currrently selected item
                    CameraLocation cam = camList[SelectedListItem];
                    StartCoroutine(SmoothMoveCamLoc(cam.position, cam.rotation, cam.fov, duration));
                   }
            }
            GUILayout.EndVertical();
 
//the SmoothMoveCamLoc just lerps between the current positions/rotations/fov's 
//and the desired ones that were stored in the CameraLocation.
//although mine has a few other random logic items in there to decide
//which style of camera i have currently and deal with any parents/targets/initializing/etc
//needed if we move the camera.

For instance, editing the list by an Editor script, that builds a list for you to Add/Remove/Rename/and Re-Order the list, because thats oddly hard to do with the built in object interface? Maybe this is where a custom inspector should be for the .asset type? hmm! things to play with in the future.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//CameraListboxWizard.cs
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
 
public class CameraListboxWizard : ScriptableWizard
{
    public string DBLocation = "Assets/Resources/CameraLocationDatabase.asset";
    private CameraLocation camLocation;
    static private Object dbaseAsset;
    static private CameraLocationHolder db;
 
    [MenuItem("Custom/Cameras/CameraListBox - Database Helper")]
    static void DoSet()
    {
        ScriptableWizard.DisplayWizard("Add view to CameraListBox", typeof(CameraListboxWizard), "DONE");
    }
 
    void OnWizardUpdate()
    {
        helpString = "This will control the Camera Location asset database\n, and allow you to 'save' the Camera.main's position\n while in the player mode\n";
 
        UpdateMyAssetLocation();
    }
 
    void AddExistingCameras()
    {
        int count = Camera.allCameras.Length;
        for (int i = 0; i < count; ++i)
        {
            //except for the main camera, which we'll use to transition between the others
            if (Camera.allCameras[i] != Camera.main)
            {
                camLocation = new CameraLocation();
                camLocation.name = Camera.allCameras[i].name;
                camLocation.fov = Camera.allCameras[i].fov;
                camLocation.position = Camera.allCameras[i].transform.position;
                camLocation.rotation = Camera.allCameras[i].transform.rotation;
                AddCamera(camLocation);
            }
        }
    }
 
    void OnWizardCreate()
    {
        Debug.Log("done");
    }
 
    void AddCamera(CameraLocation cam)
    {
        db.content.Add(cam);
        EditorUtility.SetDirty(dbaseAsset);
    }
 
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();
         EditorGUILayout.BeginHorizontal();
        GUILayout.Label(name, GUILayout.MaxWidth(0));
        DBLocation = EditorGUILayout.TextField(DBLocation);
        if (GUILayout.Button("Browse"))
        {
            DBLocation = EditorUtility.OpenFilePanel(name, DBLocation, "asset");
            UpdateMyAssetLocation();
        }
        EditorGUILayout.EndHorizontal();
 
        if (GUILayout.Button("Update Database Location"))
        {
            UpdateMyAssetLocation();
        }
 
        EditorGUILayout.Space();
        if (GUILayout.Button("Add current Camera.main position", GUILayout.Height(50)))
        {
            camLocation = new CameraLocation();
            AddCamera(camLocation);
        }
        EditorGUILayout.Space();
        DisplayCurrentCamList();
        EditorGUILayout.Space();
 
        if (GUILayout.Button("Add all existing 'Cameras' to the list\n this can 'import' max camera locations", GUILayout.Height(50)))
        {
            AddExistingCameras();
        }
        EditorGUILayout.EndVertical();
    }
 
    void DisplayCurrentCamList()
    {
        for (int i = 0; i < db.content.Count; i++ )
        {
            EditorGUILayout.BeginHorizontal();
            db.content[i].name = GUILayout.TextField(db.content[i].name, GUILayout.Width(200));
            if (GUILayout.Button("UP"))
            {
                if (i > 0)
                {
                    CameraLocation item = db.content[i];
                    db.content.RemoveAt(i);
                    db.content.Insert(i - 1, item);
                }
            }
            if (GUILayout.Button("DN"))
            {
                if (i < db.content.Count)
                {
                    CameraLocation item = db.content[i];
                    db.content.RemoveAt(i);
                    db.content.Insert(i + 1, item);
                }
            }
            if (GUILayout.Button("Remove"))
            {
                db.content.Remove(db.content[i]);
            }
            //db.SetDirty();
            EditorUtility.SetDirty(dbaseAsset);
            EditorGUILayout.EndHorizontal();
        }
    }
 
    public void UpdateMyAssetLocation()
    {
        dbaseAsset = AssetDatabase.LoadAssetAtPath(DBLocation, typeof(CameraLocationHolder));
        CameraLocationHolder CameraLocationDB = (CameraLocationHolder)dbaseAsset;
        db = CameraLocationDB;
    }
    public void CreateMyAsset()
    {
        List<CameraLocation> content = new List<CameraLocation>();
        CameraLocationHolder asset = new CameraLocationHolder(content);  //scriptable object 
        AssetDatabase.CreateAsset(asset, "CameraLocationDatabase");
        AssetDatabase.SaveAssets();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
    }
}
2 Comments more...

Interactive Lab Demo

by on Feb.10, 2010, under Architecture, csharp, Interactive, Unity3D

Here is another Architectural interactive test project. This time, a laboratory setup, a tighter interior space, set up without any real lighting (1 direct light + ambient colors + Ambient Occlusion currently) created with the goal of customizing the unity asset pipeline to be a little more friendly for architectural work.

First, the Project, roughly 6mb, clicking on the screenshot will open the project in a new window. its another quickly evolving work in progress, Warning: No consideration has been taken currently for speed on older hardware, ~100fps on an 8800GT was the target.
Screenshot

Some findings and random ramblings on arch and interactive 3d:

  • unlike with general gaming, with architecture you are in most cases going to already have a model provided in some form or another. odds are, the model is going to be pretty horrific, as arch models tend to be built for the purpose of either:
    • A: Viz… the Viz model will require a lot of cleanup in terms of material work, and stripping down a lot of the high poly fluff required for rendering.
    • B: Design Development… the DD model is normally plagued more by bad modeling conventions, no naming, poor materials, materials not fully assigned, or mangled geometry due to being stretched and squished for days on end to keep up with a design.
  • you will probably still want to break up the file by some logical layer type system, by default this will land you with a unique material for each material of each fbx file
  • a small AssetPostProcessor script that works on the OnMaterialAssign function can make the process of sharing materials across multiple FBX files much easier to handle, with the added bonus of being able to easily progressively build up a library of reusable realtime materials
 
//file: MaterialsPostProcessor.cs
//goal: Share a library of materials across different assets based on the name of material supplied in the FBX file
// Dave Buchhofer - 02.10.2010
 
using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class MaterialsPostProcessor : AssetPostprocessor
{
    Material OnAssignMaterialModel (Material material, Renderer renderer)
    {
        //The path where you keep your "Standard" library of materials
        string StandardMatPath = "Assets/DMGStandardMaterials/" + material.name + ".mat";
 
        //the path where you want to keep your "temp" materials, that weren't found above
        //So you have a logical place to look for materials that need editing and tweaking for realtime work.
        string TemporaryMatPath = "Assets/Mesh/Materials/" + material.name + ".mat";
 
        //Check for it in the standard 
        if (AssetDatabase.LoadAssetAtPath(StandardMatPath, typeof(Material)))
        {
            Debug.Log("FOUND: " + StandardMatPath);
            return (Material)AssetDatabase.LoadAssetAtPath(StandardMatPath, typeof(Material));
        }
        //Else check to see if we've already built one in the temp path
        if (AssetDatabase.LoadAssetAtPath(TemporaryMatPath, typeof(Material)))
        {
            Debug.Log("FOUND temp: " + TemporaryMatPath);
            return (Material)AssetDatabase.LoadAssetAtPath(TemporaryMatPath, typeof(Material));
        }
        //Or create it?
        material.shader = Shader.Find("Diffuse");
        AssetDatabase.CreateAsset(material, TemporaryMatPath);
        Debug.Log("CREATED temp: " + TemporaryMatPath);
        return material;
    }
}

also check out the previous arch experiment a few posts down: Basketball Arena

3 Comments :, , , more...

Architectural Interactive Demo

by on Dec.12, 2009, under Architecture, Interactive, Unity3D

Here’s a current work in progress Interactive Architectural type demo of a college Basketball Arena

it hasn’t been terribly optimized yet, so it requires a fairly hefty video card to play smoothly, that said, it runs at ~150fps on my 8800GT here, but at 5fps on my parents 3 year old dell. So your mileage may vary while I experiment!

http://www.buchhofer.com/upload/files/labs/drexel/ ~5mb

screenshot

Everything has been done with ingame lighting and shaders, nothing is baked, and was meant as a test specifically for that purpose, to see how far it can be pushed before requiring Texture Baking on a fair sized scene. (With the aim to be able to quickly iterate models in earlier phases of design without having to unwrap and bake!)

To the game! There is a quality button on the lower left that toggles between various settings of Anti Aliasing, Shader Quality, Shadow Quality.. so you can tailor it to a point to your hardware.

On the upper left is a selection of preset Camera views, clicking and dragging the mouse button in the viewport anywhere will ‘look’ the camera from the preset view.

On the upper right is some fun stuff, toggles for Ambient occlusion, Bloom shaders (glow) and a couple of sliders to adjust those primary values

there is also an alternate Daylighting scheme, if you do this i suggest toggling the roof, then you can adjust the time of day with the ‘TimeOfDay’ slider, and the ambient lighting with the ambient.

the rest are just toggles to show/hide various layers of objects

3 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...