forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectLoader.html
More file actions
162 lines (130 loc) · 5.1 KB
/
ObjectLoader.html
File metadata and controls
162 lines (130 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
[page:Loader] →
<h1>[name]</h1>
<p class="desc">
A loader for loading a JSON resource in the
[link:https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4 JSON Object/Scene format].<br /><br />
This uses the [page:FileLoader] internally for loading files.
</p>
<h2>Code Example</h2>
<code>
const loader = new THREE.ObjectLoader();
loader.load(
// resource URL
"models/json/example.json",
// onLoad callback
// Here the loaded data is assumed to be an object
function ( obj ) {
// Add the loaded object to the scene
scene.add( obj );
},
// onProgress callback
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// onError callback
function ( err ) {
console.error( 'An error happened' );
}
);
// Alternatively, to parse a previously loaded JSON structure
const object = loader.parse( a_json_object );
scene.add( object );
</code>
<h2>Examples</h2>
<p>[example:webgpu_materials_lightmap WebGL / materials / lightmap]</p>
<h2>Constructor</h2>
<h3>[name]( [param:LoadingManager manager] )</h3>
<p>
[page:LoadingManager manager] — The [page:LoadingManager loadingManager]
for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
Creates a new [name].
</p>
<h2>Properties</h2>
<p>See the base [page:Loader] class for common properties.</p>
<h2>Methods</h2>
<p>See the base [page:Loader] class for common methods.</p>
<h3>
[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
</h3>
<p>
[page:String url] — the path or URL to the file. This can also be a
[link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
[page:Function onLoad] — Will be called when load completes. The argument
will be the loaded [page:Object3D object].<br />
[page:Function onProgress] (optional) — Will be called while load
progresses. The argument will be the ProgressEvent instance, which
contains .[page:Boolean lengthComputable], .[page:Integer total] and
.[page:Integer loaded]. If the server does not set the Content-Length
header; .[page:Integer total] will be 0.<br />
[page:Function onError] (optional) — Will be called when load errors.<br />
</p>
<p>
Begin loading from url and call onLoad with the parsed response content.
</p>
<h3>
[method:Object3D parse]( [param:Object json], [param:Function onLoad] )
</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
[page:Function onLoad] — Will be called when parsed completes. The
argument will be the parsed [page:Object3D object].<br /><br />
Parse a `JSON` structure and return a three.js object. This is used
internally by [page:.load]() but can also be used directly to parse a
previously loaded JSON structure.
</p>
<h3>[method:Object parseGeometries]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
This is used by [page:.parse]() to parse any [page:BufferGeometry geometries] in the JSON structure.
</p>
<h3>[method:Object parseMaterials]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
This is used by [page:.parse]() to parse any materials in the JSON
structure using [page:MaterialLoader].
</p>
<h3>[method:Object parseAnimations]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
This is used by [page:.parse]() to parse any animations in the JSON
structure, using [page:AnimationClip.parse]().
</p>
<h3>[method:Object parseImages]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
This is used by [page:.parse]() to parse any images in the JSON structure,
using [page:ImageLoader].
</p>
<h3>[method:Object parseTextures]( [param:Object json] )</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br /><br />
This is used by [page:.parse]() to parse any textures in the JSON
structure.
</p>
<h3>
[method:Object3D parseObject]( [param:Object json], [param:BufferGeometry geometries], [param:Material materials], [param:AnimationClip animations] )
</h3>
<p>
[page:Object json] — required. The JSON source to parse.<br />
[page:BufferGeometry geometries] — required. The geometries of the
JSON.<br />
[page:Material materials] — required. The materials of the JSON.<br />
[page:AnimationClip animations] — required. The animations of the JSON.<br /><br />
This is used by [page:.parse]() to parse any 3D objects in the JSON
structure.
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>