Skip to content

Commit

Permalink
Import/export improvements (#573)
Browse files Browse the repository at this point in the history
* Export an additional GLB file using UnityGLTF (default settings for now)

* scripting define to stop the gltf importers clashing

* Remove editor-only property ref

* Experimental Export Config replaced

* Updated Export

* Set minimal defaults

* Remove LATK compiler flag as we're using UserConfig now. Formatting.

* Remove another check for the latk flag

* Cleanups for the new glb export logic. Make a separate directory.

* Small refactor. Formatting

* Small refactor and simplification. Mainly cosmetic

* dotnet-format and other cosmetic changes

* More formatting changes. Latk doesn't need to be in platform config

* Fix reading defaults from open brush config file

* Convert node names to use brush DurableName instead of guid

* Fix post-merge issues

* Update packages-lock.json

* Update UnityGLTF version

* WIP Export plugin

* Fix NRE. Cleanup unused code.

* dotnet-format

* fix extension usage

* Naming and dotnet-format

* Consistent case for metadata keys

* Refactor batch to stroke logic. Initial WIP version of brush mesh baking

* Catch a couple of NREs when exporting allbrushes.tilt

* Enable animations and blend shape export in UnityGltf

* dotnet-format

* Initial support for selecting parts of an imported model

* Import SVG as 3d model

* Normalize slashes for loaded models

* Fix issue where sketchbook panel appears when loading a sketch from the API

* Catch an occasional NRE

* Refactor the model subtree so it lives on ModelWidget instead of Model

* Fix an NRE

* Slightly better logic for extracting subtrees

* Fix undo

* Fix bounding box for broken apart models

* Correctly Configure single and double sided materials

* Update packages-lock.json

* Fix cloning and ungrouping for broken apart models. Initial work on SVG support

* dotnet format

* Subtree bug fixes. Update vector graphics package version

* Fix the case where a node is both a mesh and a parent to other meshes

* dotnet format

* Remove unused imports

* Fix broken webimport api endpoint

* Allow config switch to use UnityGLTF instead of GLTFast for import

* Update UnityGltf

* Code cleanup

* Editor script and converted maps

* Revert "Update UnityGltf"

This reverts commit a2a57b3.

* Update UnityGltf (without including extraneous changes this time)

* Update GLTFast

* Disable lights when in the panel

* Fix light range and intensity. Fix incorrect bool check. Code cleanup

* Why not generate material collector here?

* Light Gizmos

* Rewrite "break apart model" logic to be less brittle and confusing

* Remove debug logs and factor out a local function that didn't do much

* Dots and Double Tapered X added

  * Brush Baker Prefab: added the compute shaders on the list

  * BrushBaker.cs: UV1 input added

  * bakeDots.compute: first particle sample for Dots

  * bakeDoubleTaperedX.compute: work for both TaperedMarker and TaperedFlat

* Take light gizmo bounds into account

* Revert "Editor script and converted maps"

This reverts commit 2ff35d3.

* Fix normal map format

* Log error when we fall back to legacy importer

* Handle the fact UnityGLTF shaders dont't set a main color.

* [CI BUILD]

* Handle missing compute shaders

* Fix light range

* I goofed when refactoring this previously.

* This seems to mostly fix issues with the material collector.

* Fix importing via API

* Slightly more robust main color detector

* [CI BUILD]

* Initial implementation of LightWidgets (WIP)

* Finish all particles compute shaders
- BrushBaker.cs: vertex color attribute added
- Brush Baker Prefab: added the compute shaders on the list

Computer Shader Added:
- Bubbles
- Embers
- Rising Bubbles
- Smoke
- Snow
- Stars

* Finish all needed compute shader

Brush Baker:
- added World to Local Matrix
- uv1 is a Vector4 now

added compute shaders:
- Disco
- Electricity
- HyperGrid
- LightWire

added X compute shaders:
- BubbleWand
- DanceFloor
- Keijiro Tube
- Rain
- Sparks
- Waveform Particles

* Fix KeijiroTube's Bug

KeijiroTube is a little bit different.
_Time.z is used to create a building effect on the mesh
so I have set the time to be 1.0 so the mesh is build finished

In the future, this brush have to interpolate from 0 to 1
in order to rebuild the building effect

* This texture was a pallettized image

* Fix a NRE

* bounds calc should include inactive lights

* Fix for when the Unity project has spaces in the path

* Handle a few edge cases with editor texture export for toolkit

* Improved handling of imported lights

* Encapsulate HighlightMeshXfs and ensure mesh filters are kept in sync

* The rest of the scaffolding needed for light save/load

* Fleshing out LightWidget some more

* [CI BUILD]

* Add some missing API methods plus a small fix/refactor

* Fix grabbing of broken apart models

* UnityGLTF light import intensity tweak

* Keep pylint happy

* Update GLTFast to latest and add optional dependencies

* dotnet-format

* Fix bad auto-merge

* I'm awake this time

* Update UnityGltf to latest (2.11.0-rc)

---------

Co-authored-by: Benji <[email protected]>
Co-authored-by: Nicholas Liang <[email protected]>
  • Loading branch information
3 people authored May 2, 2024
1 parent 9742358 commit 33c86d6
Show file tree
Hide file tree
Showing 216 changed files with 6,732 additions and 772 deletions.
94 changes: 94 additions & 0 deletions Assets/Editor/ConvertNormalMaps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using Unity.Collections;

public static class ConvertNormalMaps
{
[MenuItem("Open Brush/Toolkit/Convert Bump Maps to Normal Maps")]
static void Convert()
{
foreach (Object obj in Selection.objects)
{
if (obj is Material)
{
Material material = (Material)obj;
Shader shader = material.shader;
int propertiesCount = ShaderUtil.GetPropertyCount(shader);

for (int j = 0; j < propertiesCount; j++)
{
if (ShaderUtil.GetPropertyType(shader, j) == ShaderUtil.ShaderPropertyType.TexEnv)
{
string propertyName = ShaderUtil.GetPropertyName(shader, j);
Texture texture = material.GetTexture(propertyName);

if (texture is Texture2D normalMap)
{
string texturePath = AssetDatabase.GetAssetPath(normalMap);
bool isNormal = ReimportTexture(texturePath, true);
if (!isNormal) continue;
Texture2D remappedTexture = new Texture2D(normalMap.width, normalMap.height);

// Get the pixels from the source texture
NativeArray<Color32> pixels = normalMap.GetPixelData<Color32>(0);

for (int i = 0; i < pixels.Length; i++)
{
byte red = pixels[i].a;
byte green = pixels[i].g;
byte blue = 255; // pixels[i].b;
byte alpha = 255; // pixels[i].r;
pixels[i] = new Color32(red, green, blue, alpha);
}
remappedTexture.SetPixels32(pixels.ToArray());

// Apply changes
remappedTexture.Apply();

File.WriteAllBytes(texturePath, remappedTexture.EncodeToPNG());
Debug.Log("Exported Normal Map: " + texturePath);
RemoveConversion(texturePath);
}
else
{
Debug.LogWarning("No normal map found in material: " + material.name);
}
}
}
}
}
AssetDatabase.Refresh();
}

private static bool ReimportTexture(string assetPath, bool isReadable)
{
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (textureImporter != null)
{
if (textureImporter.textureType != TextureImporterType.NormalMap)
{
return false;
}
textureImporter.isReadable = isReadable;
textureImporter.textureCompression = TextureImporterCompression.Uncompressed;
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
}
return true;
}

private static bool RemoveConversion(string assetPath)
{
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
if (textureImporter != null)
{
if (textureImporter.textureType != TextureImporterType.NormalMap)
{
return false;
}
textureImporter.convertToNormalmap = false;
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
}
return true;
}
}
3 changes: 3 additions & 0 deletions Assets/Editor/ConvertNormalMaps.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Editor/GlTF_EditorExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static int RunCommand(string command, params string[] commandArgs)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = new System.Diagnostics.ProcessStartInfo(
command, string.Join(" ", commandArgs));
command, string.Join(" ", commandArgs.Select(arg => $"\"{arg}\"")));
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
Expand Down
103 changes: 103 additions & 0 deletions Assets/Models/SceneLightCone.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Blender 4.0.2
# www.blender.org
o Cone
v 0.000000 1.000000 -2.000000
v 0.195090 0.980785 -2.000000
v 0.382683 0.923880 -2.000000
v 0.555570 0.831470 -2.000000
v 0.707107 0.707107 -2.000000
v 0.831470 0.555570 -2.000000
v 0.923880 0.382683 -2.000000
v 0.980785 0.195090 -2.000000
v 1.000000 0.000000 -2.000000
v 0.980785 -0.195090 -2.000000
v 0.923880 -0.382683 -2.000000
v 0.831470 -0.555570 -2.000000
v 0.707107 -0.707107 -2.000000
v 0.555570 -0.831470 -2.000000
v 0.382683 -0.923879 -2.000000
v 0.195090 -0.980785 -2.000000
v 0.000000 -1.000000 -2.000000
v -0.195090 -0.980785 -2.000000
v -0.382683 -0.923879 -2.000000
v -0.555570 -0.831470 -2.000000
v -0.707107 -0.707107 -2.000000
v -0.831470 -0.555570 -2.000000
v -0.923880 -0.382683 -2.000000
v -0.980785 -0.195090 -2.000000
v -1.000000 0.000000 -2.000000
v -0.980785 0.195090 -2.000000
v -0.923880 0.382683 -2.000000
v -0.831470 0.555570 -2.000000
v -0.707107 0.707107 -2.000000
v -0.555570 0.831470 -2.000000
v -0.382683 0.923880 -2.000000
v -0.195090 0.980785 -2.000000
v 0.000000 -0.000000 0.000000
vn 0.0878 0.8910 0.4455
vn 0.2599 0.8567 0.4455
vn 0.4220 0.7896 0.4455
vn 0.5680 0.6921 0.4455
vn 0.6921 0.5680 0.4455
vn 0.7896 0.4220 0.4455
vn 0.8567 0.2599 0.4455
vn 0.8910 0.0878 0.4455
vn 0.8910 -0.0878 0.4455
vn 0.8567 -0.2599 0.4455
vn 0.7896 -0.4220 0.4455
vn 0.6921 -0.5680 0.4455
vn 0.5680 -0.6921 0.4455
vn 0.4220 -0.7896 0.4455
vn 0.2599 -0.8567 0.4455
vn 0.0878 -0.8910 0.4455
vn -0.0878 -0.8910 0.4455
vn -0.2599 -0.8567 0.4455
vn -0.4220 -0.7896 0.4455
vn -0.5680 -0.6921 0.4455
vn -0.6921 -0.5680 0.4455
vn -0.7896 -0.4220 0.4455
vn -0.8567 -0.2599 0.4455
vn -0.8910 -0.0878 0.4455
vn -0.8910 0.0878 0.4455
vn -0.8567 0.2599 0.4455
vn -0.7896 0.4220 0.4455
vn -0.6921 0.5680 0.4455
vn -0.5680 0.6921 0.4455
vn -0.4220 0.7896 0.4455
vn -0.0000 -0.0000 -1.0000
vn -0.2599 0.8567 0.4455
vn -0.0878 0.8910 0.4455
s 0
f 1//1 33//1 2//1
f 2//2 33//2 3//2
f 3//3 33//3 4//3
f 4//4 33//4 5//4
f 5//5 33//5 6//5
f 6//6 33//6 7//6
f 7//7 33//7 8//7
f 8//8 33//8 9//8
f 9//9 33//9 10//9
f 10//10 33//10 11//10
f 11//11 33//11 12//11
f 12//12 33//12 13//12
f 13//13 33//13 14//13
f 14//14 33//14 15//14
f 15//15 33//15 16//15
f 16//16 33//16 17//16
f 17//17 33//17 18//17
f 18//18 33//18 19//18
f 19//19 33//19 20//19
f 20//20 33//20 21//20
f 21//21 33//21 22//21
f 22//22 33//22 23//22
f 23//23 33//23 24//23
f 24//24 33//24 25//24
f 25//25 33//25 26//25
f 26//26 33//26 27//26
f 27//27 33//27 28//27
f 28//28 33//28 29//28
f 29//29 33//29 30//29
f 30//30 33//30 31//30
f 1//31 2//31 3//31 4//31 5//31 6//31 7//31 8//31 9//31 10//31 11//31 12//31 13//31 14//31 15//31 16//31 17//31 18//31 19//31 20//31 21//31 22//31 23//31 24//31 25//31 26//31 27//31 28//31 29//31 30//31 31//31 32//31
f 31//32 33//32 32//32
f 32//33 33//33 1//33
106 changes: 106 additions & 0 deletions Assets/Models/SceneLightCone.obj.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 33c86d6

Please sign in to comment.