minorua / Qgis2threejs

3D map visualization and web export plugin for QGIS
http://minorua.github.io/Qgis2threejs/docs/
495 stars 91 forks source link

No scene.js file when exporting to web using pyqgis with "localMode": true #247

Open andremalms opened 3 years ago

andremalms commented 3 years ago

I am currently using instructions on official docs in order to use qgis2threejs with pyqgis, initially using QGIS console 3.18.1-Zürich.

Using the interface, I generated a qto3setting file where there's an OPT 'localMode' parameter defined as true. When I call the python script below, it won't create the scene.js file. I can export the scene without any problem using common interface:

from official documentation:

from PyQt5.QtCore import QSize from Qgis2threejs.export import ThreeJSExporter, ImageExporter from Qgis2threejs.mapextent import MapExtent

TEX_WIDTH, TEX_HEIGHT = (1024, 1024) path_to_settings = "/pathto/DTM.qto3settings" mapSettings = iface.mapCanvas().mapSettings() #this is qgis console, so layers are currently open center = mapSettings.extent().center() width = mapSettings.extent().width() height = width * TEX_HEIGHT / TEX_WIDTH rotation = 0 MapExtent(center, width, height, rotation).toMapSettings(mapSettings) mapSettings.setOutputSize(QSize(TEX_WIDTH, TEX_HEIGHT))

#

1. Export to web browser

#

filename= "pathto/3D.html" exporter = ThreeJSExporter() exporter.loadSettings(path_to_settings) exporter.setMapSettings(mapSettings)
exporter.export(filename)

Skander18 commented 11 months ago

Hi, Have you managed to discover a solution for it? I'm encountering the same issue.

andremalms commented 11 months ago

Hi! unfortunately never had an answer :/Enviado do meu iPhoneEm 3 de ago. de 2023, à(s) 11:01, Skander18 @.***> escreveu: Hi, Have you managed to discover a solution for it? I'm encountering the same issue.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

Skander18 commented 11 months ago

Hello, this code should work :

from PyQt5.QtCore import QSize from Qgis2threejs.export import ThreeJSExporter, ImageExporter # or ModelExporter from Qgis2threejs.mapextent import MapExtent

from qgis.testing import unittest TEX_WIDTH, TEX_HEIGHT = (1024, 1024) class TestExport(unittest.TestCase):

def __init__(self, filename):
    self.filename = "C:/.../ABC.html"
    self.path_to_settings = "C:/.../Project.qgs" 
    self.path = "C:/.../ABC.qto3settings" 
    pass

def test01_export_scene1_webpage(self):
    """test web page export"""

    mapSettings = iface.mapCanvas().mapSettings()
     # extent
    center = mapSettings.extent().center()
    width = mapSettings.extent().width()
    height = width * TEX_HEIGHT / TEX_WIDTH
    rotation = 0
    # apply the above extent to map settings
    MapExtent(center, width, height, rotation).toMapSettings(mapSettings)
    # texture base size
    mapSettings.setOutputSize(QSize(TEX_WIDTH, TEX_HEIGHT))

    exporter = ThreeJSExporter()
    exporter.loadSettings(self.path)
    exporter.settings.localMode = exporter.settings.base64 = True
    exporter.setMapSettings(mapSettings)
    err = exporter.export(self.filename)

    assert err, "export failed"
    pass

if name == "main": unittest.main() qgis_instance = TestExport(unittest.TestCase)
qgis_instance.test01_export_scene1_webpage()