UNPKG

arx-level-generator

Version:
22 lines 1.17 kB
import { MathUtils, Mesh, MeshBasicMaterial, PlaneGeometry, Vector2 } from 'three'; import { applyTransformations } from '../../helpers.js'; import { scaleUV } from '../../tools/mesh/scaleUV.js'; import { toArxCoordinateSystem } from '../../tools/mesh/toArxCoordinateSystem.js'; export const INDEXED = 'indexed'; export const NONINDEXED = 'non-indexed'; export const createPlaneMesh = ({ size, tileSize = 100, texture, isIndexed = INDEXED, tileUV = true, }) => { const { x: width, y: depth } = typeof size === 'number' ? new Vector2(size, size) : size; const divisionX = Math.ceil(width / tileSize); const divisionY = Math.ceil(depth / tileSize); let geometry = new PlaneGeometry(width, depth, divisionX, divisionY); geometry = toArxCoordinateSystem(geometry); if (tileUV) { scaleUV(new Vector2(width / tileSize, depth / tileSize), geometry); } const material = new MeshBasicMaterial({ map: texture }); const mesh = new Mesh(isIndexed === INDEXED ? geometry : geometry.toNonIndexed(), material); mesh.rotateX(MathUtils.degToRad(90)); applyTransformations(mesh); return mesh; }; //# sourceMappingURL=plane.js.map