Skip to content

Commit 1f5e4a6

Browse files
authored
Merge pull request #1 from zigurous/release/0.4.0
Release/0.4.0
2 parents e1caa2f + 71a3e72 commit 1f5e4a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1202
-665
lines changed

.github/FUNDING.yml

-2
This file was deleted.

.github/workflows/docs.yml

-61
This file was deleted.

.github/workflows/generate-docs.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Generate Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
generate:
15+
name: Docs
16+
uses: zigurous/docs/.github/workflows/unity-package.yml@main
17+
with:
18+
package_title: "Graphics Utils"
19+
package_base_path: com.zigurous.graphics
20+
package_workflow: generate-docs.yml
21+
package_artifact: docs
22+
secrets:
23+
token: ${{ secrets.DOCS_TOKEN }}

.gitmodules

-4
This file was deleted.

CHANGELOG.md

+29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.0] - 2023/06/19
9+
10+
### Added
11+
12+
- New `MeshGenerator` static class to generate procedural meshes
13+
- New `Triangulator` static class to split polygons into triangles
14+
- New `HiddenMaterialPropertyDrawer` attribute to hide material properties
15+
- New `Mesh.RecalculateUV` extension method
16+
- New texture extension methods
17+
- `GetPixelCoordinates`
18+
- `GetUVCoordinates`
19+
- `Sample(u, v)`
20+
- `Sample(rect, point)`
21+
- `Sample(bounds, position)`
22+
- `SetColor`
23+
- Context menu added to `SaveMesh` to save directly from the editor
24+
- Help URLs added to all behaviors
25+
26+
### Changed
27+
28+
- Refactored `TextureDrawer` as a ScriptableObject and a separate `TextureDrawerRenderer` behavior
29+
- Improved `CombineChildrenMeshes` with better transform matrix, option to set mesh name, and toggle to destroy or disable child game objects
30+
- Renamed `AutoTile.Submesh` to `AutoTile.SubmeshTiling`
31+
- Formatting changes
32+
33+
### Removed
34+
35+
- `ShaderProperty` and `AnimatedShaderProperty` (moved to AnimationLibrary package)
36+
837
## [0.3.0] - 2021/11/14
938

