-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added license file. Removed dos carriage returns.
- Loading branch information
1 parent
91ebab7
commit 5c5236a
Showing
5 changed files
with
176 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Shane Celis | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
//$ cite -u https://github.com/shanecelis/water-demo -C -l mit | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class CameraOrbit : MonoBehaviour { | ||
public float rotationRate = 100f; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
if (Input.GetMouseButton(0)) { | ||
transform.Rotate(-Input.GetAxis("Mouse Y") * rotationRate * Time.deltaTime, 0f, 0f, Space.Self); | ||
transform.Rotate(0f, Input.GetAxis("Mouse X") * rotationRate * Time.deltaTime, 0f, Space.World); | ||
} | ||
} | ||
} | ||
//$ cite -u https://github.com/shanecelis/water-demo -C -l mit | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class CameraOrbit : MonoBehaviour { | ||
public float rotationRate = 100f; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
} | ||
|
||
// Update is called once per frame | ||
void Update () { | ||
if (Input.GetMouseButton(0)) { | ||
transform.Rotate(-Input.GetAxis("Mouse Y") * rotationRate * Time.deltaTime, 0f, 0f, Space.Self); | ||
transform.Rotate(0f, Input.GetAxis("Mouse X") * rotationRate * Time.deltaTime, 0f, Space.World); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,92 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using ProceduralToolkit; | ||
using System.Linq; | ||
|
||
public class GeometryBuilder : MonoBehaviour { | ||
|
||
public MeshFilter cubeMeshFilter; | ||
public MeshFilter waterMeshFilter; | ||
public MeshFilter sphereMeshFilter; | ||
|
||
void Start () { | ||
GenerateMeshes(); | ||
} | ||
|
||
[ContextMenu("Generate Meshes")] | ||
void GenerateMeshes() { | ||
// var cube = MeshDraft.Cube(2f, true); | ||
var cube = CubeOpenTop(Vector3.right * 2f, Vector3.forward * 2f, Vector3.up * 2f, true); | ||
// var vs = cube.vertices; | ||
// cube.vertices = vs.Take(2).Concat(vs.Skip(4)).ToList(); | ||
cube.FlipFaces(); | ||
cubeMeshFilter.mesh = cube.ToMesh(); | ||
|
||
var water = MeshDraft.Plane(2f, 2f, 200, 200, true); | ||
water.vertices = water.vertices | ||
.Select(v => v - new Vector3(1f, 0, 1f)) | ||
// Put them into the same orientation as webgl. | ||
.Select(v => new Vector3(v.x, v.z, 0f)) | ||
.ToList(); | ||
waterMeshFilter.mesh = water.ToMesh(); | ||
|
||
// var sphere = MeshDraft.Sphere(0.25f, 10, 10, true); | ||
var sphere = MeshDraft.Sphere(1f, 10, 10, true); | ||
sphereMeshFilter.mesh = sphere.ToMesh(); | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a hexahedron draft | ||
/// </summary> | ||
public static MeshDraft CubeOpenTop(Vector3 width, Vector3 length, Vector3 height, bool generateUV = true) | ||
{ | ||
Vector3 v000 = -width/2 - length/2 - height/2; | ||
Vector3 v001 = v000 + height; | ||
Vector3 v010 = v000 + width; | ||
Vector3 v011 = v000 + width + height; | ||
Vector3 v100 = v000 + length; | ||
Vector3 v101 = v000 + length + height; | ||
Vector3 v110 = v000 + width + length; | ||
Vector3 v111 = v000 + width + length + height; | ||
|
||
var draft = new MeshDraft {name = "Hexahedron"}; | ||
if (generateUV) | ||
{ | ||
Vector2 uv0 = new Vector2(0, 0); | ||
Vector2 uv1 = new Vector2(0, 1); | ||
Vector2 uv2 = new Vector2(1, 1); | ||
Vector2 uv3 = new Vector2(1, 0); | ||
draft.AddQuad(v100, v101, v001, v000, Vector3.left, uv0, uv1, uv2, uv3) | ||
.AddQuad(v010, v011, v111, v110, Vector3.right, uv0, uv1, uv2, uv3) | ||
// .AddQuad(v010, v110, v100, v000, Vector3.down, uv0, uv1, uv2, uv3) | ||
.AddQuad(v111, v011, v001, v101, Vector3.up, uv0, uv1, uv2, uv3) | ||
.AddQuad(v000, v001, v011, v010, Vector3.back, uv0, uv1, uv2, uv3) | ||
.AddQuad(v110, v111, v101, v100, Vector3.forward, uv0, uv1, uv2, uv3); | ||
} | ||
else | ||
{ | ||
draft.AddQuad(v100, v101, v001, v000, Vector3.left) | ||
.AddQuad(v010, v011, v111, v110, Vector3.right) | ||
// .AddQuad(v010, v110, v100, v000, Vector3.down) | ||
.AddQuad(v111, v011, v001, v101, Vector3.up) | ||
.AddQuad(v000, v001, v011, v010, Vector3.back) | ||
.AddQuad(v110, v111, v101, v100, Vector3.forward); | ||
} | ||
return draft; | ||
} | ||
|
||
|
||
|
||
} | ||
//$ cite -u https://github.com/shanecelis/water-demo -C -l mit | ||
|
||
// #define HAS_PROCEDURAL_TOOLKIT | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
#if HAS_PROCEDURAL_TOOLKIT | ||
using ProceduralToolkit; | ||
#endif | ||
using System.Linq; | ||
|
||
/* | ||
This class was used to generate the cube, water plane, and sphere models. | ||
It requires the | ||
[ProceduralToolkit](https://github.com/Syomus/ProceduralToolkit) but shouldn't | ||
be necessary unless you're regenerating the geometry. | ||
If you do regenerate the geometry and want to save them, | ||
[MeshSaver](https://github.com/pharan/Unity-MeshSaver) may come in handy. | ||
*/ | ||
public class GeometryBuilder : MonoBehaviour { | ||
|
||
public MeshFilter cubeMeshFilter; | ||
public MeshFilter waterMeshFilter; | ||
public MeshFilter sphereMeshFilter; | ||
|
||
#if HAS_PROCEDURAL_TOOLKIT | ||
void Start () { | ||
GenerateMeshes(); | ||
} | ||
|
||
[ContextMenu("Generate Meshes")] | ||
void GenerateMeshes() { | ||
// var cube = MeshDraft.Cube(2f, true); | ||
var cube = CubeOpenTop(Vector3.right * 2f, Vector3.forward * 2f, Vector3.up * 2f, true); | ||
// var vs = cube.vertices; | ||
// cube.vertices = vs.Take(2).Concat(vs.Skip(4)).ToList(); | ||
cube.FlipFaces(); | ||
cubeMeshFilter.mesh = cube.ToMesh(); | ||
|
||
var water = MeshDraft.Plane(2f, 2f, 200, 200, true); | ||
water.vertices = water.vertices | ||
.Select(v => v - new Vector3(1f, 0, 1f)) | ||
// Put them into the same orientation as webgl. | ||
.Select(v => new Vector3(v.x, v.z, 0f)) | ||
.ToList(); | ||
waterMeshFilter.mesh = water.ToMesh(); | ||
|
||
// var sphere = MeshDraft.Sphere(0.25f, 10, 10, true); | ||
var sphere = MeshDraft.Sphere(1f, 10, 10, true); | ||
sphereMeshFilter.mesh = sphere.ToMesh(); | ||
} | ||
|
||
public static MeshDraft CubeOpenTop(Vector3 width, Vector3 length, Vector3 height, bool generateUV = true) { | ||
Vector3 v000 = -width/2 - length/2 - height/2; | ||
Vector3 v001 = v000 + height; | ||
Vector3 v010 = v000 + width; | ||
Vector3 v011 = v000 + width + height; | ||
Vector3 v100 = v000 + length; | ||
Vector3 v101 = v000 + length + height; | ||
Vector3 v110 = v000 + width + length; | ||
Vector3 v111 = v000 + width + length + height; | ||
|
||
var draft = new MeshDraft {name = "Hexahedron"}; | ||
if (generateUV) | ||
{ | ||
Vector2 uv0 = new Vector2(0, 0); | ||
Vector2 uv1 = new Vector2(0, 1); | ||
Vector2 uv2 = new Vector2(1, 1); | ||
Vector2 uv3 = new Vector2(1, 0); | ||
draft.AddQuad(v100, v101, v001, v000, Vector3.left, uv0, uv1, uv2, uv3) | ||
.AddQuad(v010, v011, v111, v110, Vector3.right, uv0, uv1, uv2, uv3) | ||
// .AddQuad(v010, v110, v100, v000, Vector3.down, uv0, uv1, uv2, uv3) | ||
.AddQuad(v111, v011, v001, v101, Vector3.up, uv0, uv1, uv2, uv3) | ||
.AddQuad(v000, v001, v011, v010, Vector3.back, uv0, uv1, uv2, uv3) | ||
.AddQuad(v110, v111, v101, v100, Vector3.forward, uv0, uv1, uv2, uv3); | ||
} | ||
else | ||
{ | ||
draft.AddQuad(v100, v101, v001, v000, Vector3.left) | ||
.AddQuad(v010, v011, v111, v110, Vector3.right) | ||
// .AddQuad(v010, v110, v100, v000, Vector3.down) | ||
.AddQuad(v111, v011, v001, v101, Vector3.up) | ||
.AddQuad(v000, v001, v011, v010, Vector3.back) | ||
.AddQuad(v110, v111, v101, v100, Vector3.forward); | ||
} | ||
return draft; | ||
} | ||
#endif | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
//$ cite -u https://github.com/shanecelis/water-demo -C -l mit | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
[ExecuteInEditMode] | ||
public class MaterialUpdater : MonoBehaviour { | ||
|
||
public Material[] materials; | ||
public Transform sphere; | ||
public Transform light; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
|
||
} | ||
|
||
void OnEnable() { | ||
Camera.onPreRender += UpdateMaterials; | ||
} | ||
|
||
void OnDisable() { | ||
Camera.onPreRender -= UpdateMaterials; | ||
} | ||
|
||
void UpdateMaterials(Camera camera) { | ||
for (int i = 0; i < materials.Length; i++) { | ||
materials[i].SetVector("sphereCenter", sphere.position); | ||
materials[i].SetVector("light", -light.forward); | ||
// materials[i].SetVector("light", light.position); | ||
materials[i].SetVector("eye", camera.transform.position); | ||
} | ||
} | ||
} | ||
//$ cite -u https://github.com/shanecelis/water-demo -C -l mit | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
[ExecuteInEditMode] | ||
public class MaterialUpdater : MonoBehaviour { | ||
|
||
public Material[] materials; | ||
public Transform sphere; | ||
public Transform light; | ||
|
||
// Use this for initialization | ||
void Start () { | ||
|
||
} | ||
|
||
void OnEnable() { | ||
Camera.onPreRender += UpdateMaterials; | ||
} | ||
|
||
void OnDisable() { | ||
Camera.onPreRender -= UpdateMaterials; | ||
} | ||
|
||
void UpdateMaterials(Camera camera) { | ||
for (int i = 0; i < materials.Length; i++) { | ||
materials[i].SetVector("sphereCenter", sphere.position); | ||
materials[i].SetVector("light", -light.forward); | ||
// materials[i].SetVector("light", light.position); | ||
materials[i].SetVector("eye", camera.transform.position); | ||
} | ||
} | ||
} |