Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing fixes, add precompilation workload #6

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
name = "GLTF"
uuid = "aeeaf58c-ab4d-11e9-3a9f-9b6bf58b5bc3"
authors = ["Yupei Qi <[email protected]>"]
version = "0.3.0"
version = "0.3.1"

[deps]
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"

[compat]
julia = "^1.1"
JSON3 = "^1"
JSON3 = "1"
PrecompileTools = "1"
StructTypes = "1"
julia = "1.1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
204 changes: 204 additions & 0 deletions assets/DamagedHelmet.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5123,
"count" : 46356,
"max" : [
14555
],
"min" : [
0
],
"type" : "SCALAR"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 14556,
"max" : [
0.9424954056739807,
0.8128451108932495,
0.900973916053772
],
"min" : [
-0.9474585652351379,
-1.18715500831604,
-0.9009949564933777
],
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5126,
"count" : 14556,
"max" : [
1.0,
1.0,
1.0
],
"min" : [
-1.0,
-1.0,
-1.0
],
"type" : "VEC3"
},
{
"bufferView" : 3,
"componentType" : 5126,
"count" : 14556,
"max" : [
0.9999759793281555,
1.998665988445282
],
"min" : [
0.002448640065267682,
1.0005531199858524
],
"type" : "VEC2"
}
],
"asset" : {
"generator" : "Khronos Blender glTF 2.0 exporter",
"version" : "2.0"
},
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 92712,
"byteOffset" : 0,
"target" : 34963
},
{
"buffer" : 0,
"byteLength" : 174672,
"byteOffset" : 92712,
"target" : 34962
},
{
"buffer" : 0,
"byteLength" : 174672,
"byteOffset" : 267384,
"target" : 34962
},
{
"buffer" : 0,
"byteLength" : 116448,
"byteOffset" : 442056,
"target" : 34962
}
],
"buffers" : [
{
"byteLength" : 558504,
"uri" : "DamagedHelmet.bin"
}
],
"images" : [
{
"uri" : "Default_albedo.jpg"
},
{
"uri" : "Default_metalRoughness.jpg"
},
{
"uri" : "Default_emissive.jpg"
},
{
"uri" : "Default_AO.jpg"
},
{
"uri" : "Default_normal.jpg"
}
],
"materials" : [
{
"emissiveFactor" : [
1.0,
1.0,
1.0
],
"emissiveTexture" : {
"index" : 2
},
"name" : "Material_MR",
"normalTexture" : {
"index" : 4
},
"occlusionTexture" : {
"index" : 3
},
"pbrMetallicRoughness" : {
"baseColorTexture" : {
"index" : 0
},
"metallicRoughnessTexture" : {
"index" : 1
}
}
}
],
"meshes" : [
{
"name" : "mesh_helmet_LP_13930damagedHelmet",
"primitives" : [
{
"attributes" : {
"NORMAL" : 2,
"POSITION" : 1,
"TEXCOORD_0" : 3
},
"indices" : 0,
"material" : 0
}
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "node_damagedHelmet_-6514",
"rotation" : [
0.7071068286895752,
0.0,
-0.0,
0.7071068286895752
]
}
],
"samplers" : [
{}
],
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0
]
}
],
"textures" : [
{
"sampler" : 0,
"source" : 0
},
{
"sampler" : 0,
"source" : 1
},
{
"sampler" : 0,
"source" : 2
},
{
"sampler" : 0,
"source" : 3
},
{
"sampler" : 0,
"source" : 4
}
]
}
16 changes: 14 additions & 2 deletions src/GLTF.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GLTF

using JSON3, StructTypes
using JSON3, StructTypes, PrecompileTools

export load, save

Expand Down Expand Up @@ -63,6 +63,18 @@ function save(path::AbstractString, obj::Object)
end
end


@compile_workload begin
filenames = ["DamagedHelmet.gltf"]
for filename in filenames
path = joinpath(pkgdir(GLTF), "assets", filename)
asset = load(path)::Object
sprint(show, asset)
sprint(show, MIME"text/plain"(), asset)
tmp = tempname()
save(tmp, asset)
load(tmp)::Object
rm(tmp)
end
end

end # module
6 changes: 4 additions & 2 deletions src/zvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Base.convert(::Type{ZeroRange{T}}, r::ZeroRange{T}) where {T<:Real} = r
Base.convert(::Type{ZeroRange{T}}, r::ZeroRange) where {T<:Real} = ZeroRange{T}(r.len)
ZeroRange{T}(r::ZeroRange) where {T} = convert(ZeroRange{T}, r)

Base.show(io::IO, r::ZeroRange) = print(io, typeof(r).name, "(", r.len, ")")
Base.show(io::IO, r::ZeroRange) = print(io, typeof(r), "(", r.len, ")")
Base.show(io::IO, ::MIME"text/plain", r::ZeroRange) = show(io, r)

"""
Expand All @@ -70,14 +70,16 @@ Base.parent(A::ZVector) = A.x
Base.size(A::ZVector) = size(parent(A))
Base.size(A::ZVector, d) = size(parent(A), d)

@inline Base.axes(A::ZVector) = (IdentityUnitRange(ZeroRange(length(parent(A)))),)
@inline Base.axes(A::ZVector) = (axes(A, 1),)
@inline Base.axes(A::ZVector, d) = d == 1 ? IdentityUnitRange(ZeroRange(length(parent(A)))) : IdentityUnitRange(0:0)

Base.IndexStyle(::Type{T}) where {T<:ZVector} = IndexLinear()
Base.eachindex(::IndexLinear, A::ZVector) = axes(A, 1)

Base.length(A::ZVector) = prod(size(A))

Base.isassigned(A::ZVector, i::Integer, j::Integer) = isassigned(A, i) && j == 0

@inline @propagate_inbounds function Base.getindex(A::ZVector{T}, i::Int) where {T}
@boundscheck checkbounds(A, i)
@inbounds ret = parent(A)[i + 1]
Expand Down
7 changes: 6 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ else
isdir(ASSETS_LOCAL_PATH) || run(`unzip -x $TEST_LOCAL_PATH -d $ASSETS_LOCAL_PATH`)
end

extra_assets = ["DamagedHelmet.gltf"]
for asset in extra_assets
cp(joinpath(pkgdir(GLTF), "assets", asset), joinpath(ASSETS_LOCAL_PATH, asset); force = true)
end

@testset "glTF-Asset-Generator" begin
for (root, dirs, files) in walkdir(ASSETS_LOCAL_PATH)
for file in files
Expand All @@ -27,4 +32,4 @@ end
end
end
end
end
end;