Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
f7d88179
Commit
f7d88179
authored
6 years ago
by
netpro2k
Browse files
Options
Downloads
Patches
Plain Diff
Move sketchfab zip to worker
parent
e71220b6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/gltf-model-plus.js
+17
-19
17 additions, 19 deletions
src/components/gltf-model-plus.js
src/utils/media-utils.js
+1
-1
1 addition, 1 deletion
src/utils/media-utils.js
src/workers/sketchfab-zip.worker.js
+31
-0
31 additions, 0 deletions
src/workers/sketchfab-zip.worker.js
with
49 additions
and
20 deletions
src/components/gltf-model-plus.js
+
17
−
19
View file @
f7d88179
import
JSZip
from
"
jszip
"
;
import
JSZip
from
"
jszip
"
;
import
SketchfabZipWorker
from
"
../workers/sketchfab-zip.worker.js
"
;
const
GLTFCache
=
{};
const
GLTFCache
=
{};
AFRAME
.
GLTFModelPlus
=
{
AFRAME
.
GLTFModelPlus
=
{
...
@@ -183,6 +185,17 @@ function nextTick() {
...
@@ -183,6 +185,17 @@ function nextTick() {
});
});
}
}
function
getFilesFromSketchfabZip
(
src
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
worker
=
new
SketchfabZipWorker
();
worker
.
onmessage
=
e
=>
{
const
[
success
,
fileMapOrError
]
=
e
.
data
;
(
success
?
resolve
:
reject
)(
fileMapOrError
);
};
worker
.
postMessage
(
src
);
});
}
function
cachedLoadGLTF
(
src
,
basePath
,
contentType
,
preferredTechnique
,
onProgress
)
{
function
cachedLoadGLTF
(
src
,
basePath
,
contentType
,
preferredTechnique
,
onProgress
)
{
// Load the gltf model from the cache if it exists.
// Load the gltf model from the cache if it exists.
if
(
!
GLTFCache
[
src
])
{
if
(
!
GLTFCache
[
src
])
{
...
@@ -190,30 +203,15 @@ function cachedLoadGLTF(src, basePath, contentType, preferredTechnique, onProgre
...
@@ -190,30 +203,15 @@ function cachedLoadGLTF(src, basePath, contentType, preferredTechnique, onProgre
let
gltfUrl
=
src
;
let
gltfUrl
=
src
;
let
onLoad
=
resolve
;
let
onLoad
=
resolve
;
if
(
contentType
===
"
model/gltf+zip
"
)
{
if
(
contentType
===
"
model/gltf+zip
"
)
{
const
zip
=
await
fetch
(
src
)
const
fileMap
=
await
getFilesFromSketchfabZip
(
src
);
.
then
(
r
=>
r
.
blob
())
gltfUrl
=
fileMap
[
"
scene.gtlf
"
];
.
then
(
JSZip
.
loadAsync
);
// Rewrite any url refferences in the GLTF to blob urls
const
gltfJson
=
JSON
.
parse
(
await
zip
.
file
(
"
scene.gltf
"
).
async
(
"
text
"
));
const
fileMap
=
await
Object
.
values
(
zip
.
files
).
reduce
(
async
(
prev
,
file
)
=>
{
if
(
file
.
name
===
"
scene.gltf
"
)
return
prev
;
const
out
=
await
prev
;
out
[
file
.
name
]
=
URL
.
createObjectURL
(
await
file
.
async
(
"
blob
"
));
return
out
;
},
Promise
.
resolve
({}));
gltfJson
.
buffers
&&
gltfJson
.
buffers
.
forEach
(
b
=>
(
b
.
uri
=
fileMap
[
b
.
uri
]));
gltfJson
.
images
&&
gltfJson
.
images
.
forEach
(
i
=>
(
i
.
uri
=
fileMap
[
i
.
uri
]));
gltfUrl
=
fileMap
[
"
scene.gtlf
"
]
=
URL
.
createObjectURL
(
new
Blob
([
JSON
.
stringify
(
gltfJson
,
null
,
2
)],
{
type
:
"
text/plain
"
})
);
onLoad
=
model
=>
{
onLoad
=
model
=>
{
// The GLTF is now cached as a THREE object, we can get rid of the original blobs
Object
.
keys
(
fileMap
).
forEach
(
URL
.
revokeObjectURL
);
Object
.
keys
(
fileMap
).
forEach
(
URL
.
revokeObjectURL
);
resolve
(
model
);
resolve
(
model
);
};
};
}
}
const
gltfLoader
=
new
THREE
.
GLTFLoader
();
const
gltfLoader
=
new
THREE
.
GLTFLoader
();
gltfLoader
.
path
=
basePath
;
gltfLoader
.
path
=
basePath
;
gltfLoader
.
preferredTechnique
=
preferredTechnique
;
gltfLoader
.
preferredTechnique
=
preferredTechnique
;
...
...
This diff is collapsed.
Click to expand it.
src/utils/media-utils.js
+
1
−
1
View file @
f7d88179
...
@@ -18,7 +18,7 @@ export const resolveFarsparkUrl = async url => {
...
@@ -18,7 +18,7 @@ export const resolveFarsparkUrl = async url => {
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
media
:
{
url
}
})
body
:
JSON
.
stringify
({
media
:
{
url
}
})
}).
then
(
r
=>
r
.
json
());
}).
then
(
r
=>
r
.
json
());
farsparkCache
.
set
(
url
,
resolved
);
//
farsparkCache.set(url, resolved);
return
resolved
;
return
resolved
;
};
};
...
...
This diff is collapsed.
Click to expand it.
src/workers/sketchfab-zip.worker.js
0 → 100644
+
31
−
0
View file @
f7d88179
import
JSZip
from
"
jszip
"
;
async
function
fetchZipAndGetBlobs
(
src
)
{
const
zip
=
await
fetch
(
src
)
.
then
(
r
=>
r
.
blob
())
.
then
(
JSZip
.
loadAsync
);
// Rewrite any url refferences in the GLTF to blob urls
const
gltfJson
=
JSON
.
parse
(
await
zip
.
file
(
"
scene.gltf
"
).
async
(
"
text
"
));
const
fileMap
=
await
Object
.
values
(
zip
.
files
).
reduce
(
async
(
prev
,
file
)
=>
{
if
(
file
.
name
===
"
scene.gltf
"
)
return
prev
;
const
out
=
await
prev
;
out
[
file
.
name
]
=
URL
.
createObjectURL
(
await
file
.
async
(
"
blob
"
));
return
out
;
},
Promise
.
resolve
({}));
gltfJson
.
buffers
&&
gltfJson
.
buffers
.
forEach
(
b
=>
(
b
.
uri
=
fileMap
[
b
.
uri
]));
gltfJson
.
images
&&
gltfJson
.
images
.
forEach
(
i
=>
(
i
.
uri
=
fileMap
[
i
.
uri
]));
fileMap
[
"
scene.gtlf
"
]
=
URL
.
createObjectURL
(
new
Blob
([
JSON
.
stringify
(
gltfJson
,
null
,
2
)],
{
type
:
"
text/plain
"
}));
return
fileMap
;
}
self
.
onmessage
=
async
e
=>
{
try
{
const
fileMap
=
await
fetchZipAndGetBlobs
(
e
.
data
);
self
.
postMessage
([
true
,
fileMap
]);
}
catch
(
e
)
{
self
.
postMessage
([
false
,
e
]);
}
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment