You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{ArxPolygonFlags}from'arx-convert/types'import{ArxMap,Material,QUADIFY,Settings,SHADING_SMOOTH,Texture,Vector3}from'arx-level-generator'import{scaleUV,toArxCoordinateSystem}from'arx-level-generator/tools/mesh'import{applyTransformations}from'arx-level-generator/utils'import{MathUtils,Mesh,MeshBasicMaterial,PlaneGeometry}from'three'constmap=newArxMap()map.config.offset=newVector3(3000,0,3000)// create a 200x200cm plane that is to be divided into 4x4 quads each with 50x50 size// at this moment quads are just 2 trianglesletgeometry=newPlaneGeometry(200,200,4,4)// Arx uses an inverted Y axis, this corrects the geometrygeometry=toArxCoordinateSystem(geometry)// pick a pre-defined texture or load one either from Arx or from a custom file (see docs/examples/textures.md)lettexture=Texture.l2TrollStoneGround04// [optional step]: you can add extra properties to a texture using the "flags" property, like making it double sided or glowing;// here you can also make it transparent with the "opacity" and "opacityMode" propertiestexture=Material.fromTexture(texture,{flags: ArxPolygonFlags.DoubleSided})// wrapping the texture into a Material class from three.js (different from the Material of arx-level-generator)constmaterial=newMeshBasicMaterial({map: texture})// grouping the geometry and material together into a three.js mesh objectconstmesh=newMesh(geometry,material)// [optional step]: adjust the orientation of the geometry// by default the plane is on its side, need to make it face upwardsgeometry.rotateX(MathUtils.degToRad(-90))// [optional step]: move the mesh on the X/Y/Z axisgeometry.translate(20,0,0)// [optional step]: by default the texture will be scaled in a way that it covers the whole mesh 1x1 times// this code will tile the texture 4 times in both axis, so every 50x50 tile will have its own full texturescaleUV(newVector2(4,4),geometry)// boilerplate code that adjusts the center of the geometry to the map's offset (3000/0/3000 in this example)applyTransformations(mesh)mesh.translateX(map.config.offset.x)mesh.translateY(map.config.offset.y)mesh.translateZ(map.config.offset.z)applyTransformations(mesh)// add the mesh to the map; this is where polygons get turned into quads + shading can be smooth or flatmap.polygons.addThreeJsMesh(mesh,{tryToQuadify: QUADIFY,shading: SHADING_SMOOTH})
Simplify the above with createPlaneMesh prefab
import{ArxPolygonFlags}from'arx-convert/types'import{ArxMap,Material,QUADIFY,Settings,SHADING_SMOOTH,Texture,Vector3}from'arx-level-generator'import{createPlaneMesh}from'arx-level-generator/prefabs/mesh'import{applyTransformations}from'arx-level-generator/utils'import{Vector2}from'three'constsettings=newSettings()constmap=newArxMap()map.config.offset=newVector3(6000,0,6000)consttexture=Material.fromTexture(Texture.l2TrollStoneGround04,{flags: ArxPolygonFlags.DoubleSided})constmesh=createPlaneMesh({size: newVector2(200,200),tileSize: 50,// every tile will be 50x50 -> the mesh will be subdivided into 4x4 tilestexture: texture,})applyTransformations(mesh)mesh.translateX(map.config.offset.x)mesh.translateY(map.config.offset.y)mesh.translateZ(map.config.offset.z)applyTransformations(mesh)map.polygons.addThreeJsMesh(mesh,{tryToQuadify: QUADIFY,// use QUADIFY if the surface is flat, otherwise use DONT_QUADIFYshading: SHADING_SMOOTH,})