forked from Chippington/Quixel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuixelEngine.cs
99 lines (88 loc) · 2.84 KB
/
QuixelEngine.cs
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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System;
using System.IO;
namespace Quixel
{
public static class QuixelEngine
{
public static Material[] materials;
private static GameObject cameraObj;
private static bool active = true;
/// <summary>
/// Initializes the Quixel Engine
/// </summary>
/// <param name="mats">Array of materials.</param>
/// <param name="terrainObj">Parent terrain object. (empty)</param>
/// <param name="worldName">Name of the world. Used for paging. (empty)</param>
public static void init(Material[] mats, GameObject terrainObj, string worldName)
{
MeshFactory.terrainObj = terrainObj;
materials = mats;
Debug.Log("Materials: " + mats.Length);
DensityPool.init();
MeshFactory.start();
NodeManager.init(worldName);
}
/// <summary>
/// Sets the width/length/height of the smallest LOD voxel.
/// The width of a single voxel will be 2^(size + LOD)
/// </summary>
/// <param name="size">The size (units).</param>
public static void setVoxelSize(int size, int maxLOD)
{
NodeManager.maxLOD = maxLOD;
NodeManager.nodeCount = new int[maxLOD+1];
NodeManager.LODSize = new int[maxLOD+1];
for (int i = 0; i <= maxLOD; i++)
{
NodeManager.LODSize[i] = (int)Mathf.Pow(2, i + size);
}
}
/// <summary>
/// Sets the terrain generator to use when generating terrain.
/// </summary>
public static void setTerrainGenerator(IGenerator gen)
{
MeshFactory.terrainGenerator = gen;
}
/// <summary>
/// Updates the Quixel system. Should be called every step.
/// </summary>
public static void update()
{
DensityPool.update();
MeshFactory.update();
if (cameraObj != null)
NodeManager.setViewPosition(cameraObj.transform.position);
if (!Application.isPlaying)
active = false;
}
/// <summary>
/// Sets the object to follow for the LOD system.
/// </summary>
/// <param name="obj"></param>
public static void setCameraObj(GameObject obj)
{
cameraObj = obj;
}
/// <summary>
/// Returns true if the player is still active.
/// </summary>
/// <returns></returns>
public static bool isActive()
{
return active;
}
/// <summary>
/// Terminates the engine.
/// </summary>
/// <returns></returns>
public static void terminate()
{
active = false;
}
}
}