• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    C#
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PointCloudExporter

(This ReadMe was made from a tutorial I've written for Sketchfab.)

Hi! My name is Leon Denise, I’m an independant artist programmer.
I draw comics, make games, code shaders, hug trees and talk to cows.
You can visit my portfolio: leon196.github.io
And my gif gallery: giphy.com/leondenise

In this tutorial, I’m going to explain how I did the Simon Splash.

The point cloud data was made with Agisoft Photoscan.
The mesh was generated with Unity3D.

About the project

The project is a point cloud tool used for generative art. It is a real-time software that generates triangle particles from a point cloud and displace them in a vector field with specific rules for velocity behavior. The tool also export the generated particles into a standard 3d mesh and bake the vertex colors into a map with generated texture coordinates.

The motivation

The motivation came from the fact that point cloud viewers are not very advanced, since point clouds are not the real matter of 3d worlds such as video games. When you zoom in, points stay as dots, it creates to me a frustration that needs to be satisfied.

So I’ve coded a program that generate triangles from the dots, taking position, normal and color. I’m sharing the source code of the program, it’s a simplified version (no GPU particles) of my point cloud engine. For the sake of comprehension and because the advanced version is part of a commercial project.

How to

Export a point cloud

After you have generated a point cloud in your favourite software, export it as PLY format: binary encoding with position, normal and color.

Exemples with Agisoft Photoscan and MeshLab:

My PLY importer C# script is pretty naive and there is chances that it won’t work with a PLY exported from a different software. If you improve the importer script, and like to share, do not hesitate to send a pull request on the git repository.

Start the Unity3D project

Download, install Unity3D and grab the project at: github.com/leon196/PointCloudExporter
If you don’t know how to use git, find the download zip button:

You will find the scripts and shaders used to generate triangle mesh from a point cloud.

If you don’t know about Unity3D, the official documentation is great and there is plenty tutorial resources over the web. To use the tool, open the scene “PointCloudExporter”. Start the play button, select the PointCloud game object in the hierarchy window, so you can adjust parameters in the inspector window.

The main script is PointCloudGenerator.

Change parameters

Load parameters

PointCloudGenerator will load a file in the StreamingAssets folder and automatically adds the .ply extension.
That’s why File Name is just “Simon2”.
You can adjust the Maximum Vertices count to get more details.

Renderer parameters

Size is the radius of the triangle.
Sprite allows you to choose a texture for the triangle.

About the sprite

The texture used for the sprite must have clamp wrap mode and disabling mipmapping give better results. Since we use triangles instead of quads for performance, the UV mapping is sized to cover the triangle.

On the left, sprite with clamp wrap mode. On the right, sprite with repeat wrap mode.

About the shader

You can check the Shader code used to generate triangles. (warning: geometry shader stuff)

If you inspect the “Generate” function in the PointCloudGenerator script, there is a part where it creates mesh with point topology. So the script create a mesh with no triangles, only points. Then a geometry shader is generating triangle from point.

If you change the shader for “Unlit/Color” for example, you will get this render: points.

With the PointCloud shader, you will get this render: triangles with color and direction.

Here is a scary screenshot with hieroglyph characters known as shader language code. That part shows a function that create a triangle from a point: a geometry shader.

The challenge is to display triangles that will face a certain direction. Manipulating vertex in a shader is about parallelism and knowing if a point in space belong to a triangle requires storing data into vertices. I’m using geometry shader mainly because you can not setup custom attributes for vertices in Unity3D. (There are tricks, but let’s keep it simple for this tutorial)

Displace parameters

Should is the ratio that selects which particles should be displaced.
Time is the duration of the displacement.
Speed is the velocity unit.
Noise Scale is the level of details of the Perlin noise.
Noise Speed is the coefficient of the noise offset.
Target Speed is the coefficient of the target offset.
Noisy is like salt, it adds a grain to coefficients.

The displacement behaviour can be found in the “Displace” function. This simple version is about two vectors: a smooth random direction and moving away from a point in space. This is where you can adjust and customize the displacement behaviour.

Baking parameters

Details is a sort of level of details for color.
Circle Radius is the size of the color on the map.
Shader Baked is the shader to use when triangle mesh is generated.

A baked map with 4 as details.

A baked map with 16 as details.

Because you can’t always have custom shader, you can’t set the triangle color from the vertices color attribute. That’s why this tool have a baking map colors, so the mesh can be imported on Sketchfab or any 3d viewer. If you inspect the baked mesh, you will find the generated texture coordinates.

Action buttons

Generate is triggered when pressing start button, and can be used to reload point cloud.
Reset will move the vertices to their original positions.
Displace will start a displacement sequence, with the chosen parameters.
Export will create a mesh ready to be exported. (it does not create a file on the disk)
Save Baked Colors will open a save dialog window, asking where you write the texture file.

To export the model, you have to press the export button. It will create a triangle topology mesh that will replace the point topology mesh. Then you can use the script ExportOBJ from the UnifyCommunity, that is already in the project. It works like this: select any game object, click through File / Export / Wavefron OBJ.

If everything worked out, you should be able to import it in you favourite 3D software, and then share it on Sketchfab!

Voilà !

I hope it will work at the first try for your point cloud data. It’s an open source work in progress project, so there is unstable code, optimizable algorithm and performance issues.
Also after an export, you will have to generate again a point topology mesh, to be able to displace again. There is a lot of things that could be improved.

Thanks for reading through this whole article. You can find more open source resources and personnal projects on my little compilation repository: github.com/leon196/Workshop
Also I’m spamming gifs on Twitter: twitter.com/leondenise

More Repositories

1

CurveModifier

Implementation of the curve modifier from Blender to Unity3D
C#
358
star
2

ShaderGum

Unity3D GPU Sculpt & Morph
C#
143
star
3

SIGExam

Correction of a Shader Exam
ShaderLab
106
star
4

Workshop

GLSL
64
star
5

OpticalFlowExample

Processing
41
star
6

CookieEngine

WebGL Demotool
JavaScript
29
star
7

CoursGlitchArt

C#
19
star
8

DragAndGlitch

JavaScript
16
star
9

GLASSSchool

Unity3D shader workshop for GLASS summer school
C#
15
star
10

Voxel

WebGL
JavaScript
14
star
11

GPU

JavaScript
13
star
12

TimeDisplacement

Time Displacement effect with Unity3D
JavaScript
9
star
13

godot-particles

GPU particles example in Godot engine
8
star
14

NaturallyUndead

First demo made with love for Evoke 2016
JavaScript
8
star
15

Hatch

WebGL demo for Revision 2019
JavaScript
7
star
16

CoursSIG2017

Class Resources
HLSL
5
star
17

DingDong

C#
4
star
18

WJ

Tool for VJing in WebGL
C#
4
star
19

Choupichoup

JavaScript
3
star
20

TalkingHeads

Game for Ludum Dare 31
JavaScript
3
star
21

RaymarchingSketches

Raymarching shader sketches in GLSL
GLSL
3
star
22

UnityVJ

GLSL
3
star
23

WinterJamBisous

C#
3
star
24

LightPath

C#
3
star
25

leon196.github.io

My website
HTML
2
star
26

Revision-2020-WebGL

2
star
27

Smoothie

4k demo for Evoke 2018
JavaScript
2
star
28

TouchDesignerSketches

2
star
29

Shapeshift

JavaScript
2
star
30

CellularAutomatown

Project for the game jam bio and the city : https://itch.io/jam/biodesign-and-the-city
GLSL
2
star
31

RaymarchingUnityBase

HLSL
2
star
32

CookiePartyInvitro

2
star
33

ThreeSeconds

A game inspired by the comic from Marc Antoine Matthieu
GLSL
2
star
34

TheSaltPlease

JavaScript
2
star
35

WorkshopSIG

WorkshopSIG
ShaderLab
2
star
36

MystJamGame

Game for Myst Jam (http://itch.io/jam/myst-jam)
C#
1
star
37

MeliMelo

JavaScript
1
star
38

demo-regl

JavaScript
1
star
39

Mortel

WebGL demo
JavaScript
1
star
40

Geometry

JavaScript
1
star
41

PuzzleProtein

A game
JavaScript
1
star
42

GIFJamMapping

C#
1
star
43

workshop-esgi-2020-06-30

C#
1
star
44

Parmesan

4k demo for Revision 2019
JavaScript
1
star
45

workshop-esgi-2020-03-24

ShaderLab
1
star
46

ZooMachines2016

C#
1
star
47

OhoShaders

C
1
star
48

WebGLWorkshop

JavaScript
1
star
49

workshop-esgi-2020-05-25

C#
1
star
50

Boupiboup

Boupiboup
C#
1
star