Vectorized, extruded, and spatialized map data.

Or the GeoJSON, D3.js to Three.js pipeline.

It has been a while since our latest Three.js project! We’re mostly playing with Unity, but it’s always a nice feeling to get back to the web directly.

For this project, we’d to display a 3D map of the France with some sites informations points. The first thought concerned displaying a 3D map, we known we will need some svg at some point but then how to display it using Three.js? Also how could we put the sites/cities on the map correctly? Let see that!

Continue reading Vectorized, extruded, and spatialized map data.

Franc-Tamponnage 2018 goes AR & VR!



Magna Vox is an association located at Dijon organizing concerts in the Burgundy – Franche – Comté region. In 2017 we already participate to the Franc Tamponnage‘s edition, with some applications you can find here. This time we improved one and create two others!

Continue reading Franc-Tamponnage 2018 goes AR & VR!

Franc-Tamponnage and creative coding

During one month, our Bourgogne-Franche-Comté region was in trouble: the music festival, called Franc-Tamponnage, for alternative, electronic and extreme kind was in progress. Our friends at Magna Vox planned dozens of concerts throughout the region.

For a specific set of concerts, we were in charge of creating a nice visual experience for visitors. It was the perfect opportunity for some creative coding! We were 3 coders on this project, Julien experimenting for the first time with openFrameworks, Tamsen playing around with one of his favorite toy: Processing and Aymeric making some good old Flash!

Here’s the recap by each of us :

Continue reading Franc-Tamponnage and creative coding

Run pngquant via a NativeProcess: C#, Unity & AS3/AIR

After our Unity runtime SpriteSheets generator, it is a good idea to optimize the generated pngs files.

pngquant is a command-line utility and a library for lossy compression of PNG images. The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency. In other words this is a must have tool if you’re working with many pngs!

I used many times pngquant directly from the command line, but depending your project, you might need to run it directly inside your application! I didn’t find example for doing this, and it was way harder than I thought due to my lack of knowledge with batch and shell scripts! So here we go:

We use custom batch file (for Windows) and shell script (for Mac OS X) for launching pngquant. It will take the path to pngs to compress and overwrite them.

OS X:

#!/bin/sh
#!/usr/bin/env bash
#$ -N $2

DIR="$( cd "$( dirname "$0" )" && pwd )"

