H3DU.ObjData
H3DU.ObjData()
WaveFront OBJ format.
This class is considered a supplementary class to the Public Domain HTML 3D Library and is not considered part of that library.
To use this class, you must include the script "extras/objmtl.js"; the class is not included in the "h3du_min.js" file which makes up the HTML 3D Library. Example:
<script type="text/javascript" src="extras/objmtl.js"></script>
Members
Methods
- loadMtlFromUrl
Loads a material (MTL) file asynchronously. - loadObjFromUrl
Loads a WaveFront OBJ file (along with its associated MTL, or material file, if available) asynchronously. - loadObjFromUrlWithTextures
Loads a WaveFront OBJ file (along with its associated MTL, or material file, if available), along with the textures it uses, asynchronously. - toShape
Creates one or more 3D shapes from the data in this OBJ file. - toShapeFromName
Creates one or more H3DU.Shape objects from the named portion of the data in this OBJ file.
H3DU.ObjData#mtllib
Deprecated: This property is not meant to be public.
An array of meshes. Two or more meshes may have the same name (the "name" property in each mesh). The "data" property holds data for each mesh.
H3DU.ObjData#url
URL of the OBJ file.
(static) H3DU.ObjData.loadMtlFromUrl(url)
Loads a material (MTL) file asynchronously.
Parameters
url
(Type: string)
The URL to load the material data file.
Return Value
A promise that resolves when the MTL file is loaded successfully, and is rejected when an error occurs when loading the MTL file. If the promise resolves, the result is an object that implements the following methods:
getMaterial(name)
- Gets a material by name;name
is the name of the material. Returns the material as H3DU.Material, or null if it doesn't exist.getMaterialNames()
- Gets an array of names of all the materials included in this MTL file.
(static) H3DU.ObjData.loadObjFromUrl(url)
Loads a WaveFront OBJ file (along with its associated MTL, or material file, if available) asynchronously.
Parameters
url
(Type: string)
The URL to load.
Return Value
A promise that resolves when the OBJ file is loaded successfully, whether or not its associated MTL is also loaded successfully (the result is an H3DU.ObjData object), and is rejected when an error occurs when loading the OBJ file. (Type: Promise)
(static) H3DU.ObjData.loadObjFromUrlWithTextures(url, textureLoader)
Loads a WaveFront OBJ file (along with its associated MTL, or material file, if available), along with the textures it uses, asynchronously.
Parameters
url
(Type: string)
The URL to load.textureLoader
(Type: TextureLoader)
An object to load textures with.
Return Value
A promise that resolves when the OBJ file and textures are loaded successfully, whether or not the associated MTL is also loaded successfully (the result is an H3DU.ObjData object), and is rejected when an error occurs when loading the OBJ file or any of its textures. (Type: Promise)
H3DU.ObjData#toShape()
Creates one or more 3D shapes from the data in this OBJ file.
Return Value
Group of shapes. (Type: H3DU.ShapeGroup)
H3DU.ObjData#toShapeFromName(name)
Creates one or more H3DU.Shape objects from the named portion of the data in this OBJ file. If a MTL file was also loaded, the shape will have the corresponding material, if it uses one.
Parameters
name
(Type: string)
Name from the OBJ file of the portion of the model to use.
Return Value
Group of shapes. The group will be empty if no shapes with the given name exist. (Type: H3DU.ShapeGroup)