Skip to content

Commit e0b441b

Browse files
committed
Merge feature/glb
Major changes: - Tilt Brush Toolkit now requires Unity 2018.4 - Support for Tilt Brush's .glb1 export format. Change-Id: Id000b015654e929336ef5bf4268e13cc3086993d
1 parent 68cb858 commit e0b441b

File tree

95 files changed

+29356
-189
lines changed

Some content is hidden

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

95 files changed

+29356
-189
lines changed

UnitySDK/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/Obj/
44
/Build/
55
/Library/
6+
/Logs/
67

78
# mono debugging files, automatically created by UnityVS
89
*.dll.mdb
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Use of deprecated "WWW"
16+
#pragma warning disable 0618
17+
18+
using System.IO;
19+
using UnityEngine;
20+
21+
using NUnit.Framework;
22+
23+
namespace TiltBrushToolkit {
24+
25+
internal class TestGlbParser {
26+
// Files in glTF-Sample-Models are too vague about their licenses for us to distribute them,
27+
// so pull them as-needed.
28+
static string FetchToTempFile(string uri, string uniqueName) {
29+
string fullDest = Path.Combine(Application.temporaryCachePath, uniqueName);
30+
if (!File.Exists(fullDest)) {
31+
using (var www = new WWW(uri)) {
32+
while (!www.isDone) {
33+
System.Threading.Thread.Sleep(50);
34+
}
35+
File.WriteAllBytes(fullDest, www.bytes);
36+
}
37+
}
38+
return fullDest;
39+
}
40+
41+
static string GetGlb1File() {
42+
return FetchToTempFile(
43+
"http://github.com/KhronosGroup/glTF-Sample-Models/blob/master/1.0/Box/glTF-Binary/Box.glb?raw=true",
44+
"Box.glb1");
45+
}
46+
47+
static string GetGlb2File() {
48+
return FetchToTempFile(
49+
"http://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Box/glTF-Binary/Box.glb?raw=true",
50+
"Box.glb2");
51+
}
52+
53+
[Test]
54+
public void TestV1Json() {
55+
var file = GetGlb1File();
56+
GlbParser.GetJsonChunkAsString(file);
57+
}
58+
59+
[Test]
60+
public void TestV1Bin() {
61+
var file = GetGlb1File();
62+
GlbParser.GetBinChunk(file);
63+
}
64+
65+
[Test]
66+
public void TestV2Json() {
67+
var file = GetGlb2File();
68+
GlbParser.GetJsonChunkAsString(file);
69+
}
70+
71+
[Test]
72+
public void TestV2Bin() {
73+
var file = GetGlb2File();
74+
GlbParser.GetBinChunk(file);
75+
}
76+
}
77+
78+
}

UnitySDK/Assets/Editor/Tests/TestGlbParser.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System.Linq;
16+
using System.IO;
17+
18+
using NUnit.Framework;
19+
using Range = TiltBrushToolkit.GlbParser.Range;
20+
21+
namespace TiltBrushToolkit {
22+
23+
internal class TestSubStream {
24+
static Stream MakeStream(int n=25) {
25+
return new MemoryStream(Enumerable.Range(0, n).Select(i => (byte) i).ToArray());
26+
}
27+
28+
static byte[] GetRange(Stream stream, Range range) {
29+
return GetRange(stream, range.start, range.length);
30+
}
31+
32+
// If the stream only has n < length bytes left, returns a byte[n] instead of a byte[length].
33+
static byte[] GetRange(Stream stream, long start, long length) {
34+
int numDesired = (int)length;
35+
// Lazy way of handling a short reads.
36+
while (true) {
37+
stream.Position = start;
38+
var ret = new byte[numDesired];
39+
int numRead = stream.Read(ret, 0, ret.Length);
40+
if (numRead == ret.Length) {
41+
return ret;
42+
} else {
43+
numDesired = numRead;
44+
}
45+
}
46+
}
47+
48+
[Test]
49+
public void TestSubStreamContents() {
50+
Stream baseStream = MakeStream();
51+
Range range = new Range { start = 10, length = 5 };
52+
Stream subStream = new SubStream(baseStream, range.start, range.length);
53+
var expected = new byte[] { 10, 11, 12, 13, 14 };
54+
Assert.AreEqual(expected, GetRange(baseStream, range));
55+
Assert.AreEqual(expected, GetRange(subStream, 0, range.length));
56+
Assert.AreEqual(expected, GetRange(subStream, 0, range.length + 1));
57+
}
58+
59+
[Test]
60+
public void TestSubStreamSeekBeforeBeginning() {
61+
Stream baseStream = MakeStream();
62+
Stream subStream = new SubStream(baseStream, 10, 5);
63+
Assert.Catch(() => { subStream.Position = -1; });
64+
}
65+
66+
[Test]
67+
public void TestSubStreamSeekAfterEnd() {
68+
Stream baseStream = MakeStream();
69+
Stream subStream = new SubStream(baseStream, 10, 5);
70+
Assert.AreEqual(new byte[0], GetRange(subStream, 5, 1));
71+
subStream.Position = 6;
72+
Assert.AreEqual(new byte[0], GetRange(subStream, 6, 1));
73+
}
74+
75+
[Test]
76+
public void TestSubStreamOutOfRange() {
77+
Stream baseStream = MakeStream(25);
78+
Assert.Catch(() => new SubStream(baseStream, 23, 5));
79+
Assert.Catch(() => new SubStream(baseStream, -1, 5));
80+
Assert.Catch(() => new SubStream(baseStream, 23, -1));
81+
}
82+
}
83+
84+
}

UnitySDK/Assets/Editor/Tests/TestSubStream.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitySDK/Assets/ThirdParty/Json-NET-for-Unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitySDK/Assets/ThirdParty/Json-NET-for-Unity/Assemblies.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitySDK/Assets/ThirdParty/Json-NET-for-Unity/Assemblies/AOT.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)