Skip to content

Commit

Permalink
Merge feature/glb
Browse files Browse the repository at this point in the history
Major changes:
- Tilt Brush Toolkit now requires Unity 2018.4
- Support for Tilt Brush's .glb1 export format.

Change-Id: Id000b015654e929336ef5bf4268e13cc3086993d
dubois committed Jul 31, 2019
1 parent 68cb858 commit e0b441b
Showing 95 changed files with 29,356 additions and 189 deletions.
1 change: 1 addition & 0 deletions UnitySDK/.gitignore
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
/Obj/
/Build/
/Library/
/Logs/

# mono debugging files, automatically created by UnityVS
*.dll.mdb
78 changes: 78 additions & 0 deletions UnitySDK/Assets/Editor/Tests/TestGlbParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2019 Google LLC
//
// 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
//
// https://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.

// Use of deprecated "WWW"
#pragma warning disable 0618

using System.IO;
using UnityEngine;

using NUnit.Framework;

namespace TiltBrushToolkit {

internal class TestGlbParser {
// Files in glTF-Sample-Models are too vague about their licenses for us to distribute them,
// so pull them as-needed.
static string FetchToTempFile(string uri, string uniqueName) {
string fullDest = Path.Combine(Application.temporaryCachePath, uniqueName);
if (!File.Exists(fullDest)) {
using (var www = new WWW(uri)) {
while (!www.isDone) {
System.Threading.Thread.Sleep(50);
}
File.WriteAllBytes(fullDest, www.bytes);
}
}
return fullDest;
}

static string GetGlb1File() {
return FetchToTempFile(
"http://github.com/KhronosGroup/glTF-Sample-Models/blob/master/1.0/Box/glTF-Binary/Box.glb?raw=true",
"Box.glb1");
}

static string GetGlb2File() {
return FetchToTempFile(
"http://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Box/glTF-Binary/Box.glb?raw=true",
"Box.glb2");
}

[Test]
public void TestV1Json() {
var file = GetGlb1File();
GlbParser.GetJsonChunkAsString(file);
}

[Test]
public void TestV1Bin() {
var file = GetGlb1File();
GlbParser.GetBinChunk(file);
}

[Test]
public void TestV2Json() {
var file = GetGlb2File();
GlbParser.GetJsonChunkAsString(file);
}

[Test]
public void TestV2Bin() {
var file = GetGlb2File();
GlbParser.GetBinChunk(file);
}
}

}
11 changes: 11 additions & 0 deletions UnitySDK/Assets/Editor/Tests/TestGlbParser.cs.meta

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

84 changes: 84 additions & 0 deletions UnitySDK/Assets/Editor/Tests/TestSubStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2019 Google LLC
//
// 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
//
// https://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.Linq;
using System.IO;

using NUnit.Framework;
using Range = TiltBrushToolkit.GlbParser.Range;

namespace TiltBrushToolkit {

internal class TestSubStream {
static Stream MakeStream(int n=25) {
return new MemoryStream(Enumerable.Range(0, n).Select(i => (byte) i).ToArray());
}

static byte[] GetRange(Stream stream, Range range) {
return GetRange(stream, range.start, range.length);
}

// If the stream only has n < length bytes left, returns a byte[n] instead of a byte[length].
static byte[] GetRange(Stream stream, long start, long length) {
int numDesired = (int)length;
// Lazy way of handling a short reads.
while (true) {
stream.Position = start;
var ret = new byte[numDesired];
int numRead = stream.Read(ret, 0, ret.Length);
if (numRead == ret.Length) {
return ret;
} else {
numDesired = numRead;
}
}
}

[Test]
public void TestSubStreamContents() {
Stream baseStream = MakeStream();
Range range = new Range { start = 10, length = 5 };
Stream subStream = new SubStream(baseStream, range.start, range.length);
var expected = new byte[] { 10, 11, 12, 13, 14 };
Assert.AreEqual(expected, GetRange(baseStream, range));
Assert.AreEqual(expected, GetRange(subStream, 0, range.length));
Assert.AreEqual(expected, GetRange(subStream, 0, range.length + 1));
}

[Test]
public void TestSubStreamSeekBeforeBeginning() {
Stream baseStream = MakeStream();
Stream subStream = new SubStream(baseStream, 10, 5);
Assert.Catch(() => { subStream.Position = -1; });
}

[Test]
public void TestSubStreamSeekAfterEnd() {
Stream baseStream = MakeStream();
Stream subStream = new SubStream(baseStream, 10, 5);
Assert.AreEqual(new byte[0], GetRange(subStream, 5, 1));
subStream.Position = 6;
Assert.AreEqual(new byte[0], GetRange(subStream, 6, 1));
}

[Test]
public void TestSubStreamOutOfRange() {
Stream baseStream = MakeStream(25);
Assert.Catch(() => new SubStream(baseStream, 23, 5));
Assert.Catch(() => new SubStream(baseStream, -1, 5));
Assert.Catch(() => new SubStream(baseStream, 23, -1));
}
}

}
11 changes: 11 additions & 0 deletions UnitySDK/Assets/Editor/Tests/TestSubStream.cs.meta

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

8 changes: 8 additions & 0 deletions UnitySDK/Assets/ThirdParty/Json-NET-for-Unity.meta

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

9 changes: 9 additions & 0 deletions UnitySDK/Assets/ThirdParty/Json-NET-for-Unity/Assemblies.meta

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.

Loading

0 comments on commit e0b441b

Please sign in to comment.