mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
Added OBJ exporter for 3D. (#609)
* Added OBJ exporter * Don't add links to document body * Changed to use downloadFile function
This commit is contained in:
parent
547069f25c
commit
a27e592dcb
5 changed files with 36 additions and 4 deletions
|
|
@ -10,7 +10,8 @@ const options = {scale: 50, lightness: .7, shadow: .5, sun: {x: 100, y: 600, z:
|
|||
|
||||
// set variables
|
||||
let Renderer, scene, camera, controls, animationFrame, material, texture,
|
||||
geometry, mesh, ambientLight, spotLight, waterPlane, waterMaterial, waterMesh;
|
||||
geometry, mesh, ambientLight, spotLight, waterPlane, waterMaterial, waterMesh,
|
||||
objexporter;
|
||||
|
||||
// initiate 3d scene
|
||||
const create = async function(canvas, type = "viewMesh") {
|
||||
|
|
@ -126,6 +127,10 @@ const saveScreenshot = async function() {
|
|||
window.setTimeout(() => window.URL.revokeObjectURL(URL), 5000);
|
||||
}
|
||||
|
||||
const saveOBJ = async function() {
|
||||
downloadFile(await getOBJ(), getFileName() + ".obj", "text/plain;charset=UTF-8");
|
||||
}
|
||||
|
||||
// start 3d view and heightmap edit preview
|
||||
async function newMesh(canvas) {
|
||||
const loaded = await loadTHREE();
|
||||
|
|
@ -289,6 +294,13 @@ async function updateGlobeTexure(addMesh) {
|
|||
img2.src = await getMapURL("mesh", "globe");;
|
||||
}
|
||||
|
||||
async function getOBJ() {
|
||||
objexporter = await OBJExporter();
|
||||
|
||||
const data = await objexporter.parse(mesh);
|
||||
return data;
|
||||
}
|
||||
|
||||
function addGlobe3dMesh() {
|
||||
geometry = new THREE.SphereBufferGeometry(1, 64, 64);
|
||||
mesh = new THREE.Mesh(geometry, material);
|
||||
|
|
@ -332,6 +344,18 @@ function OrbitControls(camera, domElement) {
|
|||
});
|
||||
}
|
||||
|
||||
return {create, redraw, update, stop, options, setScale, setLightness, setSun, setRotation, toggleSky, setResolution, setColors, saveScreenshot};
|
||||
function OBJExporter() {
|
||||
if (THREE.OBJExporter) return new THREE.OBJExporter();
|
||||
|
||||
return new Promise(resolve => {
|
||||
const script = document.createElement('script');
|
||||
script.src = "libs/objexporter.min.js"
|
||||
document.head.append(script);
|
||||
script.onload = () => resolve(new THREE.OBJExporter());
|
||||
script.onerror = () => resolve(false);
|
||||
});
|
||||
}
|
||||
|
||||
return {create, redraw, update, stop, options, setScale, setLightness, setSun, setRotation, toggleSky, setResolution, setColors, saveScreenshot, saveOBJ};
|
||||
|
||||
})));
|
||||
|
|
|
|||
|
|
@ -707,6 +707,7 @@ function toggle3dOptions() {
|
|||
|
||||
document.getElementById("options3dUpdate").addEventListener("click", ThreeD.update);
|
||||
document.getElementById("options3dSave").addEventListener("click", ThreeD.saveScreenshot);
|
||||
document.getElementById("options3dOBJSave").addEventListener("click", ThreeD.saveOBJ);
|
||||
|
||||
document.getElementById("options3dScaleRange").addEventListener("input", changeHeightScale);
|
||||
document.getElementById("options3dScaleNumber").addEventListener("change", changeHeightScale);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue