-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
|
||
# Rider | ||
**/.idea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 Andreas Atteneder | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
|
||
using System.Diagnostics; | ||
using UnityEngine; | ||
|
||
namespace Unity.glTF.Validator { | ||
|
||
public static class Validator { | ||
|
||
public static Report Validate(string path) { | ||
|
||
var processInfo = new ProcessStartInfo { | ||
FileName = "/usr/local/bin/gltf_validator", | ||
Arguments = $"-o \"{path}\"", | ||
CreateNoWindow = true, | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
}; | ||
|
||
var process = Process.Start(processInfo); | ||
|
||
if (process != null) { | ||
var json = process.StandardOutput.ReadToEnd(); | ||
process.WaitForExit(); | ||
process.Close(); | ||
return JsonUtility.FromJson<Report>(json); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2022 Andreas Atteneder | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
|
||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Unity.glTF.Validator.Editor { | ||
|
||
public static class MenuItems { | ||
|
||
static string SaveFolderPath { | ||
get { | ||
var saveFolderPath = EditorUserSettings.GetConfigValue("glTF.saveFilePath"); | ||
if (string.IsNullOrEmpty(saveFolderPath)) { | ||
saveFolderPath = Application.streamingAssetsPath; | ||
} | ||
return saveFolderPath; | ||
} | ||
set => EditorUserSettings.SetConfigValue("glTF.saveFilePath",value); | ||
} | ||
|
||
[MenuItem("Tools/glTF-Validator")] | ||
static void MenuGltfValidate() { | ||
var path = EditorUtility.OpenFilePanelWithFilters("Select glTF file to validate", SaveFolderPath, new []{"glTF files", "gltf,glb"} ); | ||
if (!string.IsNullOrEmpty(path)) { | ||
SaveFolderPath = Directory.GetParent(path)?.FullName; | ||
var report = Validator.Validate(path); | ||
report.Log(); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2022 Andreas Atteneder | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
|
||
using System; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace Unity.glTF.Validator { | ||
|
||
public enum MessageCode { | ||
Unknown, | ||
// ReSharper disable InconsistentNaming | ||
ACCESSOR_ELEMENT_OUT_OF_MAX_BOUND, | ||
ACCESSOR_MAX_MISMATCH, | ||
ACCESSOR_MIN_MISMATCH, | ||
NODE_EMPTY, | ||
UNUSED_OBJECT, | ||
// ReSharper restore InconsistentNaming | ||
} | ||
|
||
[Serializable] | ||
public class Report { | ||
public string uri; | ||
public string mimeType; | ||
public string validatorVersion; | ||
|
||
public Issue issues; | ||
public Info info; | ||
|
||
public static readonly MessageCode[] defaultIgnored = new[] { | ||
MessageCode.UNUSED_OBJECT | ||
}; | ||
|
||
public void Log(MessageCode[] ignoredCodes = null) { | ||
if (issues != null) { | ||
foreach (var message in issues.messages) { | ||
if(ignoredCodes!=null && ignoredCodes.Contains(message.codeEnum) ) continue; | ||
message.Log(); | ||
} | ||
} else { | ||
Debug.Log("glTF validation passed"); | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class Issue { | ||
public int numErrors; | ||
public int numWarnings; | ||
public int numInfos; | ||
public int numHints; | ||
public Message[] messages; | ||
public bool truncated; | ||
} | ||
|
||
[Serializable] | ||
public class Message { | ||
public string code; | ||
public string message; | ||
public int severity; | ||
public string pointer; | ||
|
||
public MessageCode codeEnum => Enum.TryParse<MessageCode>(code, out var value) ? value : MessageCode.Unknown; | ||
|
||
public void Log() { | ||
if (severity < 1) { | ||
Debug.LogError($"{message} ({code}, {pointer})"); | ||
} else if (severity < 2) { | ||
Debug.LogWarning($"{message} ({code}, {pointer})"); | ||
} else { | ||
Debug.Log($"{message} ({code}, {pointer})"); | ||
} | ||
} | ||
|
||
public override string ToString() { | ||
return $"{code}: {message} ({pointer})"; | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class Info { | ||
public string version; | ||
public string generator; | ||
public string[] extensionsUsed; | ||
public string[] extensionsRequired; | ||
|
||
public int animationCount; | ||
public int materialCount; | ||
public int drawCallCount; | ||
public int totalVertexCount; | ||
public int totalTriangleCount; | ||
public int maxUVs; | ||
public int maxInfluences; | ||
public int maxAttributes; | ||
|
||
public bool hasMorphTargets; | ||
public bool hasSkins; | ||
public bool hasTextures; | ||
public bool hasDefaultScene; | ||
} | ||
|
||
[Serializable] | ||
public class Resource { | ||
public string pointer; | ||
public string mimeTyp; | ||
public string storage; | ||
public string uri; | ||
public int byteLength; | ||
public Image image; | ||
} | ||
|
||
[Serializable] | ||
public class Image { | ||
public int width; | ||
public int height; | ||
public string format; | ||
public string primaries; | ||
public string transfer; | ||
public int bits; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "com.unity.formats.gltf.validator.Editor", | ||
"rootNamespace": "", | ||
"references": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": false, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# glTF-Validator for Unity | ||
|
||
This package integrates the [glTF-Validator][gltf-validator] CLI tool into Unity. | ||
|
||
It allows you validate a glTF file against the 2.0 specification and reports errors, warnings or info messages. | ||
|
||
> Note: Currently it's experimental and only works on macOS! | ||
## Install | ||
|
||
You need to have [glTF-Validator][gltf-validator] installed at `/usr/local/bin/gltf_validator` (this exact requirement will be removed). | ||
|
||
[gltf-validator]: https://github.com/KhronosGroup/glTF-Validator |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "com.unity.formats.gltf.validator", | ||
"version": "0.1.0-preview.1", | ||
"displayName": "glTF-Validator for Unity", | ||
"description": "Validate glTF files", | ||
"unity": "2019.4", | ||
"keywords": [ | ||
"mesh", | ||
"gltf", | ||
"asset", | ||
"format", | ||
"draco", | ||
"ktx", | ||
"basis", | ||
"universal", | ||
"basisu" | ||
], | ||
"dependencies": { | ||
"com.unity.modules.jsonserialize": "1.0.0" | ||
}, | ||
"type": "tool" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.