1039
### Added
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
slug: "/manual/custom-meshes"
3+
---
4+
5+
# Custom Meshes
6+
7+
The **Graphics Utils** package includes a few custom cube meshes.
8+
9+
- `Cube-3.mesh`: cube mesh with 3 submeshes (one for each axis)
10+
- `Cube-6.mesh`: cube mesh with 6 submeshes (one for each face)
11+
- `Cube-Inverted.mesh`: cube mesh with inverted normals and triangles (inside-out)
12+
- `Cube-Tiling.mesh` cube mesh designed specifically for [Material Tiling](/manual/material-tiling)
13+
14+
There are also 3 different scripts to generate these cube meshes at runtime:
15+
16+
- [CubeMesh](/api/Zigurous.Graphics/CubeMesh)
17+
- [CubeMesh3](/api/Zigurous.Graphics/CubeMesh3)
18+
- [CubeMesh6](/api/Zigurous.Graphics/CubeMesh6)
19+
20+
<hr/>
21+
22+
## ⭕ Inverting Meshes
23+
24+
Sometimes it is useful to invert a mesh so it renders inside out. This is especially useful for cubes. Inverting a mesh flips the triangles and the normals. The **Graphics Utils** package comes with an [InvertMesh](/api/Zigurous.Graphics/InvertMesh) script that handles this automatically.
25+
26+
You can also manually invert the normals and triangles of a mesh using extension methods:
27+
28+
```csharp
29+
mesh.InvertNormals();
30+
mesh.InvertTriangles();
31+
32+
// Returns the inverted values without changing the actual mesh
33+
Vector3[] normals = mesh.InvertedNormals();
34+
int[] triangles = mesh.InvertedTriangles();
35+
```
36+
37+
<hr/>
38+
39+
## 🔰 Combining Meshes
40+
41+
The **Graphics Utils** package includes a script to combine multiple meshes into a single mesh. This can be used to improve rendering performance, or as a way to create custom meshes and turn them into assets. Add the [CombineChildrenMeshes](/api/Zigurous.Graphics/CombineChildrenMeshes) script to the parent game object of children meshes. The combined mesh will be assigned to the mesh filter of the parent object, and the child game objects will either be destroyed or disabled.
42+
43+
You can also manually combine meshes through an extension method:
44+
45+
```csharp
46+
MeshFilter[] filters = GetComponentsInChildren<MeshFilter>();
47+
Mesh combinedMesh = filters.CombineMesh();
48+
```
49+
50+
<hr/>
51+
52+
## 💾 Saving Meshes
53+
54+
Often when generating meshes at runtime, you may want to save that mesh as an asset for future use so you don't need to regenerate them again. The **Graphics Utils** package comes with a [SaveMesh](/api/Zigurous.Graphics/SaveMesh) script that will save a mesh as an asset at runtime.
55+
56+
You can also manually save a mesh through extension methods:
57+
58+
```csharp
59+
mesh.Save("Custom");
60+
meshFilter.SaveMesh("Custom");
61+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
slug: "/manual/extension-methods"
3+
---
4+
5+
# Extension Methods
6+
7+
The **Graphics Utils** package contains dozens of extension methods to provide enhanced support for common Unity classes. See each Scripting API for more information:
8+
9+
#### [Material](/api/Zigurous.Architecture/MaterialExtensions)
10+
11+
#### [Mesh](/api/Zigurous.Architecture/MeshExtensions)
12+
13+
#### [MeshFilter](/api/Zigurous.Architecture/MeshFilterExtensions)
14+
15+
#### [Texture](/api/Zigurous.Architecture/TextureExtensions)

Documentation~/articles/index.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
slug: "/manual"
3+
---
4+
5+
# Graphics Utils
6+
7+
The **Graphics Utils** package provides scripts and utilities for graphics and rendering purposes in Unity projects. The package is still early in development, and more functionality will be added over time. Let us know what other features you would like to see.
8+
9+
<hr/>
10+
11+
## Overview
12+
13+
#### ⚙️ [Installation](/installation)
14+
15+
#### 🧰 [Scripting API](/api/Zigurous.Graphics)
16+
17+
#### 📋 [Changelog](/changelog)
18+
19+
#### ⚖️ [License](/license)
20+
21+
<hr/>
22+
23+
## Reference
24+
25+
#### 🔰 [Custom Meshes](/manual/custom-meshes)
26+
27+
#### ⛰️ [Procedural Generation](/manual/procedural-generation)
28+
29+
#### 🛤️ [Material Tiling](/manual/material-tiling)
30+
31+
#### 🖼️ [Texture Drawers](/manual/texture-drawers)
32+
33+
#### 🔌 [Extension Methods](/manual/extension-methods)
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
slug: "/installation"
3+
---
4+
5+
# Installation
6+
7+
Use the Unity [Package Manager](https://docs.unity3d.com/Manual/upm-ui.html) to install the **Graphics Utils** package.
8+
9+
1. Open the Package Manager in `Window > Package Manager`
10+
2. Click the add (`+`) button in the status bar
11+
3. Select `Add package from git URL` from the add menu
12+
4. Enter the following Git URL in the text box and click Add:
13+
14+
```http
15+
https://github.com/zigurous/unity-graphics-utils.git
16+
```
17+
18+
<hr/>
19+
20+
## 🏷️ Namespace
21+
22+
Import the package namespace in each script or file you want to use it. You may need to regenerate project files/assemblies first.
23+
24+
```csharp
25+
using Zigurous.Graphics;
26+
```
27+
28+
<hr/>
29+
30+
## 💻 Source Code
31+
32+
The source code for the **Graphics Utils** package is in the following repository:
33+
34+
- https://github.com/zigurous/unity-graphics-utils
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
slug: "/manual/material-tiling"
3+
---
4+
5+
# Material Tiling
6+
7+
One of the most powerful features included in the **Graphics Utils** package is the ability to auto tile materials based on the object's scale. In doing so, new materials are created that are unique to the object. This makes the workflow of creating materials for tiled objects effortless. Without this feature, you often end up creating dozens of variants of a material just to change the tiling values for different objects.
8+
9+
Add the [AutoTile](/api/Zigurous.Graphics/AutoTile) script to the object you want to tile. The main property that is usually edited is `submeshes`. Each element in the array indicates how a submesh of the mesh is tiled, such as which axis the object is tiled on, the unit scale of the object, the texture offset, etc. For example, a plane is usually tiled around the Y+ axis, has a unit scale of 10, and only 1 submesh.
10+
11+
<hr/>
12+
13+
## 🕋 Cube Tiling
14+
15+
When tiling cubes, the [AutoTile](/api/Zigurous.Graphics/AutoTile) script gives the best results when used with the `Cube-Tiling.mesh` asset instead of Unity's default cube mesh. This mesh asset is split into 3 separate submeshes so you can tile each axis independently from the others. The mesh also has custom UV coordinates so the materials are tiled from the center of each axis. Using the custom tiling mesh, the script should be set up with 3 submeshes tiled around the X+, Y+, and Z+ axis, respectively, and the unit scale set to 1.
16+
17+
<img src="../images/tiling.jpg" width="360px"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
slug: "/manual/procedural-generation"
3+
---
4+
5+
# Procedural Generation
6+
7+
The **Graphics Utils** package provides a utility class to generate procedural meshes at runtime. For example, use the [MeshGenerator](/api/Zigurous.Graphics/MeshGenerator) class to create a new procedural mesh that forms a grid of points.
8+
9+
```csharp
10+
Mesh mesh = MeshGenerator.Create(64, 64);
11+
```
12+
13+
This is a useful starting point to create more complex meshes, such as procedural terrain. The [MeshGenerator](/api/Zigurous.Graphics/MeshGenerator) class allows you to provide your own custom vertex generation function to create these more complex meshes.
14+
15+
```csharp
16+
void GenerateTerrain()
17+
{
18+
Mesh terrain = MeshGenerator.Create(64, 64, VertexGenerator);
19+
}
20+
21+
void VertexGenerator(int x, int y, float u, float v)
22+
{
23+
// sample terrain height using a noise function
24+
float height = Mathf.PerlinNoise(x, y);
25+
return new Vector3(x, height, y);
26+
}
27+
```
28+
29+
<hr/>
30+
31+
## 💎 Triangulation
32+
33+
Sometimes it is useful to split a polygon into triangles in order to generate a custom mesh for the polygon. The [Triangulator](/api/Zigurous.Graphics/Triangulator) class provides this utility. Pass in the points that form the polygon, and the indices of the triangles will be returned.
34+
35+
```csharp
36+
Vector2[] polygon; // array of points that form a polygon
37+
int[] triangles = Triangulator.Triangulate(polygon);
38+
```
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
slug: "/manual/texture-drawers"
3+
---
4+
5+
# Texture Drawers
6+
7+
The **Graphics Utils** package includes a base class for drawing textures at runtime. It provides the boilerplate code for creating and drawing new textures programmatically.
8+
9+
Create a new class that inherits from [TextureDrawer](/api/Zigurous.Graphics/TextureDrawer) and override the function `SetPixels(Texture2D)` to complete the implementation.
10+
11+
Since [TextureDrawer](/api/Zigurous.Graphics/TextureDrawer) is a ScriptableObject, you'll want to add the `[CreateAssetMenu]` attribute to your class so you can save an instance of the class as an asset in your project using Unity's asset menu.
12+
13+
```csharp
14+
[CreateAssetMenu]
15+
public class CustomTextureDrawer : TextureDrawer
16+
{
17+
public override void SetPixels(Texture2D texture)
18+
{
19+
// Handle setting the pixel colors here...
20+
}
21+
}
22+
```
23+
24+
<hr/>
25+
26+
## 🖼️ Rendering
27+
28+
The **Graphics Utils** package comes with a script to quickly render the result of a [TextureDrawer](/api/Zigurous.Graphics/TextureDrawer). This is an optional, but useful script to preview the texture without having to write any other code to manually assign the texture to a material.
29+
30+
Add the [TextureDrawerRenderer](/api/Zigurous.Graphics/TextureDrawerRenderer) script to any game object that contains any type of Renderer component. Assign the texture drawer you want to use and customize any other options you'd like. You can even render the texture in the editor without having to run the game.
31+
32+
<hr/>
33+
34+
## 🏁 Checkerboard
35+
36+
The **Graphics Utils** package includes a script [CheckerboardTextureDrawer](/api/Zigurous.Graphics/CheckerboardTextureDrawer) as a sample implementation. It is, of course, a fully functional script that draws a checkerboard pattern. This can be used however you desire, and there are even a number of customization options available.
37+
38+
To create a new checkerboard pattern texture, use the asset menu `Create > Zigurous > Graphics > Checkerboard Texture Drawer`.

Documentation~/data/header.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"name": "Manual",
4+
"path": "/manual"
5+
},
6+
{
7+
"name": "Scripting API",
8+
"path": "/api"
9+
},
10+
{
11+
"name": "Changelog",
12+
"path": "/changelog"
13+
},
14+
{
15+
"name": "License",
16+
"path": "/license"
17+
}
18+
]

0 commit comments

Comments
 (0)