* @param {number} x - the x screen position of the mesh object * @param {number} y - the y screen position of the mesh object * @param {object} settings - Configuration parameters for the Mesh object * @param {string} [settings.model] - name of a preloaded OBJ model (via loader.preload with ty
(x, y, settings)
| 190 | * mesh.rotate(Math.PI / 4); |
| 191 | */ |
| 192 | constructor(x, y, settings) { |
| 193 | super(x, y, settings.width, settings.height); |
| 194 | |
| 195 | // load geometry from OBJ model or raw data |
| 196 | let objGroups = null; |
| 197 | if (typeof settings.model === "string") { |
| 198 | const objData = getOBJ(settings.model); |
| 199 | if (!objData) { |
| 200 | throw new Error("Mesh: '" + settings.model + "' OBJ model not found!"); |
| 201 | } |
| 202 | /** |
| 203 | * the original (untransformed) vertex positions as x,y,z triplets |
| 204 | * @type {Float32Array} |
| 205 | */ |
| 206 | this.originalVertices = objData.vertices; |
| 207 | |
| 208 | /** |
| 209 | * texture coordinates as u,v pairs |
| 210 | * @type {Float32Array} |
| 211 | */ |
| 212 | this.uvs = objData.uvs; |
| 213 | |
| 214 | /** |
| 215 | * triangle indices |
| 216 | * @type {Uint16Array} |
| 217 | */ |
| 218 | this.indices = objData.indices; |
| 219 | |
| 220 | /** |
| 221 | * number of vertices |
| 222 | * @type {number} |
| 223 | */ |
| 224 | this.vertexCount = objData.vertexCount; |
| 225 | |
| 226 | // pick up the material-group list emitted by the OBJ parser |
| 227 | // (always non-null for non-empty models thanks to the |
| 228 | // parser's "anonymous group" fallback) |
| 229 | objGroups = objData.groups; |
| 230 | } else { |
| 231 | this.originalVertices = |
| 232 | settings.vertices instanceof Float32Array |
| 233 | ? settings.vertices |
| 234 | : new Float32Array(settings.vertices); |
| 235 | this.uvs = |
| 236 | settings.uvs instanceof Float32Array |
| 237 | ? settings.uvs |
| 238 | : new Float32Array(settings.uvs); |
| 239 | // Preserve a typed index buffer as-is — coercing a Uint32Array to |
| 240 | // Uint16Array would truncate index values > 65535, silently |
| 241 | // corrupting meshes with more than 65535 vertices (the glTF parser |
| 242 | // emits Uint32 indices for exactly that case). Only a plain JS |
| 243 | // array is materialized, as Uint16 (the small-mesh default). The |
| 244 | // batcher chunks large meshes into ≤maxVertices flushes, so its own |
| 245 | // index buffer never needs more than 16 bits regardless. |
| 246 | this.indices = |
| 247 | settings.indices instanceof Uint16Array || |
| 248 | settings.indices instanceof Uint32Array |
| 249 | ? settings.indices |
nothing calls this directly
no test coverage detected