MCPcopy Index your code
hub / github.com/processing/p5.js / loading

Function loading

src/webgl/loading.js:20–1296  ·  view source on GitHub ↗
(p5, fn)

Source from the content-addressed store, hash-verified

18}
19
20function loading(p5, fn){
21 /**
22 * Loads a 3D model to create a
23 * <a href="#/p5.Geometry">p5.Geometry</a> object.
24 *
25 * `loadModel()` can load 3D models from OBJ and STL files. Once the model is
26 * loaded, it can be displayed with the
27 * <a href="#/p5/model">model()</a> function, as in `model(shape)`.
28 *
29 * There are three ways to call `loadModel()` with optional parameters to help
30 * process the model.
31 *
32 * The first parameter, `path`, is a `String` with the path to the file. Paths
33 * to local files should be relative, as in `loadModel('assets/model.obj')`.
34 * URLs such as `'https://example.com/model.obj'` may be blocked due to browser
35 * security. The `path` parameter can also be defined as a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
36 * object for more advanced usage.
37 * Note: When loading a `.obj` file that references materials stored in
38 * `.mtl` files, p5.js will attempt to load and apply those materials.
39 * To ensure that the `.obj` file reads the `.mtl` file correctly include the
40 * `.mtl` file alongside it.
41 *
42 * The first way to call `loadModel()` has three optional parameters after the
43 * file path. The first optional parameter, `successCallback`, is a function
44 * to call once the model loads. For example,
45 * `loadModel('assets/model.obj', handleModel)` will call the `handleModel()`
46 * function once the model loads. The second optional parameter,
47 * `failureCallback`, is a function to call if the model fails to load. For
48 * example, `loadModel('assets/model.obj', handleModel, handleFailure)` will
49 * call the `handleFailure()` function if an error occurs while loading. The
50 * third optional parameter, `fileType`, is the model’s file extension as a
51 * string. For example,
52 * `loadModel('assets/model', handleModel, handleFailure, '.obj')` will try to
53 * load the file model as a `.obj` file.
54 *
55 * The second way to call `loadModel()` has four optional parameters after the
56 * file path. The first optional parameter is a `Boolean` value. If `true` is
57 * passed, as in `loadModel('assets/model.obj', true)`, then the model will be
58 * resized to ensure it fits the canvas. The next three parameters are
59 * `successCallback`, `failureCallback`, and `fileType` as described above.
60 *
61 * The third way to call `loadModel()` has one optional parameter after the
62 * file path. The optional parameter, `options`, is an `Object` with options,
63 * as in `loadModel('assets/model.obj', options)`. The `options` object can
64 * have the following properties:
65 *
66 * ```js
67 * let options = {
68 * // Enables standardized size scaling during loading if set to true.
69 * normalize: true,
70 *
71 * // Function to call once the model loads.
72 * successCallback: handleModel,
73 *
74 * // Function to call if an error occurs while loading.
75 * failureCallback: handleError,
76 *
77 * // Model's file extension.

Callers 4

downloading.jsFile · 0.85
loadModel.jsFile · 0.85
material.jsFile · 0.85
loading.jsFile · 0.85

Calls 14

normalizeMethod · 0.95
flipUMethod · 0.95
flipVMethod · 0.95
_makeTriangleEdgesMethod · 0.95
requestFunction · 0.90
getMaterialsFunction · 0.85
parseSTLFunction · 0.85
parseObjFunction · 0.85
sliceMethod · 0.80
splitMethod · 0.80
_assert3dMethod · 0.80
modelMethod · 0.80

Tested by

no test coverage detected