(cd "$DIR" && ./pngquant -f --ext .png "$1"/*.png)

Windows:

cd %~dp0
pngquant -f --ext .png "%~1"/*.png

Now a C# example for calling thoses scripts, note it works fine with Unity too:

System.Diagnostics.Process process = new  System.Diagnostics.Process();

string exec = "";
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
	exec = "pngquant-windows.cmd";
else if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
	exec = "pngquant-osx";
else
	throw new Exception("Platform not supported");

process.StartInfo.FileName = Application.dataPath + "/../../" + exec;
process.StartInfo.Arguments = Application.dataPath + "/../../png-to-compress";

// if your path have blank spaces use:
//process.StartInfo.Arguments = "\"" + Application.dataPath + "/../../png compress\"";

process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;

process.Start();

And finally an example with AS3 for AIR:

var process:NativeProcess = new NativeProcess();

var startupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory;

var exec:String = "";
if (Capabilities.os.indexOf("Windows") >= 0)
	exec = "pngquant-windows.cmd";
else if (Capabilities.os.indexOf("Mac") >= 0)
	exec = "pngquant-osx";
else
	throw new Error("doesn't work on " + Capabilities.os + " operating system");

file.nativePath = file.nativePath + "/../" + exec;
startupInfo.executable = file;

var processArgs:Vector.<String> = new Vector.<String>();
processArgs[0] = File.applicationDirectory.nativePath + "/../png-to-compress";
startupInfo.arguments = processArgs;

process.start(startupInfo);

Be sure to have a look to PngQuantNativeProcess’s git repository to be up to date!

Unity – generate SpriteSheets at runtime!

Unity and plugins provide many great ways to build Sprite Sheets. However they’re used directly into Unity Editor or with an external software which is perfect in many case, but none provide the ability to generate SpriteSheets at runtime. So we made our own library.

The goal of a sprite sheet is to pack as many sub-textures as possible in one big texture. So the first thing to do was a packing algorithm. Fortunately we remembered the one made and open-sourced by Ville Koskela in AS3, so we started with a Unity C# port.
Click here to view the Unity rectangle packing example running in your browser in WebGL!

Once the packing algorithm done, we worked on a cache system so the generated sprite sheets are written and saved on disk for a future loading. The generator process won’t be needed anymore unless you increase your cache version!

Give a try to UnityRuntimeSpriteSheetsGenerator!

Unity – sprite packing

Best practices with Unity have always been an hidden gem. Most precisely concerning the Resources folder. Hopefully things are changing with Unity’s best practices guide! And things are simple concerning the Resources folder: just don’t use it!

Managing 2D Sprites in Unity is simple if you have a static scene: just put every sprite needed on your screen and you’re almost done. Obviously you should package them in Spritesheets. The easy way to do it is via Unity’ Sprite Packer tool. But what to do if you need to load Sprites at runtime? How to access a Sprite if it’s not linked directly on a GameObject or a Prefab and without using the Resources folder?

Create a ScriptableObject! They are the best way to store informations within Unity. Here is an Editor Script for generating ScriptableObjects with a list of Sprites for each Packing Tag mentioned:

using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

[Serializable]
public class SpritesData:ScriptableObject {

	[SerializeField]
	public Sprite[] sprites;

	static public string assetDirPath = "RuntimeSprites/SpritesData/";
	static public string assetPath = "Assets/RuntimeSprites/SpritesData/{0}.asset";

	#if UNITY_EDITOR
	[MenuItem("Data/Create Sprites Data")]
	static void CreateSpritesData() {
		string dirPath = Application.dataPath + "/" +  assetDirPath;

		if (!System.IO.Directory.Exists(dirPath))
			System.IO.Directory.CreateDirectory(@dirPath);

		SpritesData data = ScriptableObject.CreateInstance<SpritesData>();

		List<Sprite> spritesList = new List<Sprite>();

		string[] anims = AssetDatabase.FindAssets("t:Sprite", new string[] {"Assets/Sprites"});

		string currentTag = "";

		foreach (string anim in anims) {

			string path = AssetDatabase.GUIDToAssetPath(anim);

			TextureImporter ti = TextureImporter.GetAtPath(path) as TextureImporter;

			if (ti.spritePackingTag != currentTag) {

				if (data && currentTag != "") {

					data.sprites = spritesList.ToArray();
					AssetDatabase.CreateAsset(data, string.Format(assetPath, currentTag));
				}

				data = ScriptableObject.CreateInstance<SpritesData>();
				spritesList = new List<Sprite>();

				currentTag = ti.spritePackingTag;
			}

			Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(path);

			spritesList.Add(sprite);
		}

		data.sprites = spritesList.ToArray();
		AssetDatabase.CreateAsset(data, string.Format(assetPath, currentTag));
	}
	#endif
}

Now that you have all your SpritesData you just have to create a MonoBehaviour with a public SpritesData[] spritesDatas; property, then you will have access to all your sprites! The good things is while a sprite isn’t displayed on Screen it’s not in memory.

Cheers!

Unity – manage mailbox

For a project, unfortunately canceled, we needed to be able to manage a mailbox with Unity. Including IMAP protocol.

Unity uses C#, so we were pretty confident it wouldn’t be an issue since there are so many .NET libraries around there. But none of them worked fine with Unity: some of them worked in Unity Editor, some were also able to work on Android, but none could pass Unity’s IL2CPP compilation for Xcode & iOS. We searched for solution on Unity’s forums but we find nothing, there was no other choice than testing all the libraries around the web!

EAGetMail was the only one to fail on Xcode due to IL2CPP compilation, all the other libraries failed way before (due to Unity Mono version). So we raised an issue to Unity’s IL2CPP team.

During that time, we needed to be sure the project would be feasible. So we looked for alternative: a PHP solution for IMAP called Fetch combined with an AMF library for Unity. Not really a good replacement, but it worked.

Luckily Unity fixed the issue some weeks later! If you have to manage mailboxes with Unity, be sure to give a try to EAGetMail before banging your head against the wall! 😉

Making a Unity game for the HTC Vive and the Oculus Gear

We currently faced the challenge of making a VR game (under NDA, so we can’t mention the game or even provide screenshots or code) for the HTC Vive (Steam VR) and the Gear VR (OculusSamsung Galaxy). In this post, we will present both headsets, the challenge they represent from a game design point of view, and also some developer feedbacks!
Continue reading Making a Unity game for the HTC Vive and the Oculus Gear

Unity – auto set Android password in project

Hey, it’s time for an other tip today!

There are small details in Unity which can make you crazy: compiling an Android project with the correct certificate request you to provide the password each time you open the project. Ok, that’s not a big deal! But the problem is: if you miss to write it and launch the compilation it will be at the end of the process than you will be informed you didn’t set it up and so it fails. With a 30 minute build time (on a big project), if you miss it, you’ve the right to be angry! Why the hell Unity doesn’t check it before!?

Anyway let’s make a small Editor Script:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class StartUp {

	#if UNITY_EDITOR

	static StartUp() {

		PlayerSettings.keystorePass = "myPwd";
		PlayerSettings.keyaliasPass = "myAliasPwd";
	}

	#endif
}

Thanks to this script, when the project will be opened the password will be registered!

Ok an other thing to figure, the keystore path is saved in your ProjectSettings.asset. So the path need to be changed on each computer. Not a big deal, but it could be done automatically if it’s near your project. On the script above, add:

PlayerSettings.Android.keystoreName = Application.dataPath + "/user.keystore";

The last thing to do would be to reset this path when Unity goes in the background so you can git push/pull without creating conflict. Unfortunately I can’t find a way to detect correctly when Unity goes in background, see http://forum.unity3d.com/threads/trapping-if-unity-editor-is-foreground.271391/. Do you know a way to do it?

Unity – fast build platform switcher script!

Today a quick tip for a huge trick!

Working with Unity is pretty awesome until you have to make a build on an other platform than your current one! Depending your project size (number of assets etc.), just changing your current platform for Android to iOS or vice versa could take one hour… yup seriously! During that time you won’t be able to work on your project and your computer’s CPU will be pretty busy… so time for a long break? Until now!
Continue reading Unity – fast build platform switcher script!