Use ES modules.

This commit is contained in:
kovacsv 2022-01-10 18:10:51 +01:00
parent acd30fdd7a
commit a4d386c521
179 changed files with 4602 additions and 4722 deletions

View File

@ -23,5 +23,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build
- run: npm run lint
- run: npm run test
- run: npm run create_package

View File

@ -10,13 +10,12 @@ install:
- npm install
build_script:
- npm run build
test_script:
- npm run lint
- npm run test
- npm run create_package
artifacts:
- path: build\final\package\*
- path: dist\final\package\*
deploy:
description: 'News:\n- ...'

View File

@ -4,28 +4,35 @@
"version": "0.8.4",
"repository": "github:kovacsv/Online3DViewer",
"license": "MIT",
"type": "module",
"devDependencies": {
"clean-css-cli": "^5.5.0",
"docdash": "^1.2.0",
"esbuild": "^0.14.11",
"eslint": "^8.5.0",
"fantasticon": "^1.2.2",
"google-closure-compiler": "^20211201.0.0",
"http-server": "^14.0.0",
"jsdoc": "^3.6.7",
"mocha": "^9.1.3",
"oslllo-svg-fixer": "^1.4.0",
"rewire": "^6.0.0",
"svgo": "^2.3.1"
},
"scripts": {
"start": "http-server",
"test": "mocha test",
"lint": "eslint source && eslint website",
"doc": "jsdoc -c tools/jsdoc.json",
"build": "npm run lint && npm run doc && node tools/run_python.js tools/build.py",
"update": "node tools/run_python.js tools/update.py",
"lint": "eslint source",
"docs": "jsdoc -c tools/jsdoc.json",
"updatelibs": "npm install && node tools/run_python.js tools/updatelibs.py",
"svg": "node tools/run_python.js tools/svg.py"
"generate_icon_font": "node tools/run_python.js tools/generate_icon_font.py",
"update_engine_exports": "node tools/run_python.js tools/update_engine_exports.py",
"create_dist": "npm run lint && npm run test && npm run create_package",
"create_package": "npm run build_engine_prod && npm run build_website_prod && npm run build_css_prod && node tools/run_python.js tools/create_package.py",
"build_dev": "npm run build_engine_dev && npm run build_website_dev",
"build_css_prod": "cleancss -o build/o3dv.website.min.css website/css/*",
"build_engine_dev": "npm run update_engine_exports && esbuild source/engine/main.js --bundle --minify --global-name=OV --sourcemap --outfile=build/o3dv.min-dev.js",
"build_engine_prod": "npm run update_engine_exports && esbuild source/engine/main.js --bundle --minify --global-name=OV --outfile=build/o3dv.min.js",
"build_website_dev": "esbuild source/website/index.js --bundle --minify --global-name=OV --sourcemap --outfile=build/o3dv.website.min-dev.js",
"build_website_prod": "esbuild source/website/index.js --bundle --minify --global-name=OV --outfile=build/o3dv.website.min.js"
},
"dependencies": {
"@simonwep/pickr": "1.8.2",
@ -52,13 +59,13 @@
"WebIFC": "readonly"
},
"parserOptions": {
"ecmaVersion": 12
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"semi": "error",
"no-var": "error",
"guard-for-in": "error",
"no-use-before-define": "error",
"no-new": "error",
"no-new-object": "error",
"no-new-func": "error",
@ -77,7 +84,8 @@
"no-undef": "error",
"no-extend-native": "error",
"eqeqeq": "error",
"no-unused-vars": "off"
"no-unused-vars": "off",
"no-use-before-define": "off"
}
}
}

View File

@ -8,77 +8,7 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();

View File

@ -8,77 +8,7 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();

View File

@ -7,78 +7,8 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<style>
div.online_3d_viewer

View File

@ -8,77 +8,7 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();

View File

@ -7,81 +7,11 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.ExternalLibLocation = '../../libs';
OV.SetExternalLibLocation ('../../libs');
OV.Init3DViewerElements ();
</script>

View File

@ -7,77 +7,8 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();

View File

@ -9,76 +9,8 @@
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<style>
div

View File

@ -9,76 +9,8 @@
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements (function (viewers) {

View File

@ -9,76 +9,8 @@
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();

View File

@ -7,77 +7,9 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();
</script>

View File

@ -7,77 +7,9 @@
<title>Online 3D Viewer</title>
<script type="text/javascript" src="../../libs/three.min.js"></script>
<!-- engine start -->
<script type="text/javascript" src="../source/core/core.js"></script>
<script type="text/javascript" src="../source/core/taskrunner.js"></script>
<script type="text/javascript" src="../source/geometry/geometry.js"></script>
<script type="text/javascript" src="../source/geometry/coord2d.js"></script>
<script type="text/javascript" src="../source/geometry/coord3d.js"></script>
<script type="text/javascript" src="../source/geometry/coord4d.js"></script>
<script type="text/javascript" src="../source/geometry/quaternion.js"></script>
<script type="text/javascript" src="../source/geometry/box3d.js"></script>
<script type="text/javascript" src="../source/geometry/octree.js"></script>
<script type="text/javascript" src="../source/geometry/matrix.js"></script>
<script type="text/javascript" src="../source/geometry/transformation.js"></script>
<script type="text/javascript" src="../source/geometry/tween.js"></script>
<script type="text/javascript" src="../source/io/binaryreader.js"></script>
<script type="text/javascript" src="../source/io/binarywriter.js"></script>
<script type="text/javascript" src="../source/io/textwriter.js"></script>
<script type="text/javascript" src="../source/io/bufferutils.js"></script>
<script type="text/javascript" src="../source/io/fileutils.js"></script>
<script type="text/javascript" src="../source/io/externallibs.js"></script>
<script type="text/javascript" src="../source/model/color.js"></script>
<script type="text/javascript" src="../source/model/material.js"></script>
<script type="text/javascript" src="../source/model/triangle.js"></script>
<script type="text/javascript" src="../source/model/property.js"></script>
<script type="text/javascript" src="../source/model/object.js"></script>
<script type="text/javascript" src="../source/model/mesh.js"></script>
<script type="text/javascript" src="../source/model/meshbuffer.js"></script>
<script type="text/javascript" src="../source/model/node.js"></script>
<script type="text/javascript" src="../source/model/meshinstance.js"></script>
<script type="text/javascript" src="../source/model/model.js"></script>
<script type="text/javascript" src="../source/model/topology.js"></script>
<script type="text/javascript" src="../source/model/meshutils.js"></script>
<script type="text/javascript" src="../source/model/modelutils.js"></script>
<script type="text/javascript" src="../source/model/modelfinalization.js"></script>
<script type="text/javascript" src="../source/model/quantities.js"></script>
<script type="text/javascript" src="../source/model/generator.js"></script>
<script type="text/javascript" src="../source/import/importerutils.js"></script>
<script type="text/javascript" src="../source/import/importerbase.js"></script>
<script type="text/javascript" src="../source/import/importerobj.js"></script>
<script type="text/javascript" src="../source/import/importerstl.js"></script>
<script type="text/javascript" src="../source/import/importeroff.js"></script>
<script type="text/javascript" src="../source/import/importerply.js"></script>
<script type="text/javascript" src="../source/import/importer3ds.js"></script>
<script type="text/javascript" src="../source/import/importergltf.js"></script>
<script type="text/javascript" src="../source/import/importero3dv.js"></script>
<script type="text/javascript" src="../source/import/importerthree.js"></script>
<script type="text/javascript" src="../source/import/importersvg.js"></script>
<script type="text/javascript" src="../source/import/importer3dm.js"></script>
<script type="text/javascript" src="../source/import/importerifc.js"></script>
<script type="text/javascript" src="../source/import/filelist.js"></script>
<script type="text/javascript" src="../source/import/importer.js"></script>
<script type="text/javascript" src="../source/export/exportermodel.js"></script>
<script type="text/javascript" src="../source/export/exporterbase.js"></script>
<script type="text/javascript" src="../source/export/exporterobj.js"></script>
<script type="text/javascript" src="../source/export/exporterstl.js"></script>
<script type="text/javascript" src="../source/export/exporterply.js"></script>
<script type="text/javascript" src="../source/export/exporteroff.js"></script>
<script type="text/javascript" src="../source/export/exportergltf.js"></script>
<script type="text/javascript" src="../source/export/exporter3dm.js"></script>
<script type="text/javascript" src="../source/export/exporter.js"></script>
<script type="text/javascript" src="../source/threejs/threeutils.js"></script>
<script type="text/javascript" src="../source/threejs/threeconverter.js"></script>
<script type="text/javascript" src="../source/threejs/threemodelloader.js"></script>
<script type="text/javascript" src="../source/parameters/parameterlist.js"></script>
<script type="text/javascript" src="../source/viewer/domutils.js"></script>
<script type="text/javascript" src="../source/viewer/navigation.js"></script>
<script type="text/javascript" src="../source/viewer/viewergeometry.js"></script>
<script type="text/javascript" src="../source/viewer/viewer.js"></script>
<script type="text/javascript" src="../source/viewer/measuretool.js"></script>
<script type="text/javascript" src="../source/viewer/embeddedviewer.js"></script>
<!-- engine end -->
<script type="text/javascript" src="../../libs/three.min.js"></script>
<script type="text/javascript" src="../build/o3dv.min-dev.js"></script>
<script type='text/javascript'>
OV.Init3DViewerElements ();
</script>

View File

@ -1,29 +1,24 @@
OV =
{
};
OV.IsDefined = function (val)
export function IsDefined (val)
{
return val !== undefined && val !== null;
};
}
OV.ValueOrDefault = function (val, def)
export function ValueOrDefault (val, def)
{
if (val === undefined || val === null) {
return def;
}
return val;
};
}
OV.CopyObjectAttributes = function (src, dest)
export function CopyObjectAttributes (src, dest)
{
if (!OV.IsDefined (src)) {
if (!IsDefined (src)) {
return;
}
for (let attribute of Object.keys (src)) {
if (OV.IsDefined (src[attribute])) {
if (IsDefined (src[attribute])) {
dest[attribute] = src[attribute];
}
}
};
}

View File

@ -1,4 +1,4 @@
OV.TaskRunner = class
export class TaskRunner
{
constructor ()
{
@ -53,28 +53,28 @@ OV.TaskRunner = class
}
}
}
};
}
OV.RunTaskAsync = function (task)
export function RunTaskAsync (task)
{
setTimeout (() => {
task ();
}, 0);
};
}
OV.RunTasks = function (count, callbacks)
export function RunTasks (count, callbacks)
{
let taskRunner = new OV.TaskRunner ();
let taskRunner = new TaskRunner ();
taskRunner.Run (count, callbacks);
};
}
OV.RunTasksBatch = function (count, batchCount, callbacks)
export function RunTasksBatch (count, batchCount, callbacks)
{
let taskRunner = new OV.TaskRunner ();
let taskRunner = new TaskRunner ();
taskRunner.RunBatch (count, batchCount, callbacks);
};
}
OV.WaitWhile = function (expression)
export function WaitWhile (expression)
{
function Waiter (expression)
{
@ -85,4 +85,4 @@ OV.WaitWhile = function (expression)
}
}
Waiter (expression);
};
}

View File

@ -1,14 +1,22 @@
OV.Exporter = class
import { Exporter3dm } from './exporter3dm.js';
import { ExporterGltf } from './exportergltf.js';
import { ExporterModel } from './exportermodel.js';
import { ExporterObj } from './exporterobj.js';
import { ExporterOff } from './exporteroff.js';
import { ExporterPly } from './exporterply.js';
import { ExporterStl } from './exporterstl.js';
export class Exporter
{
constructor ()
{
this.exporters = [
new OV.ExporterObj (),
new OV.ExporterStl (),
new OV.ExporterPly (),
new OV.ExporterOff (),
new OV.ExporterGltf (),
new OV.Exporter3dm ()
new ExporterObj (),
new ExporterStl (),
new ExporterPly (),
new ExporterOff (),
new ExporterGltf (),
new Exporter3dm ()
];
}
@ -32,7 +40,7 @@ OV.Exporter = class
return;
}
let exporterModel = new OV.ExporterModel (model, settings);
let exporterModel = new ExporterModel (model, settings);
exporter.Export (exporterModel, format, (files) => {
if (files.length === 0) {
callbacks.onError ();
@ -41,4 +49,4 @@ OV.Exporter = class
}
});
}
};
}

View File

@ -1,4 +1,10 @@
OV.Exporter3dm = class extends OV.ExporterBase
import { LoadExternalLibrary } from '../io/externallibs.js';
import { FileFormat } from '../io/fileutils.js';
import { MaterialType } from '../model/material.js';
import { ConvertMeshToMeshBuffer } from '../model/meshbuffer.js';
import { ExportedFile, ExporterBase } from './exporterbase.js';
export class Exporter3dm extends ExporterBase
{
constructor ()
{
@ -8,13 +14,13 @@ OV.Exporter3dm = class extends OV.ExporterBase
CanExport (format, extension)
{
return format === OV.FileFormat.Binary && extension === '3dm';
return format === FileFormat.Binary && extension === '3dm';
}
ExportContent (exporterModel, format, files, onFinish)
{
if (this.rhino === null) {
OV.LoadExternalLibrary ('loaders/rhino3dm.min.js').then (() => {
LoadExternalLibrary ('loaders/rhino3dm.min.js').then (() => {
rhino3dm ().then ((rhino) => {
this.rhino = rhino;
this.ExportRhinoContent (exporterModel, files, onFinish);
@ -39,12 +45,12 @@ OV.Exporter3dm = class extends OV.ExporterBase
};
}
let rhinoFile = new OV.ExportedFile ('model.3dm');
let rhinoFile = new ExportedFile ('model.3dm');
files.push (rhinoFile);
let rhinoDoc = new this.rhino.File3dm ();
exporterModel.EnumerateTransformedMeshes ((mesh) => {
let meshBuffer = OV.ConvertMeshToMeshBuffer (mesh);
let meshBuffer = ConvertMeshToMeshBuffer (mesh);
for (let primitiveIndex = 0; primitiveIndex < meshBuffer.PrimitiveCount (); primitiveIndex++) {
let primitive = meshBuffer.GetPrimitive (primitiveIndex);
let threeJson = {
@ -71,7 +77,7 @@ OV.Exporter3dm = class extends OV.ExporterBase
let material = exporterModel.GetMaterial (primitive.material);
let rhinoMaterial = new this.rhino.Material ();
rhinoMaterial.name = this.GetExportedMaterialName (material.name);
if (material.type === OV.MaterialType.Phong) {
if (material.type === MaterialType.Phong) {
rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient);
rhinoMaterial.specularColor = ColorToRhinoColor (material.specular);
}
@ -97,4 +103,4 @@ OV.Exporter3dm = class extends OV.ExporterBase
rhinoFile.SetBufferContent (rhinoDocBuffer);
onFinish ();
}
};
}

View File

@ -1,4 +1,6 @@
OV.ExportedFile = class
import { ArrayBufferToUtf8String, Utf8StringToArrayBuffer } from '../io/bufferutils.js';
export class ExportedFile
{
constructor (name)
{
@ -18,7 +20,7 @@ OV.ExportedFile = class
GetTextContent ()
{
let text = OV.ArrayBufferToUtf8String (this.content);
let text = ArrayBufferToUtf8String (this.content);
return text;
}
@ -29,7 +31,7 @@ OV.ExportedFile = class
SetTextContent (content)
{
let buffer = OV.Utf8StringToArrayBuffer (content);
let buffer = Utf8StringToArrayBuffer (content);
this.content = buffer;
}
@ -37,9 +39,9 @@ OV.ExportedFile = class
{
this.content = content;
}
};
}
OV.ExporterBase = class
export class ExporterBase
{
constructor ()
{
@ -81,4 +83,4 @@ OV.ExporterBase = class
}
return originalName;
}
};
}

View File

@ -1,4 +1,12 @@
OV.ExporterGltf = class extends OV.ExporterBase
import { BinaryWriter } from '../io/binarywriter.js';
import { Utf8StringToArrayBuffer } from '../io/bufferutils.js';
import { FileFormat, GetFileExtension, GetFileName } from '../io/fileutils.js';
import { Color, SRGBToLinear } from '../model/color.js';
import { MaterialType } from '../model/material.js';
import { ConvertMeshToMeshBuffer } from '../model/meshbuffer.js';
import { ExportedFile, ExporterBase } from './exporterbase.js';
export class ExporterGltf extends ExporterBase
{
constructor ()
{
@ -17,14 +25,14 @@ OV.ExporterGltf = class extends OV.ExporterBase
CanExport (format, extension)
{
return (format === OV.FileFormat.Text && extension === 'gltf') || (format === OV.FileFormat.Binary && extension === 'glb');
return (format === FileFormat.Text && extension === 'gltf') || (format === FileFormat.Binary && extension === 'glb');
}
ExportContent (exporterModel, format, files, onFinish)
{
if (format === OV.FileFormat.Text) {
if (format === FileFormat.Text) {
this.ExportAsciiContent (exporterModel, files);
} else if (format === OV.FileFormat.Binary) {
} else if (format === FileFormat.Binary) {
this.ExportBinaryContent (exporterModel, files);
}
onFinish ();
@ -32,8 +40,8 @@ OV.ExporterGltf = class extends OV.ExporterBase
ExportAsciiContent (exporterModel, files)
{
let gltfFile = new OV.ExportedFile ('model.gltf');
let binFile = new OV.ExportedFile ('model.bin');
let gltfFile = new ExportedFile ('model.gltf');
let binFile = new ExportedFile ('model.bin');
files.push (gltfFile);
files.push (binFile);
@ -47,11 +55,11 @@ OV.ExporterGltf = class extends OV.ExporterBase
let fileNameToIndex = new Map ();
this.ExportMaterials (exporterModel, mainJson, (texture) => {
let fileName = OV.GetFileName (texture.name);
let fileName = GetFileName (texture.name);
if (fileNameToIndex.has (fileName)) {
return fileNameToIndex.get (fileName);
} else {
let textureFile = new OV.ExportedFile (fileName);
let textureFile = new ExportedFile (fileName);
textureFile.SetBufferContent (texture.buffer);
files.push (textureFile);
@ -92,7 +100,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
}
}
let glbFile = new OV.ExportedFile ('model.glb');
let glbFile = new ExportedFile ('model.glb');
files.push (glbFile);
let meshDataArr = this.GetMeshData (exporterModel);
@ -104,8 +112,8 @@ OV.ExporterGltf = class extends OV.ExporterBase
let fileNameToIndex = new Map ();
this.ExportMaterials (exporterModel, mainJson, (texture) => {
let fileName = OV.GetFileName (texture.name);
let extension = OV.GetFileExtension (texture.name);
let fileName = GetFileName (texture.name);
let extension = GetFileExtension (texture.name);
if (fileNameToIndex.has (fileName)) {
return fileNameToIndex.get (fileName);
} else {
@ -143,12 +151,12 @@ OV.ExporterGltf = class extends OV.ExporterBase
});
let mainJsonString = JSON.stringify (mainJson);
let mainJsonBuffer = OV.Utf8StringToArrayBuffer (mainJsonString);
let mainJsonBuffer = Utf8StringToArrayBuffer (mainJsonString);
let mainJsonBufferLength = mainJsonBuffer.byteLength;
let mainJsonBufferAlignedLength = AlignToBoundary (mainJsonBufferLength);
let glbSize = 12 + 8 + mainJsonBufferAlignedLength + 8 + mainBinaryBufferAlignedLength;
let glbWriter = new OV.BinaryWriter (glbSize, true);
let glbWriter = new BinaryWriter (glbSize, true);
glbWriter.WriteUnsignedInteger32 (0x46546C67);
glbWriter.WriteUnsignedInteger32 (2);
@ -177,7 +185,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
let meshDataArr = [];
exporterModel.EnumerateTransformedMeshes ((mesh) => {
let buffer = OV.ConvertMeshToMeshBuffer (mesh);
let buffer = ConvertMeshToMeshBuffer (mesh);
meshDataArr.push ({
name : mesh.GetName (),
buffer : buffer,
@ -197,7 +205,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
mainBufferSize += meshData.buffer.GetByteLength (this.components.index.size, this.components.number.size);
}
let writer = new OV.BinaryWriter (mainBufferSize, true);
let writer = new BinaryWriter (mainBufferSize, true);
for (let meshIndex = 0; meshIndex < meshDataArr.length; meshIndex++) {
let meshData = meshDataArr[meshIndex];
for (let primitiveIndex = 0; primitiveIndex < meshData.buffer.PrimitiveCount (); primitiveIndex++) {
@ -210,7 +218,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
writer.WriteFloat32 (primitive.vertices[i]);
}
for (let i = 0; i < primitive.colors.length; i++) {
writer.WriteFloat32 (OV.SRGBToLinear (primitive.colors[i]));
writer.WriteFloat32 (SRGBToLinear (primitive.colors[i]));
}
for (let i = 0; i < primitive.normals.length; i++) {
writer.WriteFloat32 (primitive.normals[i]);
@ -373,9 +381,9 @@ OV.ExporterGltf = class extends OV.ExporterBase
function ColorToRGBA (color, opacity)
{
return [
OV.SRGBToLinear (color.r / 255.0),
OV.SRGBToLinear (color.g / 255.0),
OV.SRGBToLinear (color.b / 255.0),
SRGBToLinear (color.r / 255.0),
SRGBToLinear (color.g / 255.0),
SRGBToLinear (color.b / 255.0),
opacity
];
}
@ -383,9 +391,9 @@ OV.ExporterGltf = class extends OV.ExporterBase
function ColorToRGB (color)
{
return [
OV.SRGBToLinear (color.r / 255.0),
OV.SRGBToLinear (color.g / 255.0),
OV.SRGBToLinear (color.b / 255.0)
SRGBToLinear (color.r / 255.0),
SRGBToLinear (color.g / 255.0),
SRGBToLinear (color.b / 255.0)
];
}
@ -445,11 +453,11 @@ OV.ExporterGltf = class extends OV.ExporterBase
let baseColorTexture = GetTextureParams (mainJson, material.diffuseMap, addTexture);
if (baseColorTexture !== null) {
if (!material.multiplyDiffuseMap) {
jsonMaterial.pbrMetallicRoughness.baseColorFactor = ColorToRGBA (new OV.Color (255, 255, 255), material.opacity);
jsonMaterial.pbrMetallicRoughness.baseColorFactor = ColorToRGBA (new Color (255, 255, 255), material.opacity);
}
jsonMaterial.pbrMetallicRoughness.baseColorTexture = baseColorTexture;
}
if (material.type === OV.MaterialType.Physical) {
if (material.type === MaterialType.Physical) {
let metallicTexture = GetTextureParams (mainJson, material.metalnessMap, addTexture);
if (metallicTexture !== null) {
jsonMaterial.pbrMetallicRoughness.metallicRoughnessTexture = metallicTexture;
@ -475,4 +483,4 @@ OV.ExporterGltf = class extends OV.ExporterBase
ExportMaterial (this, mainJson, material, addTexture);
}
}
};
}

View File

@ -1,22 +1,26 @@
OV.ExporterSettings = class
import { CopyObjectAttributes } from '../core/core.js';
import { Transformation } from '../geometry/transformation.js';
import { CalculateTriangleNormal, TransformMesh } from '../model/meshutils.js';
export class ExporterSettings
{
constructor (settings)
{
this.transformation = new OV.Transformation ();
this.transformation = new Transformation ();
this.isMeshVisible = (meshInstanceId) => {
return true;
};
OV.CopyObjectAttributes (settings, this);
CopyObjectAttributes (settings, this);
}
};
}
OV.ExporterModel = class
export class ExporterModel
{
constructor (model, settings)
{
this.model = model;
this.settings = settings || new OV.ExporterSettings ();
this.settings = settings || new ExporterSettings ();
}
MaterialCount ()
@ -76,7 +80,7 @@ OV.ExporterModel = class
let mesh = meshInstance.GetMesh ();
let transformed = mesh.Clone ();
if (!transformation.IsIdentity ()) {
OV.TransformMesh (transformed, transformation);
TransformMesh (transformed, transformation);
}
onMesh (transformed);
@ -109,9 +113,9 @@ OV.ExporterModel = class
{
this.EnumerateTransformedMeshes ((mesh) => {
mesh.EnumerateTriangleVertices ((v0, v1, v2) => {
let normal = OV.CalculateTriangleNormal (v0, v1, v2);
let normal = CalculateTriangleNormal (v0, v1, v2);
onTriangle (v0, v1, v2, normal);
});
});
}
};
}

View File

@ -1,4 +1,9 @@
OV.ExporterObj = class extends OV.ExporterBase
import { FileFormat, GetFileName } from '../io/fileutils.js';
import { TextWriter } from '../io/textwriter.js';
import { MaterialType } from '../model/material.js';
import { ExportedFile, ExporterBase } from './exporterbase.js';
export class ExporterObj extends ExporterBase
{
constructor ()
{
@ -7,7 +12,7 @@ OV.ExporterObj = class extends OV.ExporterBase
CanExport (format, extension)
{
return format === OV.FileFormat.Text && extension === 'obj';
return format === FileFormat.Text && extension === 'obj';
}
ExportContent (exporterModel, format, files, onFinish)
@ -17,46 +22,46 @@ OV.ExporterObj = class extends OV.ExporterBase
if (texture === null || !texture.IsValid ()) {
return;
}
let fileName = OV.GetFileName (texture.name);
let fileName = GetFileName (texture.name);
mtlWriter.WriteArrayLine ([keyword, fileName]);
let fileIndex = files.findIndex ((file) => {
return file.GetName () === fileName;
});
if (fileIndex === -1) {
let textureFile = new OV.ExportedFile (fileName);
let textureFile = new ExportedFile (fileName);
textureFile.SetBufferContent (texture.buffer);
files.push (textureFile);
}
}
let mtlFile = new OV.ExportedFile ('model.mtl');
let objFile = new OV.ExportedFile ('model.obj');
let mtlFile = new ExportedFile ('model.mtl');
let objFile = new ExportedFile ('model.obj');
files.push (mtlFile);
files.push (objFile);
let mtlWriter = new OV.TextWriter ();
let mtlWriter = new TextWriter ();
mtlWriter.WriteLine (this.GetHeaderText ());
for (let materialIndex = 0; materialIndex < exporterModel.MaterialCount (); materialIndex++) {
let material = exporterModel.GetMaterial (materialIndex);
mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]);
mtlWriter.WriteArrayLine (['Kd', material.color.r / 255.0, material.color.g / 255.0, material.color.b / 255.0]);
mtlWriter.WriteArrayLine (['d', material.opacity]);
if (material.type === OV.MaterialType.Phong) {
if (material.type === MaterialType.Phong) {
mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]);
mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]);
mtlWriter.WriteArrayLine (['Ns', material.shininess * 1000.0]);
}
WriteTexture (mtlWriter, 'map_Kd', material.diffuseMap, files);
if (material.type === OV.MaterialType.Phong) {
if (material.type === MaterialType.Phong) {
WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files);
}
WriteTexture (mtlWriter, 'bump', material.bumpMap, files);
}
mtlFile.SetTextContent (mtlWriter.GetText ());
let objWriter = new OV.TextWriter ();
let objWriter = new TextWriter ();
objWriter.WriteLine (this.GetHeaderText ());
objWriter.WriteArrayLine (['mtllib', mtlFile.GetName ()]);
let vertexOffset = 0;
@ -116,4 +121,4 @@ OV.ExporterObj = class extends OV.ExporterBase
{
return '# exported by https://3dviewer.net';
}
};
}

View File

@ -1,4 +1,8 @@
OV.ExporterOff = class extends OV.ExporterBase
import { FileFormat } from '../io/fileutils.js';
import { TextWriter } from '../io/textwriter.js';
import { ExportedFile, ExporterBase } from './exporterbase.js';
export class ExporterOff extends ExporterBase
{
constructor ()
{
@ -7,15 +11,15 @@ OV.ExporterOff = class extends OV.ExporterBase
CanExport (format, extension)
{
return format === OV.FileFormat.Text && extension === 'off';
return format === FileFormat.Text && extension === 'off';
}
ExportContent (exporterModel, format, files, onFinish)
{
let offFile = new OV.ExportedFile ('model.off');
let offFile = new ExportedFile ('model.off');
files.push (offFile);
let offWriter = new OV.TextWriter ();
let offWriter = new TextWriter ();
offWriter.WriteLine ('OFF');
offWriter.WriteArrayLine ([exporterModel.VertexCount (), exporterModel.TriangleCount (), 0]);
@ -31,4 +35,4 @@ OV.ExporterOff = class extends OV.ExporterBase
offFile.SetTextContent (offWriter.GetText ());
onFinish ();
}
};
}

View File

@ -1,4 +1,9 @@
OV.ExporterPly = class extends OV.ExporterBase
import { BinaryWriter } from '../io/binarywriter.js';
import { FileFormat } from '../io/fileutils.js';
import { TextWriter } from '../io/textwriter.js';
import { ExportedFile, ExporterBase } from './exporterbase.js';
export class ExporterPly extends ExporterBase
{
constructor ()
{
@ -7,12 +12,12 @@ OV.ExporterPly = class extends OV.ExporterBase
CanExport (format, extension)
{
return (format === OV.FileFormat.Text || format === OV.FileFormat.Binary) && extension === 'ply';
return (format === FileFormat.Text || format === FileFormat.Binary) && extension === 'ply';
}
ExportContent (exporterModel, format, files, onFinish)
{
if (format === OV.FileFormat.Text) {
if (format === FileFormat.Text) {
this.ExportText (exporterModel, files);
} else {
this.ExportBinary (exporterModel, files);
@ -22,10 +27,10 @@ OV.ExporterPly = class extends OV.ExporterBase
ExportText (exporterModel, files)
{
let plyFile = new OV.ExportedFile ('model.ply');
let plyFile = new ExportedFile ('model.ply');
files.push (plyFile);
let plyWriter = new OV.TextWriter ();
let plyWriter = new TextWriter ();
let vertexCount = exporterModel.VertexCount ();
let triangleCount = exporterModel.TriangleCount ();
@ -46,7 +51,7 @@ OV.ExporterPly = class extends OV.ExporterBase
ExportBinary (exporterModel, files)
{
let plyFile = new OV.ExportedFile ('model.ply');
let plyFile = new ExportedFile ('model.ply');
files.push (plyFile);
let vertexCount = exporterModel.VertexCount ();
@ -54,7 +59,7 @@ OV.ExporterPly = class extends OV.ExporterBase
let headerText = this.GetHeaderText ('binary_little_endian', vertexCount, triangleCount);
let fullByteLength = headerText.length + vertexCount * 3 * 4 + triangleCount * (1 + 3 * 4);
let plyWriter = new OV.BinaryWriter (fullByteLength, true);
let plyWriter = new BinaryWriter (fullByteLength, true);
for (let i = 0; i < headerText.length; i++) {
plyWriter.WriteUnsignedCharacter8 (headerText.charCodeAt (i));
@ -79,7 +84,7 @@ OV.ExporterPly = class extends OV.ExporterBase
GetHeaderText (format, vertexCount, triangleCount)
{
let headerWriter = new OV.TextWriter ();
let headerWriter = new TextWriter ();
headerWriter.WriteLine ('ply');
headerWriter.WriteLine ('format ' + format + ' 1.0');
headerWriter.WriteLine ('element vertex ' + vertexCount);
@ -91,4 +96,4 @@ OV.ExporterPly = class extends OV.ExporterBase
headerWriter.WriteLine ('end_header');
return headerWriter.GetText ();
}
};
}

View File

@ -1,4 +1,9 @@
OV.ExporterStl = class extends OV.ExporterBase
import { BinaryWriter } from '../io/binarywriter.js';
import { FileFormat } from '../io/fileutils.js';
import { TextWriter } from '../io/textwriter.js';
import { ExportedFile, ExporterBase } from './exporterbase.js';
export class ExporterStl extends ExporterBase
{
constructor ()
{
@ -7,12 +12,12 @@ OV.ExporterStl = class extends OV.ExporterBase
CanExport (format, extension)
{
return (format === OV.FileFormat.Text || format === OV.FileFormat.Binary) && extension === 'stl';
return (format === FileFormat.Text || format === FileFormat.Binary) && extension === 'stl';
}
ExportContent (exporterModel, format, files, onFinish)
{
if (format === OV.FileFormat.Text) {
if (format === FileFormat.Text) {
this.ExportText (exporterModel, files);
} else {
this.ExportBinary (exporterModel, files);
@ -22,10 +27,10 @@ OV.ExporterStl = class extends OV.ExporterBase
ExportText (exporterModel, files)
{
let stlFile = new OV.ExportedFile ('model.stl');
let stlFile = new ExportedFile ('model.stl');
files.push (stlFile);
let stlWriter = new OV.TextWriter ();
let stlWriter = new TextWriter ();
stlWriter.WriteLine ('solid Model');
exporterModel.EnumerateTrianglesWithNormals ((v0, v1, v2, normal) => {
stlWriter.WriteArrayLine (['facet', 'normal', normal.x, normal.y, normal.z]);
@ -47,13 +52,13 @@ OV.ExporterStl = class extends OV.ExporterBase
ExportBinary (exporterModel, files)
{
let stlFile = new OV.ExportedFile ('model.stl');
let stlFile = new ExportedFile ('model.stl');
files.push (stlFile);
let triangleCount = exporterModel.TriangleCount ();
let headerSize = 80;
let fullByteLength = headerSize + 4 + triangleCount * 50;
let stlWriter = new OV.BinaryWriter (fullByteLength, true);
let stlWriter = new BinaryWriter (fullByteLength, true);
for (let i = 0; i < headerSize; i++) {
stlWriter.WriteUnsignedCharacter8 (0);
@ -82,4 +87,4 @@ OV.ExporterStl = class extends OV.ExporterBase
stlFile.SetBufferContent (stlWriter.GetBuffer ());
}
};
}

View File

@ -1,4 +1,6 @@
OV.Box3D = class
import { Coord3D } from './coord3d.js';
export class Box3D
{
constructor (min, max)
{
@ -18,21 +20,21 @@ OV.Box3D = class
GetCenter ()
{
return new OV.Coord3D (
return new Coord3D (
(this.min.x + this.max.x) / 2.0,
(this.min.y + this.max.y) / 2.0,
(this.min.z + this.max.z) / 2.0
);
}
};
}
OV.BoundingBoxCalculator3D = class
export class BoundingBoxCalculator3D
{
constructor ()
{
this.box = new OV.Box3D (
new OV.Coord3D (Infinity, Infinity, Infinity),
new OV.Coord3D (-Infinity, -Infinity, -Infinity)
this.box = new Box3D (
new Coord3D (Infinity, Infinity, Infinity),
new Coord3D (-Infinity, -Infinity, -Infinity)
);
this.isValid = false;
}
@ -55,4 +57,4 @@ OV.BoundingBoxCalculator3D = class
this.box.max.z = Math.max (this.box.max.z, point.z);
this.isValid = true;
}
};
}

View File

@ -0,0 +1,35 @@
import { IsEqual } from './geometry.js';
export class Coord2D
{
constructor (x, y)
{
this.x = x;
this.y = y;
}
Clone ()
{
return new Coord2D (this.x, this.y);
}
}
export function CoordIsEqual2D (a, b)
{
return IsEqual (a.x, b.x) && IsEqual (a.y, b.y);
}
export function AddCoord2D (a, b)
{
return new Coord2D (a.x + b.x, a.y + b.y);
}
export function SubCoord2D (a, b)
{
return new Coord2D (a.x - b.x, a.y - b.y);
}
export function CoordDistance2D (a, b)
{
return Math.sqrt ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

View File

@ -1,4 +1,6 @@
OV.Coord3D = class
import { IsEqual } from './geometry.js';
export class Coord3D
{
constructor (x, y, z)
{
@ -64,61 +66,61 @@ OV.Coord3D = class
Clone ()
{
return new OV.Coord3D (this.x, this.y, this.z);
return new Coord3D (this.x, this.y, this.z);
}
};
}
OV.CoordIsEqual3D = function (a, b)
export function CoordIsEqual3D (a, b)
{
return OV.IsEqual (a.x, b.x) && OV.IsEqual (a.y, b.y) && OV.IsEqual (a.z, b.z);
};
return IsEqual (a.x, b.x) && IsEqual (a.y, b.y) && IsEqual (a.z, b.z);
}
OV.AddCoord3D = function (a, b)
export function AddCoord3D (a, b)
{
return new OV.Coord3D (a.x + b.x, a.y + b.y, a.z + b.z);
};
return new Coord3D (a.x + b.x, a.y + b.y, a.z + b.z);
}
OV.SubCoord3D = function (a, b)
export function SubCoord3D (a, b)
{
return new OV.Coord3D (a.x - b.x, a.y - b.y, a.z - b.z);
};
return new Coord3D (a.x - b.x, a.y - b.y, a.z - b.z);
}
OV.CoordDistance3D = function (a, b)
export function CoordDistance3D (a, b)
{
return Math.sqrt ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
};
}
OV.VectorAngle3D = function (a, b)
export function DotVector3D (a, b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
export function VectorAngle3D (a, b)
{
let aDirection = a.Clone ().Normalize ();
let bDirection = b.Clone ().Normalize ();
if (OV.CoordIsEqual3D (aDirection, bDirection)) {
if (CoordIsEqual3D (aDirection, bDirection)) {
return 0.0;
}
let product = OV.DotVector3D (aDirection, bDirection);
let product = DotVector3D (aDirection, bDirection);
return Math.acos (product);
};
}
OV.DotVector3D = function (a, b)
export function CrossVector3D (a, b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
};
OV.CrossVector3D = function (a, b)
{
let result = new OV.Coord3D (0.0, 0.0, 0.0);
let result = new Coord3D (0.0, 0.0, 0.0);
result.x = a.y * b.z - a.z * b.y;
result.y = a.z * b.x - a.x * b.z;
result.z = a.x * b.y - a.y * b.x;
return result;
};
}
OV.VectorLength3D = function (x, y, z)
export function VectorLength3D (x, y, z)
{
return Math.sqrt (x * x + y * y + z * z);
};
}
OV.ArrayToCoord3D = function (arr)
export function ArrayToCoord3D (arr)
{
return new OV.Coord3D (arr[0], arr[1], arr[2]);
};
return new Coord3D (arr[0], arr[1], arr[2]);
}

View File

@ -1,4 +1,4 @@
OV.Coord4D = class
export class Coord4D
{
constructor (x, y, z, w)
{
@ -10,6 +10,6 @@ OV.Coord4D = class
Clone ()
{
return new OV.Coord4D (this.x, this.y, this.z, this.w);
return new Coord4D (this.x, this.y, this.z, this.w);
}
};
}

View File

@ -0,0 +1,56 @@
export const Eps = 0.00000001;
export const BigEps = 0.0001;
export const RadDeg = 57.29577951308232;
export const DegRad = 0.017453292519943;
export function IsZero (a)
{
return Math.abs (a) < Eps;
}
export function IsLower (a, b)
{
return b - a > Eps;
}
export function IsGreater (a, b)
{
return a - b > Eps;
}
export function IsLowerOrEqual (a, b)
{
return b - a > -Eps;
}
export function IsGreaterOrEqual (a, b)
{
return a - b > -Eps;
}
export function IsEqual (a, b)
{
return Math.abs (b - a) < Eps;
}
export function IsEqualEps (a, b, eps)
{
return Math.abs (b - a) < eps;
}
export function IsPositive (a)
{
return a > Eps;
}
export function IsNegative (a)
{
return a < -Eps;
}
export const Direction =
{
X : 1,
Y : 2,
Z : 3
};

View File

@ -1,4 +1,9 @@
OV.Matrix = class
import { Quaternion } from './quaternion.js';
import { Coord3D, VectorLength3D } from './coord3d.js';
import { IsEqual, IsNegative } from './geometry.js';
import { QuaternionFromAxisAngle } from './quaternion.js';
export class Matrix
{
constructor (matrix)
{
@ -32,7 +37,7 @@ OV.Matrix = class
this.matrix[8], this.matrix[9], this.matrix[10], this.matrix[11],
this.matrix[12], this.matrix[13], this.matrix[14], this.matrix[15]
];
return new OV.Matrix (result);
return new Matrix (result);
}
CreateIdentity ()
@ -48,9 +53,9 @@ OV.Matrix = class
IsIdentity ()
{
let identity = new OV.Matrix ().CreateIdentity ().Get ();
let identity = new Matrix ().CreateIdentity ().Get ();
for (let i = 0; i < 16; i++) {
if (!OV.IsEqual (this.matrix[i], identity[i])) {
if (!IsEqual (this.matrix[i], identity[i])) {
return false;
}
}
@ -93,7 +98,7 @@ OV.Matrix = class
CreateRotationAxisAngle (axis, angle)
{
let quaternion = OV.QuaternionFromAxisAngle (axis, angle);
let quaternion = QuaternionFromAxisAngle (axis, angle);
return this.CreateRotation (quaternion.x, quaternion.y, quaternion.z, quaternion.w);
}
@ -145,20 +150,20 @@ OV.Matrix = class
DecomposeTRS ()
{
let translation = new OV.Coord3D (
let translation = new Coord3D (
this.matrix[12],
this.matrix[13],
this.matrix[14]
);
let sx = OV.VectorLength3D (this.matrix[0], this.matrix[1], this.matrix[2]);
let sy = OV.VectorLength3D (this.matrix[4], this.matrix[5], this.matrix[6]);
let sz = OV.VectorLength3D (this.matrix[8], this.matrix[9], this.matrix[10]);
let sx = VectorLength3D (this.matrix[0], this.matrix[1], this.matrix[2]);
let sy = VectorLength3D (this.matrix[4], this.matrix[5], this.matrix[6]);
let sz = VectorLength3D (this.matrix[8], this.matrix[9], this.matrix[10]);
let determinant = this.Determinant ();
if (OV.IsNegative (determinant)) {
if (IsNegative (determinant)) {
sx *= -1.0;
}
let scale = new OV.Coord3D (sx, sy, sz);
let scale = new Coord3D (sx, sy, sz);
let m00 = this.matrix[0] / sx;
let m01 = this.matrix[4] / sy;
@ -175,7 +180,7 @@ OV.Matrix = class
let tr = m00 + m11 + m22;
if (tr > 0.0) {
let s = Math.sqrt (tr + 1.0) * 2.0;
rotation = new OV.Quaternion (
rotation = new Quaternion (
(m21 - m12) / s,
(m02 - m20) / s,
(m10 - m01) / s,
@ -183,7 +188,7 @@ OV.Matrix = class
);
} else if ((m00 > m11) && (m00 > m22)) {
let s = Math.sqrt (1.0 + m00 - m11 - m22) * 2.0;
rotation = new OV.Quaternion (
rotation = new Quaternion (
0.25 * s,
(m01 + m10) / s,
(m02 + m20) / s,
@ -191,7 +196,7 @@ OV.Matrix = class
);
} else if (m11 > m22) {
let s = Math.sqrt (1.0 + m11 - m00 - m22) * 2.0;
rotation = new OV.Quaternion (
rotation = new Quaternion (
(m01 + m10) / s,
0.25 * s,
(m12 + m21) / s,
@ -199,7 +204,7 @@ OV.Matrix = class
);
} else {
let s = Math.sqrt (1.0 + m22 - m00 - m11) * 2.0;
rotation = new OV.Quaternion (
rotation = new Quaternion (
(m02 + m20) / s,
(m12 + m21) / s,
0.25 * s,
@ -283,7 +288,7 @@ OV.Matrix = class
let b11 = a22 * a33 - a23 * a32;
let determinant = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (OV.IsEqual (determinant, 0.0)) {
if (IsEqual (determinant, 0.0)) {
return null;
}
@ -306,7 +311,7 @@ OV.Matrix = class
(a20 * b03 - a21 * b01 + a22 * b00) / determinant
];
return new OV.Matrix (result);
return new Matrix (result);
}
MultiplyVector (vector)
@ -397,18 +402,18 @@ OV.Matrix = class
a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33
];
return new OV.Matrix (result);
return new Matrix (result);
}
};
}
OV.MatrixIsEqual = function (a, b)
export function MatrixIsEqual (a, b)
{
const aMatrix = a.Get ();
const bMatrix = b.Get ();
for (let i = 0; i < 16; i++) {
if (!OV.IsEqual (aMatrix[i], bMatrix[i])) {
if (!IsEqual (aMatrix[i], bMatrix[i])) {
return false;
}
}
return true;
};
}

View File

@ -1,4 +1,8 @@
OV.OctreeNode = class
import { Box3D } from './box3d.js';
import { Coord3D, CoordIsEqual3D } from './coord3d.js';
import { IsGreaterOrEqual, IsLowerOrEqual } from './geometry.js';
export class OctreeNode
{
constructor (boundingBox, level)
{
@ -57,7 +61,7 @@ OV.OctreeNode = class
{
for (let i = 0; i < this.pointItems.length; i++) {
let pointItem = this.pointItems[i];
if (OV.CoordIsEqual3D (point, pointItem.point)) {
if (CoordIsEqual3D (point, pointItem.point)) {
return pointItem.data;
}
}
@ -89,11 +93,11 @@ OV.OctreeNode = class
{
function AddChildNode (node, minX, minY, minZ, sizeX, sizeY, sizeZ)
{
let box = new OV.Box3D (
new OV.Coord3D (minX, minY, minZ),
new OV.Coord3D (minX + sizeX, minY + sizeY, minZ + sizeZ)
let box = new Box3D (
new Coord3D (minX, minY, minZ),
new Coord3D (minX + sizeX, minY + sizeY, minZ + sizeZ)
);
node.childNodes.push (new OV.OctreeNode (box, node.level + 1, node.options));
node.childNodes.push (new OctreeNode (box, node.level + 1, node.options));
}
let min = this.boundingBox.min;
@ -115,17 +119,17 @@ OV.OctreeNode = class
IsPointInBounds (point)
{
let isEqual =
OV.IsGreaterOrEqual (point.x, this.boundingBox.min.x) &&
OV.IsGreaterOrEqual (point.y, this.boundingBox.min.y) &&
OV.IsGreaterOrEqual (point.z, this.boundingBox.min.z) &&
OV.IsLowerOrEqual (point.x, this.boundingBox.max.x) &&
OV.IsLowerOrEqual (point.y, this.boundingBox.max.y) &&
OV.IsLowerOrEqual (point.z, this.boundingBox.max.z);
IsGreaterOrEqual (point.x, this.boundingBox.min.x) &&
IsGreaterOrEqual (point.y, this.boundingBox.min.y) &&
IsGreaterOrEqual (point.z, this.boundingBox.min.z) &&
IsLowerOrEqual (point.x, this.boundingBox.max.x) &&
IsLowerOrEqual (point.y, this.boundingBox.max.y) &&
IsLowerOrEqual (point.z, this.boundingBox.max.z);
return isEqual;
}
};
}
OV.Octree = class
export class Octree
{
constructor (boundingBox, options)
{
@ -141,7 +145,7 @@ OV.Octree = class
this.options.maxTreeDepth = options.maxTreeDepth;
}
}
this.rootNode = new OV.OctreeNode (boundingBox, 0, this.options);
this.rootNode = new OctreeNode (boundingBox, 0, this.options);
}
AddPoint (point, data)
@ -153,4 +157,4 @@ OV.Octree = class
{
return this.rootNode.FindPoint (point);
}
};
}

View File

@ -1,4 +1,4 @@
OV.Quaternion = class
export class Quaternion
{
constructor (x, y, z, w)
{
@ -7,22 +7,22 @@ OV.Quaternion = class
this.z = z;
this.w = w;
}
};
}
OV.ArrayToQuaternion = function (arr)
export function ArrayToQuaternion (arr)
{
return new OV.Quaternion (arr[0], arr[1], arr[2], arr[3]);
};
return new Quaternion (arr[0], arr[1], arr[2], arr[3]);
}
OV.QuaternionFromAxisAngle = function (axis, angle)
export function QuaternionFromAxisAngle (axis, angle)
{
const a = angle / 2.0;
const s = Math.sin (a);
return new OV.Quaternion (
return new Quaternion (
axis.x * s,
axis.y * s,
axis.z * s,
Math.cos (a)
);
};
}

View File

@ -1,11 +1,14 @@
OV.Transformation = class
import { Coord3D } from './coord3d.js';
import { Matrix, MatrixIsEqual } from './matrix.js';
export class Transformation
{
constructor (matrix)
{
if (matrix !== undefined && matrix !== null) {
this.matrix = matrix;
} else {
this.matrix = new OV.Matrix ();
this.matrix = new Matrix ();
this.matrix.CreateIdentity ();
}
}
@ -41,18 +44,18 @@ OV.Transformation = class
TransformCoord3D (coord)
{
let resultVector = this.matrix.MultiplyVector ([coord.x, coord.y, coord.z, 1.0]);
let result = new OV.Coord3D (resultVector[0], resultVector[1], resultVector[2]);
let result = new Coord3D (resultVector[0], resultVector[1], resultVector[2]);
return result;
}
Clone ()
{
const clonedMatrix = this.matrix.Clone ();
return new OV.Transformation (clonedMatrix);
return new Transformation (clonedMatrix);
}
};
}
OV.TransformationIsEqual = function (a, b)
export function TransformationIsEqual (a, b)
{
return OV.MatrixIsEqual (a.GetMatrix (), b.GetMatrix ());
};
return MatrixIsEqual (a.GetMatrix (), b.GetMatrix ());
}

View File

@ -1,29 +1,31 @@
OV.BezierTweenFunction = function (distance, index, count)
import { CoordDistance3D, SubCoord3D } from './coord3d.js';
export function BezierTweenFunction (distance, index, count)
{
let t = index / count;
return distance * (t * t * (3.0 - 2.0 * t));
};
}
OV.LinearTweenFunction = function (distance, index, count)
export function LinearTweenFunction (distance, index, count)
{
return index * distance / count;
};
}
OV.ParabolicTweenFunction = function (distance, index, count)
export function ParabolicTweenFunction (distance, index, count)
{
let t = index / count;
let t2 = t * t;
return distance * (t2 / (2.0 * (t2 - t) + 1.0));
};
}
OV.TweenCoord3D = function (a, b, count, tweenFunc)
export function TweenCoord3D (a, b, count, tweenFunc)
{
let dir = OV.SubCoord3D (b, a).Normalize ();
let distance = OV.CoordDistance3D (a, b);
let dir = SubCoord3D (b, a).Normalize ();
let distance = CoordDistance3D (a, b);
let result = [];
for (let i = 0; i < count; i++) {
let step = tweenFunc (distance, i, count - 1);
result.push (a.Clone ().Offset (dir, step));
}
return result;
};
}

View File

@ -1,23 +1,26 @@
OV.File = class
import { RunTasks } from '../core/taskrunner.js';
import { FileFormat, FileSource, GetFileExtension, GetFileName, ReadFile, RequestUrl } from '../io/fileutils.js';
export class File
{
constructor (file, source)
{
this.source = source;
if (source === OV.FileSource.Url) {
if (source === FileSource.Url) {
this.fileUrl = file;
this.fileObject = null;
this.name = OV.GetFileName (file);
this.extension = OV.GetFileExtension (file);
} else if (source === OV.FileSource.File) {
this.name = GetFileName (file);
this.extension = GetFileExtension (file);
} else if (source === FileSource.File) {
this.fileUrl = null;
this.fileObject = file;
this.name = OV.GetFileName (file.name);
this.extension = OV.GetFileExtension (file.name);
} else if (source === OV.FileSource.Decompressed) {
this.name = GetFileName (file.name);
this.extension = GetFileExtension (file.name);
} else if (source === FileSource.Decompressed) {
this.fileUrl = null;
this.fileObject = null;
this.name = OV.GetFileName (file);
this.extension = OV.GetFileExtension (file);
this.name = GetFileName (file);
this.extension = GetFileExtension (file);
}
this.content = null;
}
@ -26,9 +29,9 @@ OV.File = class
{
this.content = content;
}
};
}
OV.FileList = class
export class FileList
{
constructor ()
{
@ -37,12 +40,12 @@ OV.FileList = class
FillFromFileUrls (fileList)
{
this.Fill (fileList, OV.FileSource.Url);
this.Fill (fileList, FileSource.Url);
}
FillFromFileObjects (fileList)
{
this.Fill (fileList, OV.FileSource.File);
this.Fill (fileList, FileSource.File);
}
ExtendFromFileList (files)
@ -62,7 +65,7 @@ OV.FileList = class
GetContent (onReady)
{
OV.RunTasks (this.files.length, {
RunTasks (this.files.length, {
runTask : (index, complete) => {
this.GetFileContent (this.files[index], complete);
},
@ -77,7 +80,7 @@ OV.FileList = class
FindFileByPath (filePath)
{
let fileName = OV.GetFileName (filePath).toLowerCase ();
let fileName = GetFileName (filePath).toLowerCase ();
for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) {
let file = this.files[fileIndex];
if (file.name.toLowerCase () === fileName) {
@ -94,7 +97,7 @@ OV.FileList = class
}
for (let i = 0; i < this.files.length; i++) {
let file = this.files[i];
if (file.source !== OV.FileSource.Url && file.source !== OV.FileSource.Decompressed) {
if (file.source !== FileSource.Url && file.source !== FileSource.Decompressed) {
return false;
}
}
@ -106,7 +109,7 @@ OV.FileList = class
this.files = [];
for (let fileIndex = 0; fileIndex < fileList.length; fileIndex++) {
let fileObject = fileList[fileIndex];
let file = new OV.File (fileObject, fileSource);
let file = new File (fileObject, fileSource);
this.AddFile (file);
}
}
@ -123,10 +126,10 @@ OV.FileList = class
return;
}
let loaderPromise = null;
if (file.source === OV.FileSource.Url) {
loaderPromise = OV.RequestUrl (file.fileUrl, OV.FileFormat.Binary);
} else if (file.source === OV.FileSource.File) {
loaderPromise = OV.ReadFile (file.fileObject, OV.FileFormat.Binary);
if (file.source === FileSource.Url) {
loaderPromise = RequestUrl (file.fileUrl, FileFormat.Binary);
} else if (file.source === FileSource.File) {
loaderPromise = ReadFile (file.fileObject, FileFormat.Binary);
} else {
complete ();
return;
@ -138,4 +141,4 @@ OV.FileList = class
complete ();
});
}
};
}

View File

@ -1,12 +1,29 @@
OV.ImportSettings = class
import { RunTaskAsync } from '../core/taskrunner.js';
import { CreateObjectUrl, RevokeObjectUrl } from '../io/bufferutils.js';
import { LoadExternalLibrary } from '../io/externallibs.js';
import { FileSource, GetFileName } from '../io/fileutils.js';
import { Color } from '../model/color.js';
import { File, FileList } from './filelist.js';
import { Importer3dm } from './importer3dm.js';
import { Importer3ds } from './importer3ds.js';
import { ImporterGltf } from './importergltf.js';
import { ImporterIfc } from './importerifc.js';
import { ImporterO3dv } from './importero3dv.js';
import { ImporterObj } from './importerobj.js';
import { ImporterOff } from './importeroff.js';
import { ImporterPly } from './importerply.js';
import { ImporterStl } from './importerstl.js';
import { ImporterThree3mf, ImporterThreeDae, ImporterThreeFbx, ImporterThreeWrl } from './importerthree.js';
export class ImportSettings
{
constructor ()
{
this.defaultColor = new OV.Color (200, 200, 200);
this.defaultColor = new Color (200, 200, 200);
}
};
}
OV.ImportErrorCode =
export const ImportErrorCode =
{
NoImportableFile : 1,
FailedToLoadFile : 2,
@ -14,16 +31,16 @@ OV.ImportErrorCode =
UnknownError : 4
};
OV.ImportError = class
export class ImportError
{
constructor (code, message)
{
this.code = code;
this.message = message;
}
};
}
OV.ImportResult = class
export class ImportResult
{
constructor ()
{
@ -33,9 +50,9 @@ OV.ImportResult = class
this.usedFiles = null;
this.missingFiles = null;
}
};
}
OV.ImporterFileAccessor = class
export class ImporterFileAccessor
{
constructor (getBufferCallback)
{
@ -46,7 +63,7 @@ OV.ImporterFileAccessor = class
GetFileBuffer (filePath)
{
let fileName = OV.GetFileName (filePath);
let fileName = GetFileName (filePath);
if (this.fileBuffers.has (fileName)) {
return this.fileBuffers.get (fileName);
}
@ -57,7 +74,7 @@ OV.ImporterFileAccessor = class
GetTextureBuffer (filePath)
{
let fileName = OV.GetFileName (filePath);
let fileName = GetFileName (filePath);
if (this.textureBuffers.has (fileName)) {
return this.textureBuffers.get (fileName);
}
@ -65,35 +82,35 @@ OV.ImporterFileAccessor = class
let textureBuffer = this.getBufferCallback (fileName);
if (textureBuffer !== null) {
buffer = {
url : OV.CreateObjectUrl (textureBuffer),
url : CreateObjectUrl (textureBuffer),
buffer : textureBuffer
};
}
this.textureBuffers.set (fileName, buffer);
return buffer;
}
};
}
OV.Importer = class
export class Importer
{
constructor ()
{
this.importers = [
new OV.ImporterObj (),
new OV.ImporterStl (),
new OV.ImporterOff (),
new OV.ImporterPly (),
new OV.Importer3ds (),
new OV.ImporterGltf (),
new OV.ImporterO3dv (),
new OV.Importer3dm (),
new OV.ImporterIfc (),
new OV.ImporterThreeFbx (),
new OV.ImporterThreeDae (),
new OV.ImporterThreeWrl (),
new OV.ImporterThree3mf ()
new ImporterObj (),
new ImporterStl (),
new ImporterOff (),
new ImporterPly (),
new Importer3ds (),
new ImporterGltf (),
new ImporterO3dv (),
new Importer3dm (),
new ImporterIfc (),
new ImporterThreeFbx (),
new ImporterThreeDae (),
new ImporterThreeWrl (),
new ImporterThree3mf ()
];
this.fileList = new OV.FileList ();
this.fileList = new FileList ();
this.model = null;
this.usedFiles = [];
this.missingFiles = [];
@ -108,7 +125,7 @@ OV.Importer = class
{
this.LoadFiles (fileList, fileSource, () => {
callbacks.onFilesLoaded ();
OV.RunTaskAsync (() => {
RunTaskAsync (() => {
this.ImportLoadedFiles (settings, callbacks);
});
});
@ -116,10 +133,10 @@ OV.Importer = class
LoadFiles (fileList, fileSource, onReady)
{
let newFileList = new OV.FileList (this.importers);
if (fileSource === OV.FileSource.Url) {
let newFileList = new FileList (this.importers);
if (fileSource === FileSource.Url) {
newFileList.FillFromFileUrls (fileList);
} else if (fileSource === OV.FileSource.File) {
} else if (fileSource === FileSource.File) {
newFileList.FillFromFileObjects (fileList);
}
let reset = false;
@ -155,7 +172,7 @@ OV.Importer = class
{
let importableFiles = this.GetImportableFiles (this.fileList);
if (importableFiles.length === 0) {
callbacks.onImportError (new OV.ImportError (OV.ImportErrorCode.NoImportableFile, null));
callbacks.onImportError (new ImportError (ImportErrorCode.NoImportableFile, null));
return;
}
@ -166,10 +183,10 @@ OV.Importer = class
let fileNames = importableFiles.map (importableFile => importableFile.file.name);
callbacks.onSelectMainFile (fileNames, (mainFileIndex) => {
if (mainFileIndex === null) {
callbacks.onImportError (new OV.ImportError (OV.ImportErrorCode.NoImportableFile, null));
callbacks.onImportError (new ImportError (ImportErrorCode.NoImportableFile, null));
return;
}
OV.RunTaskAsync (() => {
RunTaskAsync (() => {
let mainFile = importableFiles[mainFileIndex];
this.ImportLoadedMainFile (mainFile, settings, callbacks);
});
@ -180,7 +197,7 @@ OV.Importer = class
ImportLoadedMainFile (mainFile, settings, callbacks)
{
if (mainFile === null || mainFile.file === null || mainFile.file.content === null) {
callbacks.onImportError (new OV.ImportError (OV.ImportErrorCode.FailedToLoadFile, null));
callbacks.onImportError (new ImportError (ImportErrorCode.FailedToLoadFile, null));
return;
}
@ -191,7 +208,7 @@ OV.Importer = class
this.usedFiles.push (mainFile.file.name);
let importer = mainFile.importer;
let fileAccessor = new OV.ImporterFileAccessor ((fileName) => {
let fileAccessor = new ImporterFileAccessor ((fileName) => {
let fileBuffer = null;
let file = this.fileList.FindFileByPath (fileName);
if (file === null || file.content === null) {
@ -216,7 +233,7 @@ OV.Importer = class
},
onSuccess : () => {
this.model = importer.GetModel ();
let result = new OV.ImportResult ();
let result = new ImportResult ();
result.mainFile = mainFile.file.name;
result.model = this.model;
result.usedFiles = this.usedFiles;
@ -226,7 +243,7 @@ OV.Importer = class
},
onError : () => {
let message = importer.GetErrorMessage ();
callbacks.onImportError (new OV.ImportError (OV.ImportErrorCode.ImportFailed, message));
callbacks.onImportError (new ImportError (ImportErrorCode.ImportFailed, message));
},
onComplete : () => {
importer.Clear ();
@ -247,14 +264,14 @@ OV.Importer = class
onReady ();
return;
}
OV.LoadExternalLibrary ('loaders/fflate.min.js').then (() => {
LoadExternalLibrary ('loaders/fflate.min.js').then (() => {
for (let i = 0; i < archives.length; i++) {
const archiveFile = archives[i];
const archiveBuffer = new Uint8Array (archiveFile.content);
const decompressed = fflate.unzipSync (archiveBuffer);
for (const fileName in decompressed) {
if (Object.prototype.hasOwnProperty.call (decompressed, fileName)) {
let file = new OV.File (fileName, OV.FileSource.Decompressed);
let file = new File (fileName, FileSource.Decompressed);
file.SetContent (decompressed[fileName].buffer);
fileList.AddFile (file);
}
@ -314,9 +331,9 @@ OV.Importer = class
let material = this.model.GetMaterial (i);
material.EnumerateTextureMaps ((texture) => {
if (texture.url !== null) {
OV.RevokeObjectUrl (texture.url);
RevokeObjectUrl (texture.url);
}
});
}
}
};
}

View File

@ -1,4 +1,16 @@
OV.Importer3dm = class extends OV.ImporterBase
import { Direction } from '../geometry/geometry.js';
import { Matrix } from '../geometry/matrix.js';
import { Transformation } from '../geometry/transformation.js';
import { LoadExternalLibrary } from '../io/externallibs.js';
import { PhongMaterial, PhysicalMaterial } from '../model/material.js';
import { TransformMesh } from '../model/meshutils.js';
import { IsModelEmpty } from '../model/modelutils.js';
import { Property, PropertyGroup, PropertyType } from '../model/property.js';
import { ConvertThreeGeometryToMesh } from '../threejs/threeutils.js';
import { ImporterBase } from './importerbase.js';
import { UpdateMaterialTransparency } from './importerutils.js';
export class Importer3dm extends ImporterBase
{
constructor ()
{
@ -13,7 +25,7 @@ OV.Importer3dm = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
ClearContent ()
@ -31,7 +43,7 @@ OV.Importer3dm = class extends OV.ImporterBase
ImportContent (fileContent, onFinish)
{
if (this.rhino === null) {
OV.LoadExternalLibrary ('loaders/rhino3dm.min.js').then (() => {
LoadExternalLibrary ('loaders/rhino3dm.min.js').then (() => {
rhino3dm ().then ((rhino) => {
this.rhino = rhino;
this.ImportRhinoContent (fileContent);
@ -54,7 +66,7 @@ OV.Importer3dm = class extends OV.ImporterBase
return;
}
this.ImportRhinoDocument (rhinoDoc);
if (OV.IsModelEmpty (this.model)) {
if (IsModelEmpty (this.model)) {
this.SetError ('The model doesn\'t contain any 3D meshes. Try to save the model while you are in shaded view in Rhino.');
}
}
@ -87,10 +99,10 @@ OV.Importer3dm = class extends OV.ImporterBase
{
let docStrings = rhinoDoc.strings ();
if (docStrings.count () > 0) {
let propertyGroup = new OV.PropertyGroup ('Document user texts');
let propertyGroup = new PropertyGroup ('Document user texts');
for (let i = 0; i < docStrings.count (); i++) {
let docString = docStrings.get (i);
propertyGroup.AddProperty (new OV.Property (OV.PropertyType.Text, docString[0], docString[1]));
propertyGroup.AddProperty (new Property (PropertyType.Text, docString[0], docString[1]));
}
this.model.AddPropertyGroup (propertyGroup);
}
@ -174,30 +186,30 @@ OV.Importer3dm = class extends OV.ImporterBase
let materialIndex = this.GetMaterialIndex (rhinoDoc, rhinoObject, rhinoInstanceReferences);
let threeJson = rhinoMesh.toThreejsJSON ();
let mesh = OV.ConvertThreeGeometryToMesh (threeJson.data, materialIndex);
let mesh = ConvertThreeGeometryToMesh (threeJson.data, materialIndex);
mesh.SetName (rhinoAttributes.name);
let userStrings = rhinoAttributes.getUserStrings ();
if (userStrings.length > 0) {
let propertyGroup = new OV.PropertyGroup ('User texts');
let propertyGroup = new PropertyGroup ('User texts');
for (let i = 0; i < userStrings.length; i++) {
let userString = userStrings[i];
propertyGroup.AddProperty (new OV.Property (OV.PropertyType.Text, userString[0], userString[1]));
propertyGroup.AddProperty (new Property (PropertyType.Text, userString[0], userString[1]));
}
mesh.AddPropertyGroup (propertyGroup);
}
if (rhinoInstanceReferences.length !== 0) {
let matrix = new OV.Matrix ().CreateIdentity ();
let matrix = new Matrix ().CreateIdentity ();
for (let i = rhinoInstanceReferences.length - 1; i >= 0; i--) {
let rhinoInstanceReference = rhinoInstanceReferences[i];
let rhinoInstanceReferenceGeometry = rhinoInstanceReference.geometry ();
let rhinoInstanceReferenceMatrix = rhinoInstanceReferenceGeometry.xform.toFloatArray (false);
let transformationMatrix = new OV.Matrix (rhinoInstanceReferenceMatrix);
let transformationMatrix = new Matrix (rhinoInstanceReferenceMatrix);
matrix = matrix.MultiplyMatrix (transformationMatrix);
}
let transformation = new OV.Transformation (matrix);
OV.TransformMesh (mesh, transformation);
let transformation = new Transformation (matrix);
TransformMesh (mesh, transformation);
}
this.model.AddMeshToRootNode (mesh);
}
@ -248,23 +260,23 @@ OV.Importer3dm = class extends OV.ImporterBase
let material = null;
if (rhinoMaterial === null) {
material = new OV.PhongMaterial ();
material = new PhongMaterial ();
material.color.Set (255, 255, 255);
} else {
let physicallyBased = rhinoMaterial.physicallyBased ();
if (physicallyBased.supported) {
material = new OV.PhysicalMaterial ();
material = new PhysicalMaterial ();
material.metalness = physicallyBased.metallic ? 1.0 : 0.0;
material.roughness = physicallyBased.roughness;
} else {
material = new OV.PhongMaterial ();
material = new PhongMaterial ();
SetColor (material.ambient, rhinoMaterial.ambientColor);
SetColor (material.specular, rhinoMaterial.specularColor);
}
material.name = rhinoMaterial.name;
SetColor (material.color, rhinoMaterial.diffuseColor);
material.opacity = 1.0 - rhinoMaterial.transparency;
OV.UpdateMaterialTransparency (material);
UpdateMaterialTransparency (material);
// material.shininess = rhinoMaterial.shine / 255.0;
if (IsBlack (material.color) && !IsWhite (rhinoMaterial.reflectionColor)) {
SetColor (material.color, rhinoMaterial.reflectionColor);
@ -285,4 +297,4 @@ OV.Importer3dm = class extends OV.ImporterBase
let rhinoMaterial = GetRhinoMaterial (this.rhino, rhinoObject, rhinoInstanceReferences);
return FindMatchingMaterial (this.model, rhinoMaterial);
}
};
}

View File

@ -1,4 +1,20 @@
OV.CHUNK3DS =
import { Coord2D } from '../geometry/coord2d.js';
import { ArrayToCoord3D, Coord3D } from '../geometry/coord3d.js';
import { DegRad, Direction, IsNegative } from '../geometry/geometry.js';
import { Matrix } from '../geometry/matrix.js';
import { ArrayToQuaternion } from '../geometry/quaternion.js';
import { Transformation } from '../geometry/transformation.js';
import { BinaryReader } from '../io/binaryreader.js';
import { Color, ColorComponentFromFloat } from '../model/color.js';
import { PhongMaterial, TextureMap } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { FlipMeshTrianglesOrientation, TransformMesh } from '../model/meshutils.js';
import { Node, NodeType } from '../model/node.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
import { UpdateMaterialTransparency } from './importerutils.js';
export const CHUNK3DS =
{
MAIN3DS : 0x4D4D,
EDIT3DS : 0x3D3D,
@ -44,7 +60,7 @@ OV.CHUNK3DS =
OBJECT_ID : 0xB030
};
OV.Importer3dsNode = class
export class Importer3dsNode
{
constructor ()
{
@ -58,9 +74,9 @@ OV.Importer3dsNode = class
this.rotations = [];
this.scales = [];
}
};
}
OV.Importer3dsNodeList = class
export class Importer3dsNodeList
{
constructor ()
{
@ -83,9 +99,9 @@ OV.Importer3dsNodeList = class
{
return this.nodes;
}
};
}
OV.Importer3ds = class extends OV.ImporterBase
export class Importer3ds extends ImporterBase
{
constructor ()
{
@ -99,7 +115,7 @@ OV.Importer3ds = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
ClearContent ()
@ -113,7 +129,7 @@ OV.Importer3ds = class extends OV.ImporterBase
{
this.materialNameToIndex = new Map ();
this.meshNameToIndex = new Map ();
this.nodeList = new OV.Importer3dsNodeList ();
this.nodeList = new Importer3dsNodeList ();
}
ImportContent (fileContent, onFinish)
@ -124,10 +140,10 @@ OV.Importer3ds = class extends OV.ImporterBase
ProcessBinary (fileContent)
{
let reader = new OV.BinaryReader (fileContent, true);
let reader = new BinaryReader (fileContent, true);
let endByte = reader.GetByteLength ();
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.MAIN3DS) {
if (chunkId === CHUNK3DS.MAIN3DS) {
this.ReadMainChunk (reader, chunkLength);
} else {
this.SkipChunk (reader, chunkLength);
@ -139,9 +155,9 @@ OV.Importer3ds = class extends OV.ImporterBase
{
let endByte = this.GetChunkEnd (reader, length);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.EDIT3DS) {
if (chunkId === CHUNK3DS.EDIT3DS) {
this.ReadEditorChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.KF3DS) {
} else if (chunkId === CHUNK3DS.KF3DS) {
this.ReadKeyFrameChunk (reader, chunkLength);
} else {
this.SkipChunk (reader, chunkLength);
@ -154,9 +170,9 @@ OV.Importer3ds = class extends OV.ImporterBase
{
let endByte = this.GetChunkEnd (reader, length);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.EDIT_MATERIAL) {
if (chunkId === CHUNK3DS.EDIT_MATERIAL) {
this.ReadMaterialChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.EDIT_OBJECT) {
} else if (chunkId === CHUNK3DS.EDIT_OBJECT) {
this.ReadObjectChunk (reader, chunkLength);
} else {
this.SkipChunk (reader, chunkLength);
@ -166,29 +182,29 @@ OV.Importer3ds = class extends OV.ImporterBase
ReadMaterialChunk (reader, length)
{
let material = new OV.PhongMaterial ();
let material = new PhongMaterial ();
let endByte = this.GetChunkEnd (reader, length);
let shininess = null;
let shininessStrength = null;
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.MAT_NAME) {
if (chunkId === CHUNK3DS.MAT_NAME) {
material.name = this.ReadName (reader);
} else if (chunkId === OV.CHUNK3DS.MAT_AMBIENT) {
} else if (chunkId === CHUNK3DS.MAT_AMBIENT) {
material.ambient = this.ReadColorChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.MAT_DIFFUSE) {
} else if (chunkId === CHUNK3DS.MAT_DIFFUSE) {
material.color = this.ReadColorChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.MAT_SPECULAR) {
} else if (chunkId === CHUNK3DS.MAT_SPECULAR) {
material.specular = this.ReadColorChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.MAT_SHININESS) {
} else if (chunkId === CHUNK3DS.MAT_SHININESS) {
shininess = this.ReadPercentageChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.MAT_SHININESS_STRENGTH) {
} else if (chunkId === CHUNK3DS.MAT_SHININESS_STRENGTH) {
shininessStrength = this.ReadPercentageChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.MAT_TRANSPARENCY) {
} else if (chunkId === CHUNK3DS.MAT_TRANSPARENCY) {
material.opacity = 1.0 - this.ReadPercentageChunk (reader, chunkLength);
OV.UpdateMaterialTransparency (material);
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP) {
UpdateMaterialTransparency (material);
} else if (chunkId === CHUNK3DS.MAT_TEXMAP) {
material.diffuseMap = this.ReadTextureMapChunk (reader, chunkLength);
OV.UpdateMaterialTransparency (material);
UpdateMaterialTransparency (material);
} else {
this.SkipChunk (reader, chunkLength);
}
@ -203,10 +219,10 @@ OV.Importer3ds = class extends OV.ImporterBase
ReadTextureMapChunk (reader, length)
{
let texture = new OV.TextureMap ();
let texture = new TextureMap ();
let endByte = this.GetChunkEnd (reader, length);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_NAME) {
if (chunkId === CHUNK3DS.MAT_TEXMAP_NAME) {
let textureName = this.ReadName (reader);
let textureBuffer = this.callbacks.getTextureBuffer (textureName);
texture.name = textureName;
@ -214,16 +230,16 @@ OV.Importer3ds = class extends OV.ImporterBase
texture.url = textureBuffer.url;
texture.buffer = textureBuffer.buffer;
}
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_UOFFSET) {
} else if (chunkId === CHUNK3DS.MAT_TEXMAP_UOFFSET) {
texture.offset.x = reader.ReadFloat32 ();
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_VOFFSET) {
} else if (chunkId === CHUNK3DS.MAT_TEXMAP_VOFFSET) {
texture.offset.y = reader.ReadFloat32 ();
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_USCALE) {
} else if (chunkId === CHUNK3DS.MAT_TEXMAP_USCALE) {
texture.scale.x = reader.ReadFloat32 ();
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_VSCALE) {
} else if (chunkId === CHUNK3DS.MAT_TEXMAP_VSCALE) {
texture.scale.y = reader.ReadFloat32 ();
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_ROTATION) {
texture.rotation = reader.ReadFloat32 () * OV.DegRad;
} else if (chunkId === CHUNK3DS.MAT_TEXMAP_ROTATION) {
texture.rotation = reader.ReadFloat32 () * DegRad;
} else {
this.SkipChunk (reader, chunkLength);
}
@ -233,31 +249,31 @@ OV.Importer3ds = class extends OV.ImporterBase
ReadColorChunk (reader, length)
{
let color = new OV.Color (0, 0, 0);
let color = new Color (0, 0, 0);
let endByte = this.GetChunkEnd (reader, length);
let hasLinColor = false;
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.MAT_COLOR) {
if (chunkId === CHUNK3DS.MAT_COLOR) {
if (!hasLinColor) {
color.r = reader.ReadUnsignedCharacter8 ();
color.g = reader.ReadUnsignedCharacter8 ();
color.b = reader.ReadUnsignedCharacter8 ();
}
} else if (chunkId === OV.CHUNK3DS.MAT_LIN_COLOR) {
} else if (chunkId === CHUNK3DS.MAT_LIN_COLOR) {
color.r = reader.ReadUnsignedCharacter8 ();
color.g = reader.ReadUnsignedCharacter8 ();
color.b = reader.ReadUnsignedCharacter8 ();
hasLinColor = true;
} else if (chunkId === OV.CHUNK3DS.MAT_COLOR_F) {
} else if (chunkId === CHUNK3DS.MAT_COLOR_F) {
if (!hasLinColor) {
color.r = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
color.g = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
color.b = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
color.r = ColorComponentFromFloat (reader.ReadFloat32 ());
color.g = ColorComponentFromFloat (reader.ReadFloat32 ());
color.b = ColorComponentFromFloat (reader.ReadFloat32 ());
}
} else if (chunkId === OV.CHUNK3DS.MAT_LIN_COLOR_F) {
color.r = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
color.g = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
color.b = OV.ColorComponentFromFloat (reader.ReadFloat32 ());
} else if (chunkId === CHUNK3DS.MAT_LIN_COLOR_F) {
color.r = ColorComponentFromFloat (reader.ReadFloat32 ());
color.g = ColorComponentFromFloat (reader.ReadFloat32 ());
color.b = ColorComponentFromFloat (reader.ReadFloat32 ());
hasLinColor = true;
} else {
this.SkipChunk (reader, chunkLength);
@ -271,9 +287,9 @@ OV.Importer3ds = class extends OV.ImporterBase
let percentage = 0.0;
let endByte = this.GetChunkEnd (reader, length);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.PERCENTAGE) {
if (chunkId === CHUNK3DS.PERCENTAGE) {
percentage = reader.ReadUnsignedInteger16 () / 100.0;
} else if (chunkId === OV.CHUNK3DS.PERCENTAGE_F) {
} else if (chunkId === CHUNK3DS.PERCENTAGE_F) {
percentage = reader.ReadFloat32 ();
} else {
this.SkipChunk (reader, chunkLength);
@ -287,11 +303,11 @@ OV.Importer3ds = class extends OV.ImporterBase
let endByte = this.GetChunkEnd (reader, length);
let objectName = this.ReadName (reader);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.OBJ_TRIMESH) {
if (chunkId === CHUNK3DS.OBJ_TRIMESH) {
this.ReadMeshChunk (reader, chunkLength, objectName);
} else if (chunkId === OV.CHUNK3DS.OBJ_LIGHT) {
} else if (chunkId === CHUNK3DS.OBJ_LIGHT) {
this.SkipChunk (reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.OBJ_CAMERA) {
} else if (chunkId === CHUNK3DS.OBJ_CAMERA) {
this.SkipChunk (reader, chunkLength);
} else {
this.SkipChunk (reader, chunkLength);
@ -308,9 +324,9 @@ OV.Importer3ds = class extends OV.ImporterBase
}
let determinant = meshMatrix.Determinant ();
let mirrorByX = OV.IsNegative (determinant);
let mirrorByX = IsNegative (determinant);
if (mirrorByX) {
let scaleMatrix = new OV.Matrix ().CreateScale (-1.0, 1.0, 1.0);
let scaleMatrix = new Matrix ().CreateScale (-1.0, 1.0, 1.0);
meshMatrix = scaleMatrix.MultiplyMatrix (meshMatrix);
}
@ -319,26 +335,26 @@ OV.Importer3ds = class extends OV.ImporterBase
return;
}
let transformation = new OV.Transformation (invMeshMatrix);
OV.TransformMesh (mesh, transformation);
let transformation = new Transformation (invMeshMatrix);
TransformMesh (mesh, transformation);
if (mirrorByX) {
OV.FlipMeshTrianglesOrientation (mesh);
FlipMeshTrianglesOrientation (mesh);
}
}
let mesh = new OV.Mesh ();
let mesh = new Mesh ();
mesh.SetName (objectName);
let endByte = this.GetChunkEnd (reader, length);
let matrixElements = null;
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.TRI_VERTEX) {
if (chunkId === CHUNK3DS.TRI_VERTEX) {
this.ReadVerticesChunk (mesh, reader);
} else if (chunkId === OV.CHUNK3DS.TRI_TEXVERTEX) {
} else if (chunkId === CHUNK3DS.TRI_TEXVERTEX) {
this.ReadTextureVerticesChunk (mesh, reader);
} else if (chunkId === OV.CHUNK3DS.TRI_FACE) {
} else if (chunkId === CHUNK3DS.TRI_FACE) {
this.ReadFacesChunk (mesh, reader, chunkLength);
} else if (chunkId === OV.CHUNK3DS.TRI_TRANSFORMATION) {
} else if (chunkId === CHUNK3DS.TRI_TRANSFORMATION) {
matrixElements = this.ReadTransformationChunk (reader);
} else {
this.SkipChunk (reader, chunkLength);
@ -356,7 +372,7 @@ OV.Importer3ds = class extends OV.ImporterBase
}
}
let meshMatrix = new OV.Matrix (matrixElements);
let meshMatrix = new Matrix (matrixElements);
ApplyMeshTransformation (mesh, meshMatrix);
let meshIndex = this.model.AddMesh (mesh);
@ -370,7 +386,7 @@ OV.Importer3ds = class extends OV.ImporterBase
let x = reader.ReadFloat32 ();
let y = reader.ReadFloat32 ();
let z = reader.ReadFloat32 ();
mesh.AddVertex (new OV.Coord3D (x, y, z));
mesh.AddVertex (new Coord3D (x, y, z));
}
}
@ -380,7 +396,7 @@ OV.Importer3ds = class extends OV.ImporterBase
for (let i = 0; i < texVertexCount; i++) {
let x = reader.ReadFloat32 ();
let y = reader.ReadFloat32 ();
mesh.AddTextureUV (new OV.Coord2D (x, y));
mesh.AddTextureUV (new Coord2D (x, y));
}
}
@ -393,13 +409,13 @@ OV.Importer3ds = class extends OV.ImporterBase
let v1 = reader.ReadUnsignedInteger16 ();
let v2 = reader.ReadUnsignedInteger16 ();
reader.ReadUnsignedInteger16 (); // flags
mesh.AddTriangle (new OV.Triangle (v0, v1, v2));
mesh.AddTriangle (new Triangle (v0, v1, v2));
}
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.TRI_MATERIAL) {
if (chunkId === CHUNK3DS.TRI_MATERIAL) {
this.ReadFaceMaterialsChunk (mesh, reader);
} else if (chunkId === OV.CHUNK3DS.TRI_SMOOTH) {
} else if (chunkId === CHUNK3DS.TRI_SMOOTH) {
this.ReadFaceSmoothingGroupsChunk (mesh, faceCount, reader);
} else {
this.SkipChunk (reader, chunkLength);
@ -450,7 +466,7 @@ OV.Importer3ds = class extends OV.ImporterBase
{
let endByte = this.GetChunkEnd (reader, length);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.OBJECT_NODE) {
if (chunkId === CHUNK3DS.OBJECT_NODE) {
this.ReadObjectNodeChunk (reader, chunkLength);
} else {
this.SkipChunk (reader, chunkLength);
@ -500,20 +516,20 @@ OV.Importer3ds = class extends OV.ImporterBase
return node3ds.scales[0];
}
let matrix = new OV.Matrix ();
let matrix = new Matrix ();
matrix.ComposeTRS (
OV.ArrayToCoord3D (GetNodePosition (node3ds)),
OV.ArrayToQuaternion (GetNodeRotation (node3ds)),
OV.ArrayToCoord3D (GetNodeScale (node3ds))
ArrayToCoord3D (GetNodePosition (node3ds)),
ArrayToQuaternion (GetNodeRotation (node3ds)),
ArrayToCoord3D (GetNodeScale (node3ds))
);
if (isMeshNode) {
let pivotPoint = node3ds.pivot;
let pivotMatrix = new OV.Matrix ().CreateTranslation (-pivotPoint[0], -pivotPoint[1], -pivotPoint[2]);
let pivotMatrix = new Matrix ().CreateTranslation (-pivotPoint[0], -pivotPoint[1], -pivotPoint[2]);
matrix = pivotMatrix.MultiplyMatrix (matrix);
}
return new OV.Transformation (matrix);
return new Transformation (matrix);
}
let rootNode = this.model.GetRootNode ();
@ -524,7 +540,7 @@ OV.Importer3ds = class extends OV.ImporterBase
} else {
let nodeIdToModelNode = new Map ();
for (let node3ds of this.nodeList.GetNodes ()) {
let node = new OV.Node ();
let node = new Node ();
if (node3ds.name.length > 0 && node3ds.name !== '$$$DUMMY') {
node.SetName (node3ds.name);
if (node3ds.instanceName.length > 0) {
@ -541,7 +557,7 @@ OV.Importer3ds = class extends OV.ImporterBase
let isMeshNode = this.meshNameToIndex.has (node3ds.name);
node.SetTransformation (GetNodeTransformation (node3ds, isMeshNode));
if (isMeshNode) {
node.SetType (OV.NodeType.MeshNode);
node.SetType (NodeType.MeshNode);
node.AddMeshIndex (this.meshNameToIndex.get (node3ds.name));
}
}
@ -564,7 +580,7 @@ OV.Importer3ds = class extends OV.ImporterBase
}
let current = null;
if (type === OV.CHUNK3DS.OBJECT_ROTATION) {
if (type === CHUNK3DS.OBJECT_ROTATION) {
let tmp = reader.ReadFloat32 ();
current = obj.ReadVector (reader);
current[3] = tmp;
@ -577,24 +593,24 @@ OV.Importer3ds = class extends OV.ImporterBase
return result;
}
let node3ds = new OV.Importer3dsNode ();
let node3ds = new Importer3dsNode ();
let endByte = this.GetChunkEnd (reader, length);
this.ReadChunks (reader, endByte, (chunkId, chunkLength) => {
if (chunkId === OV.CHUNK3DS.OBJECT_HIERARCHY) {
if (chunkId === CHUNK3DS.OBJECT_HIERARCHY) {
node3ds.name = this.ReadName (reader);
node3ds.flags = reader.ReadUnsignedInteger32 ();
node3ds.parentId = reader.ReadUnsignedInteger16 ();
} else if (chunkId === OV.CHUNK3DS.OBJECT_INSTANCE_NAME) {
} else if (chunkId === CHUNK3DS.OBJECT_INSTANCE_NAME) {
node3ds.instanceName = this.ReadName (reader);
} else if (chunkId === OV.CHUNK3DS.OBJECT_PIVOT) {
} else if (chunkId === CHUNK3DS.OBJECT_PIVOT) {
node3ds.pivot = this.ReadVector (reader);
} else if (chunkId === OV.CHUNK3DS.OBJECT_POSITION) {
node3ds.positions = ReadTrackVector (this, reader, OV.CHUNK3DS.OBJECT_POSITION);
} else if (chunkId === OV.CHUNK3DS.OBJECT_ROTATION) {
node3ds.rotations = ReadTrackVector (this, reader, OV.CHUNK3DS.OBJECT_ROTATION);
} else if (chunkId === OV.CHUNK3DS.OBJECT_SCALE) {
node3ds.scales = ReadTrackVector (this, reader, OV.CHUNK3DS.OBJECT_SCALE);
} else if (chunkId === OV.CHUNK3DS.OBJECT_ID) {
} else if (chunkId === CHUNK3DS.OBJECT_POSITION) {
node3ds.positions = ReadTrackVector (this, reader, CHUNK3DS.OBJECT_POSITION);
} else if (chunkId === CHUNK3DS.OBJECT_ROTATION) {
node3ds.rotations = ReadTrackVector (this, reader, CHUNK3DS.OBJECT_ROTATION);
} else if (chunkId === CHUNK3DS.OBJECT_SCALE) {
node3ds.scales = ReadTrackVector (this, reader, CHUNK3DS.OBJECT_SCALE);
} else if (chunkId === CHUNK3DS.OBJECT_ID) {
node3ds.id = reader.ReadUnsignedInteger16 ();
} else {
this.SkipChunk (reader, chunkLength);
@ -648,4 +664,4 @@ OV.Importer3ds = class extends OV.ImporterBase
{
reader.Skip (length - 6);
}
};
}

View File

@ -1,4 +1,9 @@
OV.ImporterBase = class
import { Direction } from '../geometry/geometry.js';
import { Model } from '../model/model.js';
import { FinalizeModel } from '../model/modelfinalization.js';
import { IsModelEmpty } from '../model/modelutils.js';
export class ImporterBase
{
constructor ()
{
@ -17,7 +22,7 @@ OV.ImporterBase = class
this.name = name;
this.extension = extension;
this.callbacks = callbacks;
this.model = new OV.Model ();
this.model = new Model ();
this.error = false;
this.message = null;
this.ResetContent ();
@ -45,14 +50,14 @@ OV.ImporterBase = class
return;
}
if (OV.IsModelEmpty (this.model)) {
if (IsModelEmpty (this.model)) {
this.error = true;
callbacks.onError ();
callbacks.onComplete ();
return;
}
OV.FinalizeModel (this.model, {
FinalizeModel (this.model, {
getDefaultMaterialColor : this.callbacks.getDefaultMaterialColor
});
@ -67,7 +72,7 @@ OV.ImporterBase = class
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
ClearContent ()
@ -107,4 +112,4 @@ OV.ImporterBase = class
{
return this.message;
}
};
}

View File

@ -1,4 +1,22 @@
OV.GltfComponentType =
import { Coord2D } from '../geometry/coord2d.js';
import { ArrayToCoord3D, Coord3D } from '../geometry/coord3d.js';
import { Coord4D } from '../geometry/coord4d.js';
import { Direction } from '../geometry/geometry.js';
import { Matrix } from '../geometry/matrix.js';
import { ArrayToQuaternion } from '../geometry/quaternion.js';
import { Transformation } from '../geometry/transformation.js';
import { BinaryReader } from '../io/binaryreader.js';
import { ArrayBufferToUtf8String, Base64DataURIToArrayBuffer, CreateObjectUrlWithMimeType, GetFileExtensionFromMimeType } from '../io/bufferutils.js';
import { LoadExternalLibrary } from '../io/externallibs.js';
import { Color, ColorComponentFromFloat, ColorFromFloatComponents, LinearToSRGB } from '../model/color.js';
import { PhongMaterial, PhysicalMaterial, TextureMap } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { Node, NodeType } from '../model/node.js';
import { Property, PropertyGroup, PropertyType } from '../model/property.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
export const GltfComponentType =
{
BYTE : 5120,
UNSIGNED_BYTE : 5121,
@ -8,7 +26,7 @@ OV.GltfComponentType =
FLOAT : 5126
};
OV.GltfDataType =
export const GltfDataType =
{
SCALAR : 0,
VEC2 : 1,
@ -19,7 +37,7 @@ OV.GltfDataType =
MAT4 : 6
};
OV.GltfRenderMode =
export const GltfRenderMode =
{
POINTS : 0,
LINES : 1,
@ -30,45 +48,45 @@ OV.GltfRenderMode =
TRIANGLE_FAN : 6
};
OV.GltfConstants =
export const GltfConstants =
{
GLTF_STRING : 0x46546C67,
JSON_CHUNK_TYPE : 0x4E4F534A,
BINARY_CHUNK_TYPE : 0x004E4942
};
OV.GetGltfColor = function (color)
export function GetGltfColor (color)
{
return OV.ColorFromFloatComponents (
OV.LinearToSRGB (color[0]),
OV.LinearToSRGB (color[1]),
OV.LinearToSRGB (color[2])
return ColorFromFloatComponents (
LinearToSRGB (color[0]),
LinearToSRGB (color[1]),
LinearToSRGB (color[2])
);
};
}
OV.GetGltfVertexColor = function (color, componentType)
export function GetGltfVertexColor (color, componentType)
{
function GetColorComponent (component, componentType)
{
let normalized = component;
if (componentType !== OV.GltfComponentType.FLOAT) {
if (componentType !== GltfComponentType.FLOAT) {
normalized /= 255.0;
}
return OV.ColorComponentFromFloat (OV.LinearToSRGB (normalized));
return ColorComponentFromFloat (LinearToSRGB (normalized));
}
return new OV.Color (
return new Color (
GetColorComponent (color[0], componentType),
GetColorComponent (color[1], componentType),
GetColorComponent (color[2], componentType)
);
};
}
OV.GltfBufferReader = class
export class GltfBufferReader
{
constructor (buffer)
{
this.reader = new OV.BinaryReader (buffer, true);
this.reader = new BinaryReader (buffer, true);
this.componentType = null;
this.dataType = null;
this.byteStride = null;
@ -84,19 +102,19 @@ OV.GltfBufferReader = class
SetDataType (dataType)
{
if (dataType === 'SCALAR') {
this.dataType = OV.GltfDataType.SCALAR;
this.dataType = GltfDataType.SCALAR;
} else if (dataType === 'VEC2') {
this.dataType = OV.GltfDataType.VEC2;
this.dataType = GltfDataType.VEC2;
} else if (dataType === 'VEC3') {
this.dataType = OV.GltfDataType.VEC3;
this.dataType = GltfDataType.VEC3;
} else if (dataType === 'VEC4') {
this.dataType = OV.GltfDataType.VEC4;
this.dataType = GltfDataType.VEC4;
} else if (dataType === 'MAT2') {
this.dataType = OV.GltfDataType.MAT2;
this.dataType = GltfDataType.MAT2;
} else if (dataType === 'MAT3') {
this.dataType = OV.GltfDataType.MAT3;
this.dataType = GltfDataType.MAT3;
} else if (dataType === 'MAT4') {
this.dataType = OV.GltfDataType.MAT4;
this.dataType = GltfDataType.MAT4;
}
}
@ -133,28 +151,28 @@ OV.GltfBufferReader = class
if (this.dataType === null) {
return null;
}
if (this.dataType === OV.GltfDataType.SCALAR) {
if (this.dataType === GltfDataType.SCALAR) {
let data = this.ReadComponent ();
this.SkipBytesByStride (1);
return data;
} else if (this.dataType === OV.GltfDataType.VEC2) {
} else if (this.dataType === GltfDataType.VEC2) {
let x = this.ReadComponent ();
let y = this.ReadComponent ();
this.SkipBytesByStride (2);
return new OV.Coord2D (x, y);
} else if (this.dataType === OV.GltfDataType.VEC3) {
return new Coord2D (x, y);
} else if (this.dataType === GltfDataType.VEC3) {
let x = this.ReadComponent ();
let y = this.ReadComponent ();
let z = this.ReadComponent ();
this.SkipBytesByStride (3);
return new OV.Coord3D (x, y, z);
} else if (this.dataType === OV.GltfDataType.VEC4) {
return new Coord3D (x, y, z);
} else if (this.dataType === GltfDataType.VEC4) {
let x = this.ReadComponent ();
let y = this.ReadComponent ();
let z = this.ReadComponent ();
let w = this.ReadComponent ();
this.SkipBytesByStride (4);
return new OV.Coord4D (x, y, z, w);
return new Coord4D (x, y, z, w);
}
return null;
}
@ -198,17 +216,17 @@ OV.GltfBufferReader = class
if (this.componentType === null) {
return null;
}
if (this.componentType === OV.GltfComponentType.BYTE) {
if (this.componentType === GltfComponentType.BYTE) {
return this.reader.ReadCharacter8 ();
} else if (this.componentType === OV.GltfComponentType.UNSIGNED_BYTE) {
} else if (this.componentType === GltfComponentType.UNSIGNED_BYTE) {
return this.reader.ReadUnsignedCharacter8 ();
} else if (this.componentType === OV.GltfComponentType.SHORT) {
} else if (this.componentType === GltfComponentType.SHORT) {
return this.reader.ReadInteger16 ();
} else if (this.componentType === OV.GltfComponentType.UNSIGNED_SHORT) {
} else if (this.componentType === GltfComponentType.UNSIGNED_SHORT) {
return this.reader.ReadUnsignedInteger16 ();
} else if (this.componentType === OV.GltfComponentType.UNSIGNED_INT) {
} else if (this.componentType === GltfComponentType.UNSIGNED_INT) {
return this.reader.ReadInteger32 ();
} else if (this.componentType === OV.GltfComponentType.FLOAT) {
} else if (this.componentType === GltfComponentType.FLOAT) {
return this.reader.ReadFloat32 ();
}
return null;
@ -225,24 +243,24 @@ OV.GltfBufferReader = class
GetComponentSize ()
{
if (this.componentType === OV.GltfComponentType.BYTE) {
if (this.componentType === GltfComponentType.BYTE) {
return 1;
} else if (this.componentType === OV.GltfComponentType.UNSIGNED_BYTE) {
} else if (this.componentType === GltfComponentType.UNSIGNED_BYTE) {
return 1;
} else if (this.componentType === OV.GltfComponentType.SHORT) {
} else if (this.componentType === GltfComponentType.SHORT) {
return 2;
} else if (this.componentType === OV.GltfComponentType.UNSIGNED_SHORT) {
} else if (this.componentType === GltfComponentType.UNSIGNED_SHORT) {
return 2;
} else if (this.componentType === OV.GltfComponentType.UNSIGNED_INT) {
} else if (this.componentType === GltfComponentType.UNSIGNED_INT) {
return 4;
} else if (this.componentType === OV.GltfComponentType.FLOAT) {
} else if (this.componentType === GltfComponentType.FLOAT) {
return 4;
}
return 0;
}
};
}
OV.GltfExtensions = class
export class GltfExtensions
{
constructor ()
{
@ -261,7 +279,7 @@ OV.GltfExtensions = class
return;
}
if (this.draco === null && extensionsRequired.indexOf ('KHR_draco_mesh_compression') !== -1) {
OV.LoadExternalLibrary ('loaders/draco_decoder.js').then (() => {
LoadExternalLibrary ('loaders/draco_decoder.js').then (() => {
DracoDecoderModule ().then ((draco) => {
this.draco = draco;
callbacks.onSuccess ();
@ -300,10 +318,10 @@ OV.GltfExtensions = class
return null;
}
let phongMaterial = new OV.PhongMaterial ();
let phongMaterial = new PhongMaterial ();
let diffuseColor = khrSpecularGlossiness.diffuseFactor;
if (diffuseColor !== undefined) {
phongMaterial.color = OV.GetGltfColor (diffuseColor);
phongMaterial.color = GetGltfColor (diffuseColor);
phongMaterial.opacity = diffuseColor[3];
}
let diffuseTexture = khrSpecularGlossiness.diffuseTexture;
@ -312,7 +330,7 @@ OV.GltfExtensions = class
}
let specularColor = khrSpecularGlossiness.specularFactor;
if (specularColor !== undefined) {
phongMaterial.specular = OV.GetGltfColor (specularColor);
phongMaterial.specular = GetGltfColor (specularColor);
}
let specularTexture = khrSpecularGlossiness.specularGlossinessTexture;
if (specularTexture !== undefined) {
@ -361,14 +379,14 @@ OV.GltfExtensions = class
let attributeArray = new Float32Array (draco.HEAPF32.buffer, attributePtr, numValues).slice ();
if (numComponents === 2) {
for (let i = 0; i < attributeArray.length; i += 2) {
processor (new OV.Coord2D (
processor (new Coord2D (
attributeArray[i + 0],
attributeArray[i + 1]
));
}
} else if (numComponents === 3) {
for (let i = 0; i < attributeArray.length; i += 3) {
processor (new OV.Coord3D (
processor (new Coord3D (
attributeArray[i + 0],
attributeArray[i + 1],
attributeArray[i + 2]
@ -376,7 +394,7 @@ OV.GltfExtensions = class
}
} else if (numComponents === 4) {
for (let i = 0; i < attributeArray.length; i += 4) {
processor (new OV.Coord4D (
processor (new Coord4D (
attributeArray[i + 0],
attributeArray[i + 1],
attributeArray[i + 2],
@ -461,14 +479,14 @@ OV.GltfExtensions = class
return true;
}
};
}
OV.ImporterGltf = class extends OV.ImporterBase
export class ImporterGltf extends ImporterBase
{
constructor ()
{
super ();
this.gltfExtensions = new OV.GltfExtensions ();
this.gltfExtensions = new GltfExtensions ();
}
CanImportExtension (extension)
@ -478,7 +496,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
ClearContent ()
@ -504,7 +522,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
ProcessGltf (fileContent, onFinish)
{
let textContent = OV.ArrayBufferToUtf8String (fileContent);
let textContent = ArrayBufferToUtf8String (fileContent);
let gltf = JSON.parse (textContent);
if (gltf.asset.version !== '2.0') {
this.SetError ('Invalid glTF version.');
@ -515,7 +533,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
for (let i = 0; i < gltf.buffers.length; i++) {
let buffer = null;
let gltfBuffer = gltf.buffers[i];
let base64Buffer = OV.Base64DataURIToArrayBuffer (gltfBuffer.uri);
let base64Buffer = Base64DataURIToArrayBuffer (gltfBuffer.uri);
if (base64Buffer !== null) {
buffer = base64Buffer.buffer;
} else {
@ -548,9 +566,9 @@ OV.ImporterGltf = class extends OV.ImporterBase
};
}
let reader = new OV.BinaryReader (fileContent, true);
let reader = new BinaryReader (fileContent, true);
let magic = reader.ReadUnsignedInteger32 ();
if (magic !== OV.GltfConstants.GLTF_STRING) {
if (magic !== GltfConstants.GLTF_STRING) {
this.SetError ('Invalid glTF file.');
onFinish ();
return;
@ -571,9 +589,9 @@ OV.ImporterGltf = class extends OV.ImporterBase
let gltfTextContent = null;
while (!reader.End ()) {
let chunk = ReadChunk (reader);
if (chunk.type === OV.GltfConstants.JSON_CHUNK_TYPE) {
gltfTextContent = OV.ArrayBufferToUtf8String (chunk.buffer);
} else if (chunk.type === OV.GltfConstants.BINARY_CHUNK_TYPE) {
if (chunk.type === GltfConstants.JSON_CHUNK_TYPE) {
gltfTextContent = ArrayBufferToUtf8String (chunk.buffer);
} else if (chunk.type === GltfConstants.BINARY_CHUNK_TYPE) {
this.bufferContents.push (chunk.buffer);
}
}
@ -629,11 +647,11 @@ OV.ImporterGltf = class extends OV.ImporterBase
{
function ImportProperties (model, propertyGroupName, propertyObject)
{
let propertyGroup = new OV.PropertyGroup (propertyGroupName);
let propertyGroup = new PropertyGroup (propertyGroupName);
for (let propertyName in propertyObject) {
if (Object.prototype.hasOwnProperty.call (propertyObject, propertyName)) {
if (typeof propertyObject[propertyName] === 'string') {
const property = new OV.Property (OV.PropertyType.Text, propertyName, propertyObject[propertyName]);
const property = new Property (PropertyType.Text, propertyName, propertyObject[propertyName]);
propertyGroup.AddProperty (property);
}
}
@ -661,16 +679,16 @@ OV.ImporterGltf = class extends OV.ImporterBase
ImportMaterial (gltf, gltfMaterial)
{
let material = new OV.PhysicalMaterial ();
let material = new PhysicalMaterial ();
if (gltfMaterial.name !== undefined) {
material.name = gltfMaterial.name;
}
material.color = OV.GetGltfColor ([1.0, 1.0, 1.0]);
material.color = GetGltfColor ([1.0, 1.0, 1.0]);
if (gltfMaterial.pbrMetallicRoughness !== undefined) {
let baseColor = gltfMaterial.pbrMetallicRoughness.baseColorFactor;
if (baseColor !== undefined) {
material.color = OV.GetGltfColor (baseColor);
material.color = GetGltfColor (baseColor);
material.opacity = baseColor[3];
}
let metallicFactor = gltfMaterial.pbrMetallicRoughness.metallicFactor;
@ -683,7 +701,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
}
let emissiveColor = gltfMaterial.emissiveFactor;
if (emissiveColor !== undefined) {
material.emissive = OV.GetGltfColor (emissiveColor);
material.emissive = GetGltfColor (emissiveColor);
}
material.diffuseMap = this.ImportTexture (gltf, gltfMaterial.pbrMetallicRoughness.baseColorTexture);
@ -720,7 +738,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
return null;
}
let texture = new OV.TextureMap ();
let texture = new TextureMap ();
let gltfTexture = gltf.textures[gltfTextureRef.index];
let gltfImageIndex = gltfTexture.source;
let gltfImage = gltf.images[gltfImageIndex];
@ -736,10 +754,10 @@ OV.ImporterGltf = class extends OV.ImporterBase
};
let textureIndexString = gltfImageIndex.toString ();
if (gltfImage.uri !== undefined) {
let base64Buffer = OV.Base64DataURIToArrayBuffer (gltfImage.uri);
let base64Buffer = Base64DataURIToArrayBuffer (gltfImage.uri);
if (base64Buffer !== null) {
textureParams.name = 'Embedded_' + textureIndexString + '.' + OV.GetFileExtensionFromMimeType (base64Buffer.mimeType);
textureParams.url = OV.CreateObjectUrlWithMimeType (base64Buffer.buffer, base64Buffer.mimeType);
textureParams.name = 'Embedded_' + textureIndexString + '.' + GetFileExtensionFromMimeType (base64Buffer.mimeType);
textureParams.url = CreateObjectUrlWithMimeType (base64Buffer.buffer, base64Buffer.mimeType);
textureParams.buffer = base64Buffer.buffer;
} else {
let textureBuffer = this.callbacks.getTextureBuffer (gltfImage.uri);
@ -754,8 +772,8 @@ OV.ImporterGltf = class extends OV.ImporterBase
let reader = this.GetReaderFromBufferView (bufferView);
if (reader !== null) {
let buffer = reader.ReadArrayBuffer (bufferView.byteLength);
textureParams.name = 'Binary_' + textureIndexString + '.' + OV.GetFileExtensionFromMimeType (gltfImage.mimeType);
textureParams.url = OV.CreateObjectUrlWithMimeType (buffer, gltfImage.mimeType);
textureParams.name = 'Binary_' + textureIndexString + '.' + GetFileExtensionFromMimeType (gltfImage.mimeType);
textureParams.url = CreateObjectUrlWithMimeType (buffer, gltfImage.mimeType);
textureParams.buffer = buffer;
}
}
@ -772,7 +790,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
ImportMesh (gltf, gltfMesh)
{
let mesh = new OV.Mesh ();
let mesh = new Mesh ();
this.model.AddMesh (mesh);
if (gltfMesh.name !== undefined) {
mesh.SetName (gltfMesh.name);
@ -800,11 +818,11 @@ OV.ImporterGltf = class extends OV.ImporterBase
let hasUVs = (primitive.attributes.TEXCOORD_0 !== undefined);
let hasIndices = (primitive.indices !== undefined);
let mode = OV.GltfRenderMode.TRIANGLES;
let mode = GltfRenderMode.TRIANGLES;
if (primitive.mode !== undefined) {
mode = primitive.mode;
}
if (mode !== OV.GltfRenderMode.TRIANGLES && mode !== OV.GltfRenderMode.TRIANGLE_STRIP && mode !== OV.GltfRenderMode.TRIANGLE_FAN) {
if (mode !== GltfRenderMode.TRIANGLES && mode !== GltfRenderMode.TRIANGLE_STRIP && mode !== GltfRenderMode.TRIANGLE_FAN) {
return;
}
@ -833,7 +851,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
return;
}
reader.EnumerateData ((data) => {
let color = OV.GetGltfVertexColor ([data.x, data.y, data.z], reader.componentType);
let color = GetGltfVertexColor ([data.x, data.y, data.z], reader.componentType);
mesh.AddVertexColor (color);
});
}
@ -877,14 +895,14 @@ OV.ImporterGltf = class extends OV.ImporterBase
}
}
if (mode === OV.GltfRenderMode.TRIANGLES) {
if (mode === GltfRenderMode.TRIANGLES) {
for (let i = 0; i < vertexIndices.length; i += 3) {
let v0 = vertexIndices[i];
let v1 = vertexIndices[i + 1];
let v2 = vertexIndices[i + 2];
this.AddTriangle (primitive, mesh, v0, v1, v2, hasVertexColors, hasNormals, hasUVs, vertexOffset, vertexColorOffset, normalOffset, uvOffset);
}
} else if (mode === OV.GltfRenderMode.TRIANGLE_STRIP) {
} else if (mode === GltfRenderMode.TRIANGLE_STRIP) {
for (let i = 0; i < vertexIndices.length - 2; i++) {
let v0 = vertexIndices[i];
let v1 = vertexIndices[i + 1];
@ -896,7 +914,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
}
this.AddTriangle (primitive, mesh, v0, v1, v2, hasVertexColors, hasNormals, hasUVs, vertexOffset, vertexColorOffset, normalOffset, uvOffset);
}
} else if (mode === OV.GltfRenderMode.TRIANGLE_FAN) {
} else if (mode === GltfRenderMode.TRIANGLE_FAN) {
for (let i = 1; i < vertexIndices.length - 1; i++) {
let v0 = vertexIndices[0];
let v1 = vertexIndices[i];
@ -908,7 +926,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
AddTriangle (primitive, mesh, v0, v1, v2, hasVertexColors, hasNormals, hasUVs, vertexOffset, vertexColorOffset, normalOffset, uvOffset)
{
let triangle = new OV.Triangle (vertexOffset + v0, vertexOffset + v1, vertexOffset + v2);
let triangle = new Triangle (vertexOffset + v0, vertexOffset + v1, vertexOffset + v2);
if (hasVertexColors) {
triangle.SetVertexColors (
vertexColorOffset + v0,
@ -953,7 +971,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
{
function GetNodeTransformation (gltfNode)
{
let matrix = new OV.Matrix ().CreateIdentity ();
let matrix = new Matrix ().CreateIdentity ();
if (gltfNode.matrix !== undefined) {
matrix.Set (gltfNode.matrix);
} else {
@ -970,19 +988,19 @@ OV.ImporterGltf = class extends OV.ImporterBase
scale = gltfNode.scale;
}
matrix.ComposeTRS (
OV.ArrayToCoord3D (translation),
OV.ArrayToQuaternion (rotation),
OV.ArrayToCoord3D (scale)
ArrayToCoord3D (translation),
ArrayToQuaternion (rotation),
ArrayToCoord3D (scale)
);
}
return new OV.Transformation (matrix);
return new Transformation (matrix);
}
if (gltfNode.children === undefined && gltfNode.mesh === undefined) {
return;
}
let node = new OV.Node ();
let node = new Node ();
if (gltfNode.name !== undefined) {
node.SetName (gltfNode.name);
}
@ -998,7 +1016,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
if (gltfNode.mesh !== undefined) {
if (gltfNode.children === undefined || gltfNode.children.length === 0) {
node.SetType (OV.NodeType.MeshNode);
node.SetType (NodeType.MeshNode);
}
node.AddMeshIndex (gltfNode.mesh);
}
@ -1012,7 +1030,7 @@ OV.ImporterGltf = class extends OV.ImporterBase
return null;
}
let reader = new OV.GltfBufferReader (buffer);
let reader = new GltfBufferReader (buffer);
reader.SkipBytes (bufferView.byteOffset || 0);
let byteStride = bufferView.byteStride;
if (byteStride !== undefined && byteStride !== 0) {
@ -1064,4 +1082,4 @@ OV.ImporterGltf = class extends OV.ImporterBase
reader.SkipBytes (sparseAccessor.byteOffset || 0);
return reader;
}
};
}

View File

@ -1,4 +1,17 @@
OV.ImporterIfc = class extends OV.ImporterBase
import { Coord3D } from '../geometry/coord3d.js';
import { Direction } from '../geometry/geometry.js';
import { Matrix } from '../geometry/matrix.js';
import { Transformation } from '../geometry/transformation.js';
import { LoadExternalLibrary } from '../io/externallibs.js';
import { ColorFromFloatComponents, IntegerToHexString } from '../model/color.js';
import { PhongMaterial } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { Property, PropertyGroup, PropertyType } from '../model/property.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
import { UpdateMaterialTransparency } from './importerutils.js';
export class ImporterIfc extends ImporterBase
{
constructor ()
{
@ -13,7 +26,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
ClearContent ()
@ -31,7 +44,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
ImportContent (fileContent, onFinish)
{
if (this.ifc === null) {
OV.LoadExternalLibrary ('loaders/web-ifc-api-browser.js').then (() => {
LoadExternalLibrary ('loaders/web-ifc-api-browser.js').then (() => {
this.ifc = new WebIFC.IfcAPI ();
this.ifc.Init ().then (() => {
this.ImportIfcContent (fileContent);
@ -65,7 +78,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
ImportIfcMesh (modelID, ifcMesh)
{
let mesh = new OV.Mesh ();
let mesh = new Mesh ();
mesh.SetName ('Mesh ' + ifcMesh.expressID.toString ());
let vertexOffset = 0;
@ -76,14 +89,14 @@ OV.ImporterIfc = class extends OV.ImporterBase
const ifcVertices = this.ifc.GetVertexArray (ifcGeometryData.GetVertexData (), ifcGeometryData.GetVertexDataSize ());
const ifcIndices = this.ifc.GetIndexArray (ifcGeometryData.GetIndexData (), ifcGeometryData.GetIndexDataSize ());
const materialIndex = this.GetMaterialIndexByColor (ifcGeometry.color);
const matrix = new OV.Matrix (ifcGeometry.flatTransformation);
const transformation = new OV.Transformation (matrix);
const matrix = new Matrix (ifcGeometry.flatTransformation);
const transformation = new Transformation (matrix);
for (let i = 0; i < ifcVertices.length; i += 6) {
const x = ifcVertices[i];
const y = ifcVertices[i + 1];
const z = ifcVertices[i + 2];
const coord = new OV.Coord3D (x, y, z);
const coord = new Coord3D (x, y, z);
const transformed = transformation.TransformCoord3D (coord);
mesh.AddVertex (transformed);
}
@ -92,7 +105,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
const v0 = ifcIndices[i];
const v1 = ifcIndices[i + 1];
const v2 = ifcIndices[i + 2];
const triangle = new OV.Triangle (
const triangle = new Triangle (
vertexOffset + v0,
vertexOffset + v1,
vertexOffset + v2
@ -134,7 +147,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
if (!propSet || !propSet.HasProperties) {
return;
}
let propertyGroup = new OV.PropertyGroup (propSet.Name.value);
let propertyGroup = new PropertyGroup (propSet.Name.value);
propSet.HasProperties.forEach ((property) => {
if (!property || !property.Name || !property.NominalValue) {
return;
@ -146,7 +159,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
case 'IFCTEXT':
case 'IFCLABEL':
case 'IFCIDENTIFIER':
elemProperty = new OV.Property (OV.PropertyType.Text, propertyName, this.GetIFCString (property.NominalValue.value));
elemProperty = new Property (PropertyType.Text, propertyName, this.GetIFCString (property.NominalValue.value));
break;
case 'IFCBOOLEAN':
case 'IFCLOGICAL':
@ -156,11 +169,11 @@ OV.ImporterIfc = class extends OV.ImporterBase
} else if (property.NominalValue.value === 'F') {
strValue = 'False';
}
elemProperty = new OV.Property (OV.PropertyType.Text, propertyName, strValue);
elemProperty = new Property (PropertyType.Text, propertyName, strValue);
break;
case 'IFCINTEGER':
case 'IFCCOUNTMEASURE':
elemProperty = new OV.Property (OV.PropertyType.Integer, propertyName, property.NominalValue.value);
elemProperty = new Property (PropertyType.Integer, propertyName, property.NominalValue.value);
break;
case 'IFCREAL':
case 'IFCLENGTHMEASURE':
@ -173,7 +186,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
case 'IFCMASSPERLENGTHMEASURE':
case 'IFCPLANEANGLEMEASURE':
case 'IFCTHERMALTRANSMITTANCEMEASURE':
elemProperty = new OV.Property (OV.PropertyType.Number, propertyName, property.NominalValue.value);
elemProperty = new Property (PropertyType.Number, propertyName, property.NominalValue.value);
break;
default:
// TODO
@ -194,22 +207,22 @@ OV.ImporterIfc = class extends OV.ImporterBase
GetMaterialIndexByColor (ifcColor)
{
const color = OV.ColorFromFloatComponents (ifcColor.x, ifcColor.y, ifcColor.z);
const color = ColorFromFloatComponents (ifcColor.x, ifcColor.y, ifcColor.z);
const materialName = 'Color ' +
OV.IntegerToHexString (color.r) +
OV.IntegerToHexString (color.g) +
OV.IntegerToHexString (color.b) +
OV.IntegerToHexString (parseInt (ifcColor.w * 255.0, 10));
IntegerToHexString (color.r) +
IntegerToHexString (color.g) +
IntegerToHexString (color.b) +
IntegerToHexString (parseInt (ifcColor.w * 255.0, 10));
if (this.materialNameToIndex.has (materialName)) {
return this.materialNameToIndex.get (materialName);
} else {
let material = new OV.PhongMaterial ();
let material = new PhongMaterial ();
material.name = materialName;
material.color = color;
material.opacity = ifcColor.w;
OV.UpdateMaterialTransparency (material);
UpdateMaterialTransparency (material);
let materialIndex = this.model.AddMaterial (material);
this.materialNameToIndex.set (materialName, materialIndex);
return materialIndex;
@ -238,4 +251,4 @@ OV.ImporterIfc = class extends OV.ImporterBase
}
return resultString;
}
};
}

View File

@ -1,4 +1,18 @@
OV.ImporterO3dv = class extends OV.ImporterBase
import { ValueOrDefault } from '../core/core.js';
import { ArrayToCoord3D, Coord3D } from '../geometry/coord3d.js';
import { Direction } from '../geometry/geometry.js';
import { Matrix } from '../geometry/matrix.js';
import { ArrayToQuaternion, Quaternion } from '../geometry/quaternion.js';
import { Transformation } from '../geometry/transformation.js';
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
import { ArrayToColor } from '../model/color.js';
import { GenerateCuboid, GenerateCylinder, GeneratePlatonicSolid, GenerateSphere, GeneratorParams } from '../model/generator.js';
import { PhysicalMaterial } from '../model/material.js';
import { Node, NodeType } from '../model/node.js';
import { Property, PropertyGroup, PropertyType } from '../model/property.js';
import { ImporterBase } from './importerbase.js';
export class ImporterO3dv extends ImporterBase
{
constructor ()
{
@ -12,7 +26,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
ClearContent ()
@ -27,7 +41,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase
ImportContent (fileContent, onFinish)
{
let textContent = OV.ArrayBufferToUtf8String (fileContent);
let textContent = ArrayBufferToUtf8String (fileContent);
let content = JSON.parse (textContent);
if (content.root === undefined) {
onFinish ();
@ -56,22 +70,22 @@ OV.ImporterO3dv = class extends OV.ImporterBase
ImportMaterial (materialContent)
{
let material = new OV.PhysicalMaterial ();
let material = new PhysicalMaterial ();
material.color.Set (255, 255, 255);
if (materialContent.name !== undefined) {
material.name = materialContent.name;
}
if (materialContent.color !== undefined) {
material.color = OV.ArrayToColor (materialContent.color);
material.color = ArrayToColor (materialContent.color);
}
material.metalness = OV.ValueOrDefault (materialContent.metalness, 0.0);
material.roughness = OV.ValueOrDefault (materialContent.roughness, 1.0);
material.metalness = ValueOrDefault (materialContent.metalness, 0.0);
material.roughness = ValueOrDefault (materialContent.roughness, 1.0);
this.model.AddMaterial (material);
}
ImportMesh (meshContent)
{
let genParams = new OV.GeneratorParams ();
let genParams = new GeneratorParams ();
if (meshContent.name !== undefined) {
genParams.SetName (meshContent.name);
}
@ -89,27 +103,27 @@ OV.ImporterO3dv = class extends OV.ImporterBase
if (parameters.size_x === undefined || parameters.size_y === undefined || parameters.size_z === undefined) {
return;
}
mesh = OV.GenerateCuboid (genParams, parameters.size_x, parameters.size_y, parameters.size_z);
mesh = GenerateCuboid (genParams, parameters.size_x, parameters.size_y, parameters.size_z);
} else if (meshContent.type === 'cylinder') {
if (parameters.radius === undefined || parameters.height === undefined) {
return;
}
let segments = OV.ValueOrDefault (parameters.segments, 25);
let smooth = OV.ValueOrDefault (parameters.smooth, true);
mesh = OV.GenerateCylinder (genParams, parameters.radius, parameters.height, segments, smooth);
let segments = ValueOrDefault (parameters.segments, 25);
let smooth = ValueOrDefault (parameters.smooth, true);
mesh = GenerateCylinder (genParams, parameters.radius, parameters.height, segments, smooth);
} else if (meshContent.type === 'sphere') {
if (parameters.radius === undefined) {
return;
}
let segments = OV.ValueOrDefault (parameters.segments, 20);
let smooth = OV.ValueOrDefault (parameters.smooth, true);
mesh = OV.GenerateSphere (genParams, parameters.radius, segments, smooth);
let segments = ValueOrDefault (parameters.segments, 20);
let smooth = ValueOrDefault (parameters.smooth, true);
mesh = GenerateSphere (genParams, parameters.radius, segments, smooth);
} else if (meshContent.type === 'platonic') {
if (parameters.solid_type === undefined) {
return;
}
let radius = OV.ValueOrDefault (parameters.radius, 1.0);
mesh = OV.GeneratePlatonicSolid (genParams, parameters.solid_type, radius);
let radius = ValueOrDefault (parameters.radius, 1.0);
mesh = GeneratePlatonicSolid (genParams, parameters.solid_type, radius);
}
if (mesh !== null) {
this.ImportProperties (mesh, meshContent);
@ -129,14 +143,14 @@ OV.ImporterO3dv = class extends OV.ImporterBase
if (nodeContent.children !== undefined) {
for (const childIndex of nodeContent.children) {
let childContent = content.nodes[childIndex];
let childNode = new OV.Node ();
let childNode = new Node ();
node.AddChildNode (childNode);
this.ImportNode (content, childContent, childNode);
}
}
if (nodeContent.mesh !== undefined) {
if (nodeContent.children === undefined || nodeContent.children.length === 0) {
node.SetType (OV.NodeType.MeshNode);
node.SetType (NodeType.MeshNode);
}
node.AddMeshIndex (nodeContent.mesh);
}
@ -145,10 +159,10 @@ OV.ImporterO3dv = class extends OV.ImporterBase
ImportProperties (element, nodeContent)
{
if (nodeContent.properties !== undefined) {
const propertyGroup = new OV.PropertyGroup ('Properties');
const propertyGroup = new PropertyGroup ('Properties');
element.AddPropertyGroup (propertyGroup);
for (const nodeProperty of nodeContent.properties) {
const property = new OV.Property (OV.PropertyType.Text, nodeProperty.name, nodeProperty.value);
const property = new Property (PropertyType.Text, nodeProperty.name, nodeProperty.value);
propertyGroup.AddProperty (property);
}
}
@ -156,19 +170,19 @@ OV.ImporterO3dv = class extends OV.ImporterBase
GetTransformation (contentTransformation)
{
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0);
let scale = new OV.Coord3D (1.0, 1.0, 1.0);
let translation = new Coord3D (0.0, 0.0, 0.0);
let rotation = new Quaternion (0.0, 0.0, 0.0, 1.0);
let scale = new Coord3D (1.0, 1.0, 1.0);
if (contentTransformation.translation !== undefined) {
translation = OV.ArrayToCoord3D (contentTransformation.translation);
translation = ArrayToCoord3D (contentTransformation.translation);
}
if (contentTransformation.rotation !== undefined) {
rotation = OV.ArrayToQuaternion (contentTransformation.rotation);
rotation = ArrayToQuaternion (contentTransformation.rotation);
}
if (contentTransformation.scale !== undefined) {
scale = OV.ArrayToCoord3D (contentTransformation.scale);
scale = ArrayToCoord3D (contentTransformation.scale);
}
const matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale);
return new OV.Transformation (matrix);
const matrix = new Matrix ().ComposeTRS (translation, rotation, scale);
return new Transformation (matrix);
}
};
}

View File

@ -1,4 +1,15 @@
OV.ObjMeshConverter = class
import { Coord2D } from '../geometry/coord2d.js';
import { Coord3D } from '../geometry/coord3d.js';
import { Direction } from '../geometry/geometry.js';
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
import { ColorFromFloatComponents } from '../model/color.js';
import { PhongMaterial, TextureMap } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
import { NameFromLine, ParametersFromLine, ReadLines, UpdateMaterialTransparency } from './importerutils.js';
export class ObjMeshConverter
{
constructor (mesh)
{
@ -11,21 +22,21 @@ OV.ObjMeshConverter = class
AddVertex (globalIndex, globalVertices)
{
return this.GetLocalIndex (globalIndex, globalVertices, this.globalToMeshVertices, (val) => {
return this.mesh.AddVertex (new OV.Coord3D (val.x, val.y, val.z));
return this.mesh.AddVertex (new Coord3D (val.x, val.y, val.z));
});
}
AddNormal (globalIndex, globalNormals)
{
return this.GetLocalIndex (globalIndex, globalNormals, this.globalToMeshNormals, (val) => {
return this.mesh.AddNormal (new OV.Coord3D (val.x, val.y, val.z));
return this.mesh.AddNormal (new Coord3D (val.x, val.y, val.z));
});
}
AddUV (globalIndex, globalUvs)
{
return this.GetLocalIndex (globalIndex, globalUvs, this.globalToMeshUvs, (val) => {
return this.mesh.AddTextureUV (new OV.Coord2D (val.x, val.y));
return this.mesh.AddTextureUV (new Coord2D (val.x, val.y));
});
}
@ -48,9 +59,9 @@ OV.ObjMeshConverter = class
return localIndex;
}
}
};
}
OV.ImporterObj = class extends OV.ImporterBase
export class ImporterObj extends ImporterBase
{
constructor ()
{
@ -64,7 +75,7 @@ OV.ImporterObj = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
ClearContent ()
@ -97,8 +108,8 @@ OV.ImporterObj = class extends OV.ImporterBase
ImportContent (fileContent, onFinish)
{
let textContent = OV.ArrayBufferToUtf8String (fileContent);
OV.ReadLines (textContent, (line) => {
let textContent = ArrayBufferToUtf8String (fileContent);
ReadLines (textContent, (line) => {
if (!this.WasError ()) {
this.ProcessLine (line);
}
@ -112,7 +123,7 @@ OV.ImporterObj = class extends OV.ImporterBase
return;
}
let parameters = OV.ParametersFromLine (line, '#');
let parameters = ParametersFromLine (line, '#');
if (parameters.length === 0) {
return;
}
@ -134,10 +145,10 @@ OV.ImporterObj = class extends OV.ImporterBase
if (this.meshNameToConverter.has (name)) {
this.currentMeshConverter = this.meshNameToConverter.get (name);
} else {
let mesh = new OV.Mesh ();
let mesh = new Mesh ();
mesh.SetName (name);
this.model.AddMeshToRootNode (mesh);
this.currentMeshConverter = new OV.ObjMeshConverter (mesh);
this.currentMeshConverter = new ObjMeshConverter (mesh);
this.meshNameToConverter.set (name, this.currentMeshConverter);
}
}
@ -148,14 +159,14 @@ OV.ImporterObj = class extends OV.ImporterBase
if (parameters.length === 0) {
return true;
}
let name = OV.NameFromLine (line, keyword.length, '#');
let name = NameFromLine (line, keyword.length, '#');
this.AddNewMesh (name);
return true;
} else if (keyword === 'v') {
if (parameters.length < 3) {
return true;
}
this.globalVertices.push (new OV.Coord3D (
this.globalVertices.push (new Coord3D (
parseFloat (parameters[0]),
parseFloat (parameters[1]),
parseFloat (parameters[2])
@ -165,7 +176,7 @@ OV.ImporterObj = class extends OV.ImporterBase
if (parameters.length < 3) {
return true;
}
this.globalNormals.push (new OV.Coord3D (
this.globalNormals.push (new Coord3D (
parseFloat (parameters[0]),
parseFloat (parameters[1]),
parseFloat (parameters[2])
@ -175,7 +186,7 @@ OV.ImporterObj = class extends OV.ImporterBase
if (parameters.length < 2) {
return true;
}
this.globalUvs.push (new OV.Coord2D (
this.globalUvs.push (new Coord2D (
parseFloat (parameters[0]),
parseFloat (parameters[1])
));
@ -195,8 +206,8 @@ OV.ImporterObj = class extends OV.ImporterBase
{
function CreateTexture (keyword, line, callbacks)
{
let texture = new OV.TextureMap ();
let textureName = OV.NameFromLine (line, keyword.length, '#');
let texture = new TextureMap ();
let textureName = NameFromLine (line, keyword.length, '#');
let textureBuffer = callbacks.getTextureBuffer (textureName);
texture.name = textureName;
if (textureBuffer !== null) {
@ -211,8 +222,8 @@ OV.ImporterObj = class extends OV.ImporterBase
return true;
}
let material = new OV.PhongMaterial ();
let materialName = OV.NameFromLine (line, keyword.length, '#');
let material = new PhongMaterial ();
let materialName = NameFromLine (line, keyword.length, '#');
let materialIndex = this.model.AddMaterial (material);
material.name = materialName;
this.currentMaterial = material;
@ -223,7 +234,7 @@ OV.ImporterObj = class extends OV.ImporterBase
return true;
}
let materialName = OV.NameFromLine (line, keyword.length, '#');
let materialName = NameFromLine (line, keyword.length, '#');
if (this.materialNameToIndex.has (materialName)) {
this.currentMaterialIndex = this.materialNameToIndex.get (materialName);
}
@ -232,11 +243,11 @@ OV.ImporterObj = class extends OV.ImporterBase
if (parameters.length === 0) {
return true;
}
let fileName = OV.NameFromLine (line, keyword.length, '#');
let fileName = NameFromLine (line, keyword.length, '#');
let fileBuffer = this.callbacks.getFileBuffer (fileName);
if (fileBuffer !== null) {
let textContent = OV.ArrayBufferToUtf8String (fileBuffer);
OV.ReadLines (textContent, (line) => {
let textContent = ArrayBufferToUtf8String (fileBuffer);
ReadLines (textContent, (line) => {
if (!this.WasError ()) {
this.ProcessLine (line);
}
@ -248,7 +259,7 @@ OV.ImporterObj = class extends OV.ImporterBase
return true;
}
this.currentMaterial.diffuseMap = CreateTexture (keyword, line, this.callbacks);
OV.UpdateMaterialTransparency (this.currentMaterial);
UpdateMaterialTransparency (this.currentMaterial);
return true;
} else if (keyword === 'map_ks') {
if (this.currentMaterial === null || parameters.length === 0) {
@ -266,19 +277,19 @@ OV.ImporterObj = class extends OV.ImporterBase
if (this.currentMaterial === null || parameters.length < 3) {
return true;
}
this.currentMaterial.ambient = OV.ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
this.currentMaterial.ambient = ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
return true;
} else if (keyword === 'kd') {
if (this.currentMaterial === null || parameters.length < 3) {
return true;
}
this.currentMaterial.color = OV.ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
this.currentMaterial.color = ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
return true;
} else if (keyword === 'ks') {
if (this.currentMaterial === null || parameters.length < 3) {
return true;
}
this.currentMaterial.specular = OV.ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
this.currentMaterial.specular = ColorFromFloatComponents (parameters[0], parameters[1], parameters[2]);
return true;
} else if (keyword === 'ns') {
if (this.currentMaterial === null || parameters.length < 1) {
@ -291,14 +302,14 @@ OV.ImporterObj = class extends OV.ImporterBase
return true;
}
this.currentMaterial.opacity = 1.0 - parseFloat (parameters[0]);
OV.UpdateMaterialTransparency (this.currentMaterial);
UpdateMaterialTransparency (this.currentMaterial);
return true;
} else if (keyword === 'd') {
if (this.currentMaterial === null || parameters.length < 1) {
return true;
}
this.currentMaterial.opacity = parseFloat (parameters[0]);
OV.UpdateMaterialTransparency (this.currentMaterial);
UpdateMaterialTransparency (this.currentMaterial);
return true;
}
@ -343,7 +354,7 @@ OV.ImporterObj = class extends OV.ImporterBase
this.SetError ('Invalid vertex index.');
break;
}
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
if (normals.length === vertices.length) {
let n0 = this.currentMeshConverter.AddNormal (normals[0], this.globalNormals);
let n1 = this.currentMeshConverter.AddNormal (normals[i + 1], this.globalNormals);
@ -370,4 +381,4 @@ OV.ImporterObj = class extends OV.ImporterBase
this.currentMeshConverter.AddTriangle (triangle);
}
}
};
}

View File

@ -1,4 +1,12 @@
OV.ImporterOff = class extends OV.ImporterBase
import { Coord3D } from '../geometry/coord3d.js';
import { Direction } from '../geometry/geometry.js';
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
import { Mesh } from '../model/mesh.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
import { ParametersFromLine, ReadLines } from './importerutils.js';
export class ImporterOff extends ImporterBase
{
constructor ()
{
@ -12,7 +20,7 @@ OV.ImporterOff = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
ClearContent ()
@ -23,7 +31,7 @@ OV.ImporterOff = class extends OV.ImporterBase
ResetContent ()
{
this.mesh = new OV.Mesh ();
this.mesh = new Mesh ();
this.model.AddMeshToRootNode (this.mesh);
this.status = {
vertexCount : 0,
@ -35,8 +43,8 @@ OV.ImporterOff = class extends OV.ImporterBase
ImportContent (fileContent, onFinish)
{
let textContent = OV.ArrayBufferToUtf8String (fileContent);
OV.ReadLines (textContent, (line) => {
let textContent = ArrayBufferToUtf8String (fileContent);
ReadLines (textContent, (line) => {
if (!this.WasError ()) {
this.ProcessLine (line);
}
@ -50,7 +58,7 @@ OV.ImporterOff = class extends OV.ImporterBase
return;
}
let parameters = OV.ParametersFromLine (line, '#');
let parameters = ParametersFromLine (line, '#');
if (parameters.length === 0) {
return;
}
@ -69,7 +77,7 @@ OV.ImporterOff = class extends OV.ImporterBase
if (this.status.foundVertex < this.status.vertexCount) {
if (parameters.length >= 3) {
this.mesh.AddVertex (new OV.Coord3D (
this.mesh.AddVertex (new Coord3D (
parseFloat (parameters[0]),
parseFloat (parameters[1]),
parseFloat (parameters[2])
@ -89,7 +97,7 @@ OV.ImporterOff = class extends OV.ImporterBase
let v0 = parseInt (parameters[1]);
let v1 = parseInt (parameters[i + 2]);
let v2 = parseInt (parameters[i + 3]);
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
this.mesh.AddTriangle (triangle);
}
this.status.foundFace += 1;
@ -97,4 +105,4 @@ OV.ImporterOff = class extends OV.ImporterBase
return;
}
}
};
}

View File

@ -1,4 +1,15 @@
OV.PlyHeaderCheckResult =
import { Coord3D } from '../geometry/coord3d.js';
import { Direction } from '../geometry/geometry.js';
import { BinaryReader } from '../io/binaryreader.js';
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
import { Color, IntegerToHexString } from '../model/color.js';
import { PhongMaterial } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
import { ParametersFromLine, ReadLines, UpdateMaterialTransparency } from './importerutils.js';
export const PlyHeaderCheckResult =
{
Ok : 1,
NoVertices : 2,
@ -6,7 +17,7 @@ OV.PlyHeaderCheckResult =
UnknownError : 4
};
OV.PlyHeader = class
export class PlyHeader
{
constructor ()
{
@ -69,30 +80,30 @@ OV.PlyHeader = class
{
let vertex = this.GetElement ('vertex');
if (vertex === null || vertex.length === 0 || vertex.format.length < 3) {
return OV.PlyHeaderCheckResult.NoVertices;
return PlyHeaderCheckResult.NoVertices;
}
let face = this.GetElement ('face');
if (this.format === 'ascii') {
if (face === null || face.count === 0 || face.format.length < 0) {
return OV.PlyHeaderCheckResult.NoFaces;
return PlyHeaderCheckResult.NoFaces;
}
} else if (this.format === 'binary_little_endian' || this.format === 'binary_big_endian') {
let triStrips = this.GetElement ('tristrips');
let hasFaces = (face !== null && face.count > 0 && face.format.length > 0);
let hasTriStrips = (triStrips !== null && triStrips.count > 0 && triStrips.format.length > 0);
if (!hasFaces && !hasTriStrips) {
return OV.PlyHeaderCheckResult.NoFaces;
return PlyHeaderCheckResult.NoFaces;
}
} else {
return OV.PlyHeaderCheckResult.UnknownError;
return PlyHeaderCheckResult.UnknownError;
}
return OV.PlyHeaderCheckResult.Ok;
return PlyHeaderCheckResult.Ok;
}
};
}
OV.PlyMaterialHandler = class
export class PlyMaterialHandler
{
constructor (model)
{
@ -103,27 +114,27 @@ OV.PlyMaterialHandler = class
GetMaterialIndexByColor (color)
{
let materialName = 'Color ' +
OV.IntegerToHexString (color[0]) +
OV.IntegerToHexString (color[1]) +
OV.IntegerToHexString (color[2]) +
OV.IntegerToHexString (color[3]);
IntegerToHexString (color[0]) +
IntegerToHexString (color[1]) +
IntegerToHexString (color[2]) +
IntegerToHexString (color[3]);
if (this.colorToMaterial.has (materialName)) {
return this.colorToMaterial.get (materialName);
} else {
let material = new OV.PhongMaterial ();
let material = new PhongMaterial ();
material.name = materialName;
material.color = new OV.Color (color[0], color[1], color[2]);
material.color = new Color (color[0], color[1], color[2]);
material.opacity = color[3] / 255.0;
OV.UpdateMaterialTransparency (material);
UpdateMaterialTransparency (material);
let materialIndex = this.model.AddMaterial (material);
this.colorToMaterial.set (materialName, materialIndex);
return materialIndex;
}
}
};
}
OV.ImporterPly = class extends OV.ImporterBase
export class ImporterPly extends ImporterBase
{
constructor ()
{
@ -137,7 +148,7 @@ OV.ImporterPly = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
ClearContent ()
@ -147,7 +158,7 @@ OV.ImporterPly = class extends OV.ImporterBase
ResetContent ()
{
this.mesh = new OV.Mesh ();
this.mesh = new Mesh ();
this.model.AddMeshToRootNode (this.mesh);
}
@ -156,18 +167,18 @@ OV.ImporterPly = class extends OV.ImporterBase
let headerString = this.GetHeaderContent (fileContent);
let header = this.ReadHeader (headerString);
let checkResult = header.Check ();
if (checkResult === OV.PlyHeaderCheckResult.Ok) {
if (checkResult === PlyHeaderCheckResult.Ok) {
if (header.format === 'ascii') {
let contentString = OV.ArrayBufferToUtf8String (fileContent);
let contentString = ArrayBufferToUtf8String (fileContent);
contentString = contentString.substr (headerString.length);
this.ReadAsciiContent (header, contentString);
} else if (header.format === 'binary_little_endian' || header.format === 'binary_big_endian') {
this.ReadBinaryContent (header, fileContent, headerString.length);
}
} else {
if (checkResult === OV.PlyHeaderCheckResult.NoVertices) {
if (checkResult === PlyHeaderCheckResult.NoVertices) {
this.SetError ('The model contains no vertices.');
} else if (checkResult === OV.PlyHeaderCheckResult.NoFaces) {
} else if (checkResult === PlyHeaderCheckResult.NoFaces) {
this.SetError ('The model contains no faces.');
} else {
this.SetError ('Invalid header information.');
@ -201,9 +212,9 @@ OV.ImporterPly = class extends OV.ImporterBase
ReadHeader (headerContent)
{
let header = new OV.PlyHeader ();
OV.ReadLines (headerContent, (line) => {
let parameters = OV.ParametersFromLine (line, null);
let header = new PlyHeader ();
ReadLines (headerContent, (line) => {
let parameters = ParametersFromLine (line, null);
if (parameters.length === 0 || parameters[0] === 'comment') {
return;
}
@ -232,19 +243,19 @@ OV.ImporterPly = class extends OV.ImporterBase
let face = header.GetElement ('face');
let foundVertex = 0;
let foundFace = 0;
OV.ReadLines (fileContent, (line) => {
ReadLines (fileContent, (line) => {
if (this.WasError ()) {
return;
}
let parameters = OV.ParametersFromLine (line, null);
let parameters = ParametersFromLine (line, null);
if (parameters.length === 0 || parameters[0] === 'comment') {
return;
}
if (foundVertex < vertex.count) {
if (parameters.length >= 3) {
this.mesh.AddVertex (new OV.Coord3D (
this.mesh.AddVertex (new Coord3D (
parseFloat (parameters[0]),
parseFloat (parameters[1]),
parseFloat (parameters[2])
@ -264,7 +275,7 @@ OV.ImporterPly = class extends OV.ImporterBase
let v0 = parseInt (parameters[1]);
let v1 = parseInt (parameters[i + 2]);
let v2 = parseInt (parameters[i + 3]);
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
this.mesh.AddTriangle (triangle);
}
foundFace += 1;
@ -349,15 +360,15 @@ OV.ImporterPly = class extends OV.ImporterBase
let reader = null;
if (header.format === 'binary_little_endian') {
reader = new OV.BinaryReader (fileContent, true);
reader = new BinaryReader (fileContent, true);
} else if (header.format === 'binary_big_endian') {
reader = new OV.BinaryReader (fileContent, false);
reader = new BinaryReader (fileContent, false);
} else {
return;
}
reader.Skip (headerLength);
let materialHandler = new OV.PlyMaterialHandler (this.model);
let materialHandler = new PlyMaterialHandler (this.model);
let elements = header.GetElements ();
for (let elementIndex = 0; elementIndex < elements.length; elementIndex++) {
let element = elements[elementIndex];
@ -368,9 +379,9 @@ OV.ImporterPly = class extends OV.ImporterBase
let z = ReadByFormat (reader, element.format[2]);
let color = SkipAndGetColor (reader, element.format, 3);
if (color !== null) {
this.mesh.AddVertexColor (new OV.Color (color[0], color[1], color[2]));
this.mesh.AddVertexColor (new Color (color[0], color[1], color[2]));
}
this.mesh.AddVertex (new OV.Coord3D (x, y, z));
this.mesh.AddVertex (new Coord3D (x, y, z));
}
} else if (element.name === 'face') {
for (let faceIndex = 0; faceIndex < element.count; faceIndex++) {
@ -380,7 +391,7 @@ OV.ImporterPly = class extends OV.ImporterBase
let v0 = vertices[0];
let v1 = vertices[i + 1];
let v2 = vertices[i + 2];
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
if (faceColor !== null) {
triangle.mat = materialHandler.GetMaterialIndexByColor (faceColor);
} else if (this.mesh.VertexColorCount () > 0) {
@ -409,7 +420,7 @@ OV.ImporterPly = class extends OV.ImporterBase
v2 = tmp;
}
ccw = !ccw;
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
this.mesh.AddTriangle (triangle);
}
}
@ -418,4 +429,4 @@ OV.ImporterPly = class extends OV.ImporterBase
}
}
}
};
}

View File

@ -1,4 +1,13 @@
OV.ImporterStl = class extends OV.ImporterBase
import { Coord3D } from '../geometry/coord3d.js';
import { Direction, IsPositive } from '../geometry/geometry.js';
import { BinaryReader } from '../io/binaryreader.js';
import { ArrayBufferToUtf8String } from '../io/bufferutils.js';
import { Mesh } from '../model/mesh.js';
import { Triangle } from '../model/triangle.js';
import { ImporterBase } from './importerbase.js';
import { NameFromLine, ParametersFromLine, ReadLines } from './importerutils.js';
export class ImporterStl extends ImporterBase
{
constructor ()
{
@ -12,7 +21,7 @@ OV.ImporterStl = class extends OV.ImporterBase
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
ClearContent ()
@ -23,7 +32,7 @@ OV.ImporterStl = class extends OV.ImporterBase
ResetContent ()
{
this.mesh = new OV.Mesh ();
this.mesh = new Mesh ();
this.model.AddMeshToRootNode (this.mesh);
this.triangle = null;
}
@ -33,8 +42,8 @@ OV.ImporterStl = class extends OV.ImporterBase
if (this.IsBinaryStlFile (fileContent)) {
this.ProcessBinary (fileContent);
} else {
let textContent = OV.ArrayBufferToUtf8String (fileContent);
OV.ReadLines (textContent, (line) => {
let textContent = ArrayBufferToUtf8String (fileContent);
ReadLines (textContent, (line) => {
if (!this.WasError ()) {
this.ProcessLine (line);
}
@ -50,7 +59,7 @@ OV.ImporterStl = class extends OV.ImporterBase
return false;
}
let reader = new OV.BinaryReader (fileContent, true);
let reader = new BinaryReader (fileContent, true);
reader.Skip (80);
let triangleCount = reader.ReadUnsignedInteger32 ();
@ -67,7 +76,7 @@ OV.ImporterStl = class extends OV.ImporterBase
return;
}
let parameters = OV.ParametersFromLine (line, '#');
let parameters = ParametersFromLine (line, '#');
if (parameters.length === 0) {
return;
}
@ -75,21 +84,21 @@ OV.ImporterStl = class extends OV.ImporterBase
let keyword = parameters[0];
if (keyword === 'solid') {
if (parameters.length > 1) {
let name = OV.NameFromLine (line, keyword.length, '#');
let name = NameFromLine (line, keyword.length, '#');
this.mesh.SetName (name);
}
return;
}
if (keyword === 'facet') {
this.triangle = new OV.Triangle (-1, -1, -1);
this.triangle = new Triangle (-1, -1, -1);
if (parameters.length >= 5 && parameters[1] === 'normal') {
let normalVector = new OV.Coord3D (
let normalVector = new Coord3D (
parseFloat (parameters[2]),
parseFloat (parameters[3]),
parseFloat (parameters[4])
);
if (OV.IsPositive (normalVector.Length ())) {
if (IsPositive (normalVector.Length ())) {
let normalIndex = this.mesh.AddNormal (normalVector);
this.triangle.SetNormals (
normalIndex,
@ -103,7 +112,7 @@ OV.ImporterStl = class extends OV.ImporterBase
if (keyword === 'vertex' && this.triangle !== null) {
if (parameters.length >= 4) {
let vertexIndex = this.mesh.AddVertex (new OV.Coord3D (
let vertexIndex = this.mesh.AddVertex (new Coord3D (
parseFloat (parameters[1]),
parseFloat (parameters[2]),
parseFloat (parameters[3])
@ -132,7 +141,7 @@ OV.ImporterStl = class extends OV.ImporterBase
{
function ReadVector (reader)
{
let coord = new OV.Coord3D ();
let coord = new Coord3D ();
coord.x = reader.ReadFloat32 ();
coord.y = reader.ReadFloat32 ();
coord.z = reader.ReadFloat32 ();
@ -145,7 +154,7 @@ OV.ImporterStl = class extends OV.ImporterBase
return mesh.AddVertex (coord);
}
let reader = new OV.BinaryReader (fileContent, true);
let reader = new BinaryReader (fileContent, true);
reader.Skip (80);
let triangleCount = reader.ReadUnsignedInteger32 ();
for (let i = 0; i < triangleCount; i++) {
@ -154,12 +163,12 @@ OV.ImporterStl = class extends OV.ImporterBase
let v1 = AddVertex (this.mesh, reader);
let v2 = AddVertex (this.mesh, reader);
reader.Skip (2);
let triangle = new OV.Triangle (v0, v1, v2);
if (OV.IsPositive (normalVector.Length ())) {
let triangle = new Triangle (v0, v1, v2);
if (IsPositive (normalVector.Length ())) {
let normal = this.mesh.AddNormal (normalVector);
triangle.SetNormals (normal, normal, normal);
}
this.mesh.AddTriangle (triangle);
}
}
};
}

View File

@ -1,4 +1,7 @@
OV.ImporterThreeSvg = class extends OV.ImporterThreeBase
import { Direction } from '../geometry/geometry.js';
import { ImporterThreeBase } from './importerthree.js';
export class ImporterThreeSvg extends ImporterThreeBase
{
constructor ()
{
@ -12,7 +15,7 @@ OV.ImporterThreeSvg = class extends OV.ImporterThreeBase
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
GetExternalLibraries ()
@ -85,4 +88,4 @@ OV.ImporterThreeSvg = class extends OV.ImporterThreeBase
}
return object;
}
};
}

View File

@ -1,4 +1,16 @@
OV.ImporterThreeBase = class extends OV.ImporterBase
import { WaitWhile } from '../core/taskrunner.js';
import { Direction } from '../geometry/geometry.js';
import { Matrix } from '../geometry/matrix.js';
import { Transformation } from '../geometry/transformation.js';
import { Base64DataURIToArrayBuffer, CreateObjectUrl, GetFileExtensionFromMimeType } from '../io/bufferutils.js';
import { LoadExternalLibrary } from '../io/externallibs.js';
import { GetFileExtension, GetFileName } from '../io/fileutils.js';
import { PhongMaterial, TextureMap } from '../model/material.js';
import { Node, NodeType } from '../model/node.js';
import { ConvertThreeColorToColor, ConvertThreeGeometryToMesh } from '../threejs/threeutils.js';
import { ImporterBase } from './importerbase.js';
export class ImporterThreeBase extends ImporterBase
{
constructor ()
{
@ -45,7 +57,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
{
try {
for (let i = 0; i < libraries.length; i++) {
await OV.LoadExternalLibrary (libraries[i]);
await LoadExternalLibrary (libraries[i]);
}
} catch (err) {
onError ();
@ -73,17 +85,17 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
isAllLoadersDone = true;
});
const mainFileUrl = OV.CreateObjectUrl (fileContent);
const mainFileUrl = CreateObjectUrl (fileContent);
loadingManager.setURLModifier ((url) => {
if (url === mainFileUrl) {
return url;
}
const name = OV.GetFileName (url);
const extension = OV.GetFileExtension (url);
const name = GetFileName (url);
const extension = GetFileExtension (url);
if (extension.length > 0) {
const buffer = this.callbacks.getFileBuffer (url);
if (buffer !== null) {
let objectUrl = OV.CreateObjectUrl (buffer);
let objectUrl = CreateObjectUrl (buffer);
this.objectUrlToFileName.set (objectUrl, name);
return objectUrl;
}
@ -99,7 +111,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
threeLoader.load (mainFileUrl,
(object) => {
OV.WaitWhile (() => {
WaitWhile (() => {
if (isAllLoadersDone) {
this.OnThreeObjectsLoaded (object, onFinish);
return false;
@ -120,17 +132,17 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
{
function GetObjectTransformation (threeObject)
{
let matrix = new OV.Matrix ().CreateIdentity ();
let matrix = new Matrix ().CreateIdentity ();
threeObject.updateMatrix ();
if (threeObject.matrix !== undefined && threeObject.matrix !== null) {
matrix.Set (threeObject.matrix.elements);
}
return new OV.Transformation (matrix);
return new Transformation (matrix);
}
function AddObject (importer, model, threeObject, parentNode)
{
let node = new OV.Node ();
let node = new Node ();
if (threeObject.name !== undefined) {
node.SetName (threeObject.name);
}
@ -142,7 +154,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
}
if (threeObject.isMesh && importer.IsMeshVisible (threeObject)) {
if (threeObject.children.length === 0) {
node.SetType (OV.NodeType.MeshNode);
node.SetType (NodeType.MeshNode);
}
let mesh = importer.ConvertThreeMesh (threeObject);
let meshIndex = model.AddMesh (mesh);
@ -164,7 +176,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
{
let mesh = null;
if (Array.isArray (threeMesh.material)) {
mesh = OV.ConvertThreeGeometryToMesh (threeMesh.geometry, null);
mesh = ConvertThreeGeometryToMesh (threeMesh.geometry, null);
if (threeMesh.geometry.attributes.color === undefined || threeMesh.geometry.attributes.color === null) {
let materialIndices = [];
for (let i = 0; i < threeMesh.material.length; i++) {
@ -188,7 +200,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
}
} else {
const materialIndex = this.FindOrCreateMaterial (threeMesh.material);
mesh = OV.ConvertThreeGeometryToMesh (threeMesh.geometry, materialIndex);
mesh = ConvertThreeGeometryToMesh (threeMesh.geometry, materialIndex);
}
if (threeMesh.name !== undefined && threeMesh.name !== null) {
mesh.SetName (threeMesh.name);
@ -235,15 +247,15 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
try {
const dataUrl = GetDataUrl (threeMap.image);
const base64Buffer = OV.Base64DataURIToArrayBuffer (dataUrl);
let texture = new OV.TextureMap ();
const base64Buffer = Base64DataURIToArrayBuffer (dataUrl);
let texture = new TextureMap ();
let textureName = null;
if (objectUrlToFileName.has (threeMap.image.src)) {
textureName = objectUrlToFileName.get (threeMap.image.src);
} else if (threeMap.name !== undefined && threeMap.name !== null) {
textureName = threeMap.name + '.' + OV.GetFileExtensionFromMimeType (base64Buffer.mimeType);
textureName = threeMap.name + '.' + GetFileExtensionFromMimeType (base64Buffer.mimeType);
} else {
textureName = 'Embedded_' + threeMap.id.toString () + '.' + OV.GetFileExtensionFromMimeType (base64Buffer.mimeType);
textureName = 'Embedded_' + threeMap.id.toString () + '.' + GetFileExtensionFromMimeType (base64Buffer.mimeType);
}
texture.name = textureName;
texture.url = dataUrl;
@ -259,14 +271,14 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
}
}
let material = new OV.PhongMaterial ();
let material = new PhongMaterial ();
material.name = threeMaterial.name;
material.color = OV.ConvertThreeColorToColor (threeMaterial.color);
material.color = ConvertThreeColorToColor (threeMaterial.color);
material.opacity = threeMaterial.opacity;
material.transparent = threeMaterial.transparent;
material.alphaTest = threeMaterial.alphaTest;
if (threeMaterial.type === 'MeshPhongMaterial') {
material.specular = OV.ConvertThreeColorToColor (threeMaterial.specular);
material.specular = ConvertThreeColorToColor (threeMaterial.specular);
material.shininess = threeMaterial.shininess / 100.0;
}
material.diffuseMap = CreateTexture (threeMaterial.map, this.objectUrlToFileName);
@ -275,9 +287,9 @@ OV.ImporterThreeBase = class extends OV.ImporterBase
return material;
}
};
}
OV.ImporterThreeFbx = class extends OV.ImporterThreeBase
export class ImporterThreeFbx extends ImporterThreeBase
{
constructor ()
{
@ -291,7 +303,7 @@ OV.ImporterThreeFbx = class extends OV.ImporterThreeBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
GetExternalLibraries ()
@ -313,9 +325,9 @@ OV.ImporterThreeFbx = class extends OV.ImporterThreeBase
{
return loadedObject;
}
};
}
OV.ImporterThreeDae = class extends OV.ImporterThreeBase
export class ImporterThreeDae extends ImporterThreeBase
{
constructor ()
{
@ -329,7 +341,7 @@ OV.ImporterThreeDae = class extends OV.ImporterThreeBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
GetExternalLibraries ()
@ -350,9 +362,9 @@ OV.ImporterThreeDae = class extends OV.ImporterThreeBase
{
return loadedObject.scene;
}
};
}
OV.ImporterThreeWrl = class extends OV.ImporterThreeBase
export class ImporterThreeWrl extends ImporterThreeBase
{
constructor ()
{
@ -366,7 +378,7 @@ OV.ImporterThreeWrl = class extends OV.ImporterThreeBase
GetUpDirection ()
{
return OV.Direction.Y;
return Direction.Y;
}
GetExternalLibraries ()
@ -402,9 +414,9 @@ OV.ImporterThreeWrl = class extends OV.ImporterThreeBase
}
return isVisible;
}
};
}
OV.ImporterThree3mf = class extends OV.ImporterThreeBase
export class ImporterThree3mf extends ImporterThreeBase
{
constructor ()
{
@ -418,7 +430,7 @@ OV.ImporterThree3mf = class extends OV.ImporterThreeBase
GetUpDirection ()
{
return OV.Direction.Z;
return Direction.Z;
}
GetExternalLibraries ()
@ -438,4 +450,4 @@ OV.ImporterThree3mf = class extends OV.ImporterThreeBase
{
return loadedObject;
}
};
}

View File

@ -1,4 +1,6 @@
OV.NameFromLine = function (line, startIndex, commentChar)
import { IsLower } from '../geometry/geometry.js';
export function NameFromLine (line, startIndex, commentChar)
{
let name = line.substr (startIndex);
let commentStart = name.indexOf (commentChar);
@ -6,9 +8,9 @@ OV.NameFromLine = function (line, startIndex, commentChar)
name = name.substr (0, commentStart);
}
return name.trim ();
};
}
OV.ParametersFromLine = function (line, commentChar)
export function ParametersFromLine (line, commentChar)
{
if (commentChar !== null) {
let commentStart = line.indexOf (commentChar);
@ -17,9 +19,9 @@ OV.ParametersFromLine = function (line, commentChar)
}
}
return line.split (/\s+/u);
};
}
OV.ReadLines = function (str, onLine)
export function ReadLines (str, onLine)
{
function LineFound (line, onLine)
{
@ -28,7 +30,7 @@ OV.ReadLines = function (str, onLine)
onLine (trimmed);
}
}
let cursor = 0;
let next = str.indexOf ('\n', cursor);
while (next !== -1) {
@ -37,26 +39,26 @@ OV.ReadLines = function (str, onLine)
next = str.indexOf ('\n', cursor);
}
LineFound (str.substr (cursor), onLine);
};
}
OV.IsPowerOfTwo = function (x)
export function IsPowerOfTwo (x)
{
return (x & (x - 1)) === 0;
};
}
OV.NextPowerOfTwo = function (x)
export function NextPowerOfTwo (x)
{
if (OV.IsPowerOfTwo (x)) {
if (IsPowerOfTwo (x)) {
return x;
}
let npot = Math.pow (2, Math.ceil (Math.log (x) / Math.log (2)));
return parseInt (npot, 10);
};
}
OV.UpdateMaterialTransparency = function (material)
export function UpdateMaterialTransparency (material)
{
material.transparent = false;
if (OV.IsLower (material.opacity, 1.0)) {
if (IsLower (material.opacity, 1.0)) {
material.transparent = true;
}
};
}

View File

@ -1,4 +1,4 @@
OV.BinaryReader = class
export class BinaryReader
{
constructor (arrayBuffer, isLittleEndian)
{
@ -106,4 +106,4 @@ OV.BinaryReader = class
this.position = this.position + 8;
return result;
}
};
}

View File

@ -1,4 +1,4 @@
OV.BinaryWriter = class
export class BinaryWriter
{
constructor (byteLength, isLittleEndian)
{
@ -89,4 +89,4 @@ OV.BinaryWriter = class
this.dataView.setFloat64 (this.position, val, this.isLittleEndian);
this.position = this.position + 8;
}
};
}

View File

@ -1,10 +1,10 @@
OV.ArrayBufferToUtf8String = function (buffer)
export function ArrayBufferToUtf8String (buffer)
{
let decoder = new TextDecoder ('utf-8');
return decoder.decode (buffer);
};
}
OV.ArrayBufferToAsciiString = function (buffer)
export function ArrayBufferToAsciiString (buffer)
{
let text = '';
let bufferView = new Uint8Array (buffer);
@ -12,9 +12,9 @@ OV.ArrayBufferToAsciiString = function (buffer)
text += String.fromCharCode (bufferView[i]);
}
return text;
};
}
OV.AsciiStringToArrayBuffer = function (str)
export function AsciiStringToArrayBuffer (str)
{
let buffer = new ArrayBuffer (str.length);
let bufferView = new Uint8Array (buffer);
@ -22,16 +22,16 @@ OV.AsciiStringToArrayBuffer = function (str)
bufferView[i] = str.charCodeAt (i);
}
return buffer;
};
}
OV.Utf8StringToArrayBuffer = function (str)
export function Utf8StringToArrayBuffer (str)
{
let encoder = new TextEncoder ();
let uint8Array = encoder.encode (str);
return uint8Array.buffer;
};
}
OV.Base64DataURIToArrayBuffer = function (uri)
export function Base64DataURIToArrayBuffer (uri)
{
let dataPrefix = 'data:';
if (!uri.startsWith (dataPrefix)) {
@ -60,9 +60,9 @@ OV.Base64DataURIToArrayBuffer = function (uri)
mimeType : mimeType,
buffer : buffer
};
};
}
OV.GetFileExtensionFromMimeType = function (mimeType)
export function GetFileExtensionFromMimeType (mimeType)
{
if (mimeType === undefined || mimeType === null) {
return '';
@ -72,23 +72,23 @@ OV.GetFileExtensionFromMimeType = function (mimeType)
return '';
}
return mimeParts[mimeParts.length - 1];
};
}
OV.CreateObjectUrl = function (content)
export function CreateObjectUrl (content)
{
let blob = new Blob ([content]);
let url = URL.createObjectURL (blob);
return url;
};
}
OV.CreateObjectUrlWithMimeType = function (content, mimeType)
export function CreateObjectUrlWithMimeType (content, mimeType)
{
let blob = new Blob ([content], { type : mimeType });
let url = URL.createObjectURL (blob);
return url;
};
}
OV.RevokeObjectUrl = function (url)
export function RevokeObjectUrl (url)
{
URL.revokeObjectURL (url);
};
}

View File

@ -1,24 +1,29 @@
OV.ExternalLibLocation = null;
OV.LoadedExternalLibs = new Set ();
let externalLibLocation = null;
let loadedExternalLibs = new Set ();
OV.LoadExternalLibrary = function (libName)
export function SetExternalLibLocation (newExternalLibLocation)
{
externalLibLocation = newExternalLibLocation;
}
export function LoadExternalLibrary (libName)
{
return new Promise ((resolve, reject) => {
if (OV.ExternalLibLocation === null) {
if (externalLibLocation === null) {
reject ();
return;
}
if (OV.LoadedExternalLibs.has (libName)) {
if (loadedExternalLibs.has (libName)) {
resolve ();
return;
}
let scriptElement = document.createElement ('script');
scriptElement.type = 'text/javascript';
scriptElement.src = OV.ExternalLibLocation + '/' + libName;
scriptElement.src = externalLibLocation + '/' + libName;
scriptElement.onload = () => {
OV.LoadedExternalLibs.add (libName);
loadedExternalLibs.add (libName);
resolve ();
};
scriptElement.onerror = () => {
@ -26,4 +31,4 @@ OV.LoadExternalLibrary = function (libName)
};
document.head.appendChild (scriptElement);
});
};
}

View File

@ -1,17 +1,17 @@
OV.FileSource =
export const FileSource =
{
Url : 1,
File : 2,
Decompressed : 3
};
OV.FileFormat =
export const FileFormat =
{
Text : 1,
Binary : 2
};
OV.GetFileName = function (filePath)
export function GetFileName (filePath)
{
let firstSeparator = filePath.lastIndexOf ('/');
if (firstSeparator === -1) {
@ -26,27 +26,27 @@ OV.GetFileName = function (filePath)
fileName = fileName.substr (0, firstParamIndex);
}
return decodeURI (fileName);
};
}
OV.GetFileExtension = function (filePath)
export function GetFileExtension (filePath)
{
let fileName = OV.GetFileName (filePath);
let fileName = GetFileName (filePath);
let firstPoint = fileName.lastIndexOf ('.');
if (firstPoint === -1) {
return '';
}
let extension = fileName.substr (firstPoint + 1);
return extension.toLowerCase ();
};
}
OV.RequestUrl = function (url, format)
export function RequestUrl (url, format)
{
return new Promise ((resolve, reject) => {
let request = new XMLHttpRequest ();
request.open ('GET', url, true);
if (format === OV.FileFormat.Text) {
if (format === FileFormat.Text) {
request.responseType = 'text';
} else if (format === OV.FileFormat.Binary) {
} else if (format === FileFormat.Binary) {
request.responseType = 'arraybuffer';
} else {
reject ();
@ -67,9 +67,9 @@ OV.RequestUrl = function (url, format)
request.send (null);
});
};
}
OV.ReadFile = function (file, format)
export function ReadFile (file, format)
{
return new Promise ((resolve, reject) => {
let reader = new FileReader ();
@ -84,17 +84,17 @@ OV.ReadFile = function (file, format)
reject ();
};
if (format === OV.FileFormat.Text) {
if (format === FileFormat.Text) {
reader.readAsText (file);
} else if (format === OV.FileFormat.Binary) {
} else if (format === FileFormat.Binary) {
reader.readAsArrayBuffer (file);
} else {
reject ();
}
});
};
}
OV.TransformFileHostUrls = function (urls)
export function TransformFileHostUrls (urls)
{
for (let i = 0; i < urls.length; i++) {
let url = urls[i];
@ -115,4 +115,4 @@ OV.TransformFileHostUrls = function (urls)
urls[i] = url;
}
}
};
}

View File

@ -1,4 +1,4 @@
OV.TextWriter = class
export class TextWriter
{
constructor ()
{
@ -38,4 +38,4 @@ OV.TextWriter = class
{
this.text += str;
}
};
}

327
source/engine/main.js Normal file
View File

@ -0,0 +1,327 @@
import { IsDefined, ValueOrDefault, CopyObjectAttributes } from './core/core.js';
import { TaskRunner, RunTaskAsync, RunTasks, RunTasksBatch, WaitWhile } from './core/taskrunner.js';
import { Exporter } from './export/exporter.js';
import { Exporter3dm } from './export/exporter3dm.js';
import { ExportedFile, ExporterBase } from './export/exporterbase.js';
import { ExporterGltf } from './export/exportergltf.js';
import { ExporterSettings, ExporterModel } from './export/exportermodel.js';
import { ExporterObj } from './export/exporterobj.js';
import { ExporterOff } from './export/exporteroff.js';
import { ExporterPly } from './export/exporterply.js';
import { ExporterStl } from './export/exporterstl.js';
import { Box3D, BoundingBoxCalculator3D } from './geometry/box3d.js';
import { Coord2D, CoordIsEqual2D, AddCoord2D, SubCoord2D, CoordDistance2D } from './geometry/coord2d.js';
import { Coord3D, CoordIsEqual3D, AddCoord3D, SubCoord3D, CoordDistance3D, DotVector3D, VectorAngle3D, CrossVector3D, VectorLength3D, ArrayToCoord3D } from './geometry/coord3d.js';
import { Coord4D } from './geometry/coord4d.js';
import { IsZero, IsLower, IsGreater, IsLowerOrEqual, IsGreaterOrEqual, IsEqual, IsEqualEps, IsPositive, IsNegative, Eps, BigEps, RadDeg, DegRad, Direction } from './geometry/geometry.js';
import { Matrix, MatrixIsEqual } from './geometry/matrix.js';
import { OctreeNode, Octree } from './geometry/octree.js';
import { Quaternion, ArrayToQuaternion, QuaternionFromAxisAngle } from './geometry/quaternion.js';
import { Transformation, TransformationIsEqual } from './geometry/transformation.js';
import { BezierTweenFunction, LinearTweenFunction, ParabolicTweenFunction, TweenCoord3D } from './geometry/tween.js';
import { File, FileList } from './import/filelist.js';
import { ImportSettings, ImportError, ImportResult, ImporterFileAccessor, Importer, ImportErrorCode } from './import/importer.js';
import { Importer3dm } from './import/importer3dm.js';
import { Importer3dsNode, Importer3dsNodeList, Importer3ds, CHUNK3DS } from './import/importer3ds.js';
import { ImporterBase } from './import/importerbase.js';
import { GltfBufferReader, GltfExtensions, ImporterGltf, GetGltfColor, GetGltfVertexColor, GltfComponentType, GltfDataType, GltfRenderMode, GltfConstants } from './import/importergltf.js';
import { ImporterIfc } from './import/importerifc.js';
import { ImporterO3dv } from './import/importero3dv.js';
import { ObjMeshConverter, ImporterObj } from './import/importerobj.js';
import { ImporterOff } from './import/importeroff.js';
import { PlyHeader, PlyMaterialHandler, ImporterPly, PlyHeaderCheckResult } from './import/importerply.js';
import { ImporterStl } from './import/importerstl.js';
import { ImporterThreeSvg } from './import/importersvg.js';
import { ImporterThreeBase, ImporterThreeFbx, ImporterThreeDae, ImporterThreeWrl, ImporterThree3mf } from './import/importerthree.js';
import { NameFromLine, ParametersFromLine, ReadLines, IsPowerOfTwo, NextPowerOfTwo, UpdateMaterialTransparency } from './import/importerutils.js';
import { BinaryReader } from './io/binaryreader.js';
import { BinaryWriter } from './io/binarywriter.js';
import { ArrayBufferToUtf8String, ArrayBufferToAsciiString, AsciiStringToArrayBuffer, Utf8StringToArrayBuffer, Base64DataURIToArrayBuffer, GetFileExtensionFromMimeType, CreateObjectUrl, CreateObjectUrlWithMimeType, RevokeObjectUrl } from './io/bufferutils.js';
import { SetExternalLibLocation, LoadExternalLibrary } from './io/externallibs.js';
import { GetFileName, GetFileExtension, RequestUrl, ReadFile, TransformFileHostUrls, FileSource, FileFormat } from './io/fileutils.js';
import { TextWriter } from './io/textwriter.js';
import { Color, ColorComponentFromFloat, ColorFromFloatComponents, SRGBToLinear, LinearToSRGB, IntegerToHexString, ColorToHexString, HexStringToColor, ArrayToColor, ColorIsEqual } from './model/color.js';
import { GeneratorParams, Generator, GeneratorHelper, GenerateCuboid, GenerateCylinder, GenerateSphere, GeneratePlatonicSolid } from './model/generator.js';
import { TextureMap, MaterialBase, FaceMaterial, PhongMaterial, PhysicalMaterial, TextureMapIsEqual, TextureIsEqual, MaterialType } from './model/material.js';
import { Mesh } from './model/mesh.js';
import { MeshPrimitiveBuffer, MeshBuffer, ConvertMeshToMeshBuffer } from './model/meshbuffer.js';
import { MeshInstanceId, MeshInstance } from './model/meshinstance.js';
import { GetMeshType, CalculateTriangleNormal, TransformMesh, FlipMeshTrianglesOrientation, MeshType } from './model/meshutils.js';
import { Model } from './model/model.js';
import { ModelFinalizer, FinalizeModel, CheckModel } from './model/modelfinalization.js';
import { IsModelEmpty, GetBoundingBox, GetTopology, IsSolid, HasDefaultMaterial, ReplaceDefaultMaterialColor } from './model/modelutils.js';
import { NodeIdGenerator, Node, NodeType } from './model/node.js';
import { Object3D, ModelObject3D } from './model/object.js';
import { Property, PropertyGroup, PropertyType } from './model/property.js';
import { GetTriangleArea, GetTetrahedronSignedVolume, CalculateVolume, CalculateSurfaceArea } from './model/quantities.js';
import { TopologyVertex, TopologyEdge, TopologyTriangleEdge, TopologyTriangle, Topology } from './model/topology.js';
import { Triangle } from './model/triangle.js';
import { ParameterListBuilder, ParameterListParser, CreateUrlBuilder, CreateUrlParser, CreateModelUrlParameters, ParameterConverter } from './parameters/parameterlist.js';
import { ModelToThreeConversionParams, ModelToThreeConversionOutput, ThreeConversionStateHandler, ThreeNodeTree, ConvertModelToThreeObject } from './threejs/threeconverter.js';
import { ThreeModelLoader } from './threejs/threemodelloader.js';
import { HasHighpDriverIssue, GetShadingType, ConvertThreeColorToColor, ConvertColorToThreeColor, ConvertThreeGeometryToMesh, ShadingType } from './threejs/threeutils.js';
import { GetIntegerFromStyle, GetDomElementExternalWidth, GetDomElementExternalHeight, GetDomElementInnerDimensions, GetDomElementClientCoordinates, CreateDomElement, AddDomElement, AddDiv, ClearDomElement, InsertDomElementBefore, InsertDomElementAfter, ShowDomElement, IsDomElementVisible, SetDomElementWidth, SetDomElementHeight, GetDomElementOuterWidth, GetDomElementOuterHeight, SetDomElementOuterWidth, SetDomElementOuterHeight, AddCheckbox, AddRangeSlider, AddSelect, AddToggle, CreateDiv } from './viewer/domutils.js';
import { EmbeddedViewer, Init3DViewerElement, Init3DViewerElements } from './viewer/embeddedviewer.js';
import { MeasureTool } from './viewer/measuretool.js';
import { Camera, MouseInteraction, TouchInteraction, ClickDetector, Navigation, CameraIsEqual3D, NavigationType } from './viewer/navigation.js';
import { UpVector, ShadingModel, Viewer, GetDefaultCamera, TraverseThreeObject, GetShadingTypeOfObject } from './viewer/viewer.js';
import { ViewerGeometry, ViewerExtraGeometry, SetThreeMeshPolygonOffset } from './viewer/viewergeometry.js';
export {
IsDefined,
ValueOrDefault,
CopyObjectAttributes,
TaskRunner,
RunTaskAsync,
RunTasks,
RunTasksBatch,
WaitWhile,
Exporter,
Exporter3dm,
ExportedFile,
ExporterBase,
ExporterGltf,
ExporterSettings,
ExporterModel,
ExporterObj,
ExporterOff,
ExporterPly,
ExporterStl,
Box3D,
BoundingBoxCalculator3D,
Coord2D,
CoordIsEqual2D,
AddCoord2D,
SubCoord2D,
CoordDistance2D,
Coord3D,
CoordIsEqual3D,
AddCoord3D,
SubCoord3D,
CoordDistance3D,
DotVector3D,
VectorAngle3D,
CrossVector3D,
VectorLength3D,
ArrayToCoord3D,
Coord4D,
IsZero,
IsLower,
IsGreater,
IsLowerOrEqual,
IsGreaterOrEqual,
IsEqual,
IsEqualEps,
IsPositive,
IsNegative,
Eps,
BigEps,
RadDeg,
DegRad,
Direction,
Matrix,
MatrixIsEqual,
OctreeNode,
Octree,
Quaternion,
ArrayToQuaternion,
QuaternionFromAxisAngle,
Transformation,
TransformationIsEqual,
BezierTweenFunction,
LinearTweenFunction,
ParabolicTweenFunction,
TweenCoord3D,
File,
FileList,
ImportSettings,
ImportError,
ImportResult,
ImporterFileAccessor,
Importer,
ImportErrorCode,
Importer3dm,
Importer3dsNode,
Importer3dsNodeList,
Importer3ds,
CHUNK3DS,
ImporterBase,
GltfBufferReader,
GltfExtensions,
ImporterGltf,
GetGltfColor,
GetGltfVertexColor,
GltfComponentType,
GltfDataType,
GltfRenderMode,
GltfConstants,
ImporterIfc,
ImporterO3dv,
ObjMeshConverter,
ImporterObj,
ImporterOff,
PlyHeader,
PlyMaterialHandler,
ImporterPly,
PlyHeaderCheckResult,
ImporterStl,
ImporterThreeSvg,
ImporterThreeBase,
ImporterThreeFbx,
ImporterThreeDae,
ImporterThreeWrl,
ImporterThree3mf,
NameFromLine,
ParametersFromLine,
ReadLines,
IsPowerOfTwo,
NextPowerOfTwo,
UpdateMaterialTransparency,
BinaryReader,
BinaryWriter,
ArrayBufferToUtf8String,
ArrayBufferToAsciiString,
AsciiStringToArrayBuffer,
Utf8StringToArrayBuffer,
Base64DataURIToArrayBuffer,
GetFileExtensionFromMimeType,
CreateObjectUrl,
CreateObjectUrlWithMimeType,
RevokeObjectUrl,
SetExternalLibLocation,
LoadExternalLibrary,
GetFileName,
GetFileExtension,
RequestUrl,
ReadFile,
TransformFileHostUrls,
FileSource,
FileFormat,
TextWriter,
Color,
ColorComponentFromFloat,
ColorFromFloatComponents,
SRGBToLinear,
LinearToSRGB,
IntegerToHexString,
ColorToHexString,
HexStringToColor,
ArrayToColor,
ColorIsEqual,
GeneratorParams,
Generator,
GeneratorHelper,
GenerateCuboid,
GenerateCylinder,
GenerateSphere,
GeneratePlatonicSolid,
TextureMap,
MaterialBase,
FaceMaterial,
PhongMaterial,
PhysicalMaterial,
TextureMapIsEqual,
TextureIsEqual,
MaterialType,
Mesh,
MeshPrimitiveBuffer,
MeshBuffer,
ConvertMeshToMeshBuffer,
MeshInstanceId,
MeshInstance,
GetMeshType,
CalculateTriangleNormal,
TransformMesh,
FlipMeshTrianglesOrientation,
MeshType,
Model,
ModelFinalizer,
FinalizeModel,
CheckModel,
IsModelEmpty,
GetBoundingBox,
GetTopology,
IsSolid,
HasDefaultMaterial,
ReplaceDefaultMaterialColor,
NodeIdGenerator,
Node,
NodeType,
Object3D,
ModelObject3D,
Property,
PropertyGroup,
PropertyType,
GetTriangleArea,
GetTetrahedronSignedVolume,
CalculateVolume,
CalculateSurfaceArea,
TopologyVertex,
TopologyEdge,
TopologyTriangleEdge,
TopologyTriangle,
Topology,
Triangle,
ParameterListBuilder,
ParameterListParser,
CreateUrlBuilder,
CreateUrlParser,
CreateModelUrlParameters,
ParameterConverter,
ModelToThreeConversionParams,
ModelToThreeConversionOutput,
ThreeConversionStateHandler,
ThreeNodeTree,
ConvertModelToThreeObject,
ThreeModelLoader,
HasHighpDriverIssue,
GetShadingType,
ConvertThreeColorToColor,
ConvertColorToThreeColor,
ConvertThreeGeometryToMesh,
ShadingType,
GetIntegerFromStyle,
GetDomElementExternalWidth,
GetDomElementExternalHeight,
GetDomElementInnerDimensions,
GetDomElementClientCoordinates,
CreateDomElement,
AddDomElement,
AddDiv,
ClearDomElement,
InsertDomElementBefore,
InsertDomElementAfter,
ShowDomElement,
IsDomElementVisible,
SetDomElementWidth,
SetDomElementHeight,
GetDomElementOuterWidth,
GetDomElementOuterHeight,
SetDomElementOuterWidth,
SetDomElementOuterHeight,
AddCheckbox,
AddRangeSlider,
AddSelect,
AddToggle,
CreateDiv,
EmbeddedViewer,
Init3DViewerElement,
Init3DViewerElements,
MeasureTool,
Camera,
MouseInteraction,
TouchInteraction,
ClickDetector,
Navigation,
CameraIsEqual3D,
NavigationType,
UpVector,
ShadingModel,
Viewer,
GetDefaultCamera,
TraverseThreeObject,
GetShadingTypeOfObject,
ViewerGeometry,
ViewerExtraGeometry,
SetThreeMeshPolygonOffset
};

View File

@ -1,4 +1,4 @@
OV.Color = class
export class Color
{
constructor (r, g, b)
{
@ -16,60 +16,60 @@ OV.Color = class
Clone ()
{
return new OV.Color (this.r, this.g, this.b);
return new Color (this.r, this.g, this.b);
}
};
}
OV.ColorComponentFromFloat = function (component)
export function ColorComponentFromFloat (component)
{
return parseInt (Math.round (component * 255.0), 10);
};
}
OV.ColorFromFloatComponents = function (r, g, b)
export function ColorFromFloatComponents (r, g, b)
{
return new OV.Color (
OV.ColorComponentFromFloat (r),
OV.ColorComponentFromFloat (g),
OV.ColorComponentFromFloat (b)
return new Color (
ColorComponentFromFloat (r),
ColorComponentFromFloat (g),
ColorComponentFromFloat (b)
);
};
}
OV.SRGBToLinear = function (component)
export function SRGBToLinear (component)
{
if (component < 0.04045) {
return component * 0.0773993808;
} else {
return Math.pow (component * 0.9478672986 + 0.0521327014, 2.4);
}
};
}
OV.LinearToSRGB = function (component)
export function LinearToSRGB (component)
{
if (component < 0.0031308) {
return component * 12.92;
} else {
return 1.055 * (Math.pow (component, 0.41666)) - 0.055;
}
};
}
OV.IntegerToHexString = function (intVal)
export function IntegerToHexString (intVal)
{
let result = parseInt (intVal, 10).toString (16);
while (result.length < 2) {
result = '0' + result;
}
return result;
};
}
OV.ColorToHexString = function (color)
export function ColorToHexString (color)
{
let r = OV.IntegerToHexString (color.r);
let g = OV.IntegerToHexString (color.g);
let b = OV.IntegerToHexString (color.b);
let r = IntegerToHexString (color.r);
let g = IntegerToHexString (color.g);
let b = IntegerToHexString (color.b);
return r + g + b;
};
}
OV.HexStringToColor = function (hexString)
export function HexStringToColor (hexString)
{
if (hexString.length !== 6) {
return null;
@ -78,15 +78,15 @@ OV.HexStringToColor = function (hexString)
let r = parseInt (hexString.substr (0, 2), 16);
let g = parseInt (hexString.substr (2, 2), 16);
let b = parseInt (hexString.substr (4, 2), 16);
return new OV.Color (r, g, b);
};
return new Color (r, g, b);
}
OV.ArrayToColor = function (arr)
export function ArrayToColor (arr)
{
return new OV.Color (arr[0], arr[1], arr[2]);
};
return new Color (arr[0], arr[1], arr[2]);
}
OV.ColorIsEqual = function (a, b)
export function ColorIsEqual (a, b)
{
return a.r === b.r && a.g === b.g && a.b === b.b;
};
}

View File

@ -1,4 +1,10 @@
OV.GeneratorParams = class
import { Coord2D } from '../geometry/coord2d.js';
import { Coord3D } from '../geometry/coord3d.js';
import { IsZero } from '../geometry/geometry.js';
import { Mesh } from './mesh.js';
import { Triangle } from './triangle.js';
export class GeneratorParams
{
constructor ()
{
@ -17,14 +23,14 @@ OV.GeneratorParams = class
this.material = material;
return this;
}
};
}
OV.Generator = class
export class Generator
{
constructor (params)
{
this.params = params || new OV.GeneratorParams ();
this.mesh = new OV.Mesh ();
this.params = params || new GeneratorParams ();
this.mesh = new Mesh ();
if (this.params.name !== null) {
this.mesh.SetName (this.params.name);
}
@ -38,7 +44,7 @@ OV.Generator = class
AddVertex (x, y, z)
{
let coord = new OV.Coord3D (x, y, z);
let coord = new Coord3D (x, y, z);
return this.mesh.AddVertex (coord);
}
@ -64,7 +70,7 @@ OV.Generator = class
AddTriangle (v0, v1, v2)
{
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
if (this.params.material !== null) {
triangle.mat = this.params.material;
}
@ -100,9 +106,9 @@ OV.Generator = class
);
}
}
};
}
OV.GeneratorHelper = class
export class GeneratorHelper
{
constructor (generator)
{
@ -156,27 +162,27 @@ OV.GeneratorHelper = class
);
}
}
};
}
OV.GenerateCuboid = function (genParams, xSize, ySize, zSize)
export function GenerateCuboid (genParams, xSize, ySize, zSize)
{
let generator = new OV.Generator (genParams);
let generator = new Generator (genParams);
let vertices = [
new OV.Coord2D (0.0, 0.0),
new OV.Coord2D (xSize, 0.0),
new OV.Coord2D (xSize, ySize),
new OV.Coord2D (0.0, ySize),
new Coord2D (0.0, 0.0),
new Coord2D (xSize, 0.0),
new Coord2D (xSize, ySize),
new Coord2D (0.0, ySize),
];
let helper = new OV.GeneratorHelper (generator);
let helper = new GeneratorHelper (generator);
helper.GenerateExtrude (vertices, zSize, null);
return generator.GetMesh ();
};
}
OV.GenerateCylinder = function (genParams, radius, height, segments, smooth)
export function GenerateCylinder (genParams, radius, height, segments, smooth)
{
function GetCylindricalCoord (radius, angle)
{
return new OV.Coord2D (
return new Coord2D (
radius * Math.cos (angle),
radius * Math.sin (angle)
);
@ -186,23 +192,23 @@ OV.GenerateCylinder = function (genParams, radius, height, segments, smooth)
return null;
}
let generator = new OV.Generator (genParams);
let generator = new Generator (genParams);
let baseVertices = [];
const step = 2.0 * Math.PI / segments;
for (let i = 0; i < segments; i++) {
let cylindrical = GetCylindricalCoord (radius, i * step);
baseVertices.push (cylindrical);
}
let helper = new OV.GeneratorHelper (generator);
let helper = new GeneratorHelper (generator);
helper.GenerateExtrude (baseVertices, height, smooth ? 1 : null);
return generator.GetMesh ();
};
}
OV.GenerateSphere = function (genParams, radius, segments, smooth)
export function GenerateSphere (genParams, radius, segments, smooth)
{
function GetSphericalCoord (radius, theta, phi)
{
return new OV.Coord3D (
return new Coord3D (
radius * Math.sin (theta) * Math.cos (phi),
radius * Math.sin (theta) * Math.sin (phi),
radius * Math.cos (theta)
@ -213,8 +219,8 @@ OV.GenerateSphere = function (genParams, radius, segments, smooth)
return null;
}
let generator = new OV.Generator (genParams);
let helper = new OV.GeneratorHelper (generator);
let generator = new Generator (genParams);
let helper = new GeneratorHelper (generator);
generator.SetCurve (smooth ? 1 : null);
@ -244,22 +250,22 @@ OV.GenerateSphere = function (genParams, radius, segments, smooth)
generator.ResetCurve ();
return generator.GetMesh ();
};
}
OV.GeneratePlatonicSolid = function (genParams, type, radius)
export function GeneratePlatonicSolid (genParams, type, radius)
{
function AddVertex (generator, radius, x, y, z)
{
let vertex = new OV.Coord3D (x, y, z);
let vertex = new Coord3D (x, y, z);
vertex.MultiplyScalar (radius / vertex.Length ());
generator.AddVertex (vertex.x, vertex.y, vertex.z);
}
if (OV.IsZero (radius)) {
if (IsZero (radius)) {
return null;
}
let generator = new OV.Generator (genParams);
let generator = new Generator (genParams);
if (type === 'tetrahedron') {
let a = 1.0;
AddVertex (generator, radius, +a, +a, +a);
@ -378,4 +384,4 @@ OV.GeneratePlatonicSolid = function (genParams, type, radius)
generator.AddTriangle (7, 10, 11);
}
return generator.GetMesh ();
};
}

View File

@ -1,12 +1,16 @@
OV.TextureMap = class
import { Coord2D, CoordIsEqual2D } from '../geometry/coord2d.js';
import { IsEqual } from '../geometry/geometry.js';
import { Color, ColorIsEqual } from './color.js';
export class TextureMap
{
constructor ()
{
this.name = null;
this.url = null;
this.buffer = null;
this.offset = new OV.Coord2D (0.0, 0.0);
this.scale = new OV.Coord2D (1.0, 1.0);
this.offset = new Coord2D (0.0, 0.0);
this.scale = new Coord2D (1.0, 1.0);
this.rotation = 0.0; // radians
}
@ -17,13 +21,13 @@ OV.TextureMap = class
HasTransformation ()
{
if (!OV.CoordIsEqual2D (this.offset, new OV.Coord2D (0.0, 0.0))) {
if (!CoordIsEqual2D (this.offset, new Coord2D (0.0, 0.0))) {
return true;
}
if (!OV.CoordIsEqual2D (this.scale, new OV.Coord2D (1.0, 1.0))) {
if (!CoordIsEqual2D (this.scale, new Coord2D (1.0, 1.0))) {
return true;
}
if (!OV.IsEqual (this.rotation, 0.0)) {
if (!IsEqual (this.rotation, 0.0)) {
return true;
}
return false;
@ -40,20 +44,20 @@ OV.TextureMap = class
if (this.url !== rhs.url) {
return false;
}
if (!OV.CoordIsEqual2D (this.offset, rhs.offset)) {
if (!CoordIsEqual2D (this.offset, rhs.offset)) {
return false;
}
if (!OV.CoordIsEqual2D (this.scale, rhs.scale)) {
if (!CoordIsEqual2D (this.scale, rhs.scale)) {
return false;
}
if (!OV.IsEqual (this.rotation, rhs.rotation)) {
if (!IsEqual (this.rotation, rhs.rotation)) {
return false;
}
return true;
}
};
}
OV.TextureMapIsEqual = function (aTex, bTex)
export function TextureMapIsEqual (aTex, bTex)
{
if (aTex === null && bTex === null) {
return true;
@ -61,15 +65,15 @@ OV.TextureMapIsEqual = function (aTex, bTex)
return false;
}
return aTex.IsEqual (bTex);
};
}
OV.MaterialType =
export const MaterialType =
{
Phong : 1,
Physical : 2
};
OV.MaterialBase = class
export class MaterialBase
{
constructor (type)
{
@ -77,7 +81,7 @@ OV.MaterialBase = class
this.isDefault = false;
this.name = '';
this.color = new OV.Color (0, 0, 0);
this.color = new Color (0, 0, 0);
this.vertexColors = false;
}
@ -93,7 +97,7 @@ OV.MaterialBase = class
if (this.name !== rhs.name) {
return false;
}
if (!OV.ColorIsEqual (this.color, rhs.color)) {
if (!ColorIsEqual (this.color, rhs.color)) {
return false;
}
if (this.vertexColors !== rhs.vertexColors) {
@ -101,15 +105,15 @@ OV.MaterialBase = class
}
return true;
}
};
}
OV.FaceMaterial = class extends OV.MaterialBase
export class FaceMaterial extends MaterialBase
{
constructor (type)
{
super (type);
this.emissive = new OV.Color (0, 0, 0);
this.emissive = new Color (0, 0, 0);
this.opacity = 1.0; // 0.0 .. 1.0
this.transparent = false;
@ -128,28 +132,28 @@ OV.FaceMaterial = class extends OV.MaterialBase
if (!super.IsEqual (rhs)) {
return false;
}
if (!OV.ColorIsEqual (this.emissive, rhs.emissive)) {
if (!ColorIsEqual (this.emissive, rhs.emissive)) {
return false;
}
if (!OV.IsEqual (this.opacity, rhs.opacity)) {
if (!IsEqual (this.opacity, rhs.opacity)) {
return false;
}
if (this.transparent !== rhs.transparent) {
return false;
}
if (!OV.TextureMapIsEqual (this.diffuseMap, rhs.diffuseMap)) {
if (!TextureMapIsEqual (this.diffuseMap, rhs.diffuseMap)) {
return false;
}
if (!OV.TextureMapIsEqual (this.bumpMap, rhs.bumpMap)) {
if (!TextureMapIsEqual (this.bumpMap, rhs.bumpMap)) {
return false;
}
if (!OV.TextureMapIsEqual (this.normalMap, rhs.normalMap)) {
if (!TextureMapIsEqual (this.normalMap, rhs.normalMap)) {
return false;
}
if (!OV.TextureMapIsEqual (this.emissiveMap, rhs.emissiveMap)) {
if (!TextureMapIsEqual (this.emissiveMap, rhs.emissiveMap)) {
return false;
}
if (!OV.IsEqual (this.alphaTest, rhs.alphaTest)) {
if (!IsEqual (this.alphaTest, rhs.alphaTest)) {
return false;
}
if (this.multiplyDiffuseMap !== rhs.multiplyDiffuseMap) {
@ -173,16 +177,16 @@ OV.FaceMaterial = class extends OV.MaterialBase
enumerator (this.emissiveMap);
}
}
};
}
OV.PhongMaterial = class extends OV.FaceMaterial
export class PhongMaterial extends FaceMaterial
{
constructor ()
{
super (OV.MaterialType.Phong);
super (MaterialType.Phong);
this.ambient = new OV.Color (0, 0, 0);
this.specular = new OV.Color (0, 0, 0);
this.ambient = new Color (0, 0, 0);
this.specular = new Color (0, 0, 0);
this.shininess = 0.0; // 0.0 .. 1.0
this.specularMap = null;
}
@ -192,16 +196,16 @@ OV.PhongMaterial = class extends OV.FaceMaterial
if (!super.IsEqual (rhs)) {
return false;
}
if (!OV.ColorIsEqual (this.ambient, rhs.ambient)) {
if (!ColorIsEqual (this.ambient, rhs.ambient)) {
return false;
}
if (!OV.ColorIsEqual (this.specular, rhs.specular)) {
if (!ColorIsEqual (this.specular, rhs.specular)) {
return false;
}
if (!OV.IsEqual (this.shininess, rhs.shininess)) {
if (!IsEqual (this.shininess, rhs.shininess)) {
return false;
}
if (!OV.TextureMapIsEqual (this.specularMap, rhs.specularMap)) {
if (!TextureMapIsEqual (this.specularMap, rhs.specularMap)) {
return false;
}
return true;
@ -214,13 +218,13 @@ OV.PhongMaterial = class extends OV.FaceMaterial
enumerator (this.specularMap);
}
}
};
}
OV.PhysicalMaterial = class extends OV.FaceMaterial
export class PhysicalMaterial extends FaceMaterial
{
constructor ()
{
super (OV.MaterialType.Physical);
super (MaterialType.Physical);
this.metalness = 0.0; // 0.0 .. 1.0
this.roughness = 1.0; // 0.0 .. 1.0
@ -232,13 +236,13 @@ OV.PhysicalMaterial = class extends OV.FaceMaterial
if (!super.IsEqual (rhs)) {
return false;
}
if (!OV.IsEqual (this.metalness, rhs.metalness)) {
if (!IsEqual (this.metalness, rhs.metalness)) {
return false;
}
if (!OV.IsEqual (this.roughness, rhs.roughness)) {
if (!IsEqual (this.roughness, rhs.roughness)) {
return false;
}
if (!OV.TextureMapIsEqual (this.metalnessMap, rhs.metalnessMap)) {
if (!TextureMapIsEqual (this.metalnessMap, rhs.metalnessMap)) {
return false;
}
return true;
@ -251,9 +255,9 @@ OV.PhysicalMaterial = class extends OV.FaceMaterial
enumerator (this.metalnessMap);
}
}
};
}
OV.TextureIsEqual = function (a, b)
export function TextureIsEqual (a, b)
{
if (a.name !== b.name) {
return false;
@ -264,14 +268,14 @@ OV.TextureIsEqual = function (a, b)
if (a.url !== b.url) {
return false;
}
if (!OV.CoordIsEqual2D (a.offset, b.offset)) {
if (!CoordIsEqual2D (a.offset, b.offset)) {
return false;
}
if (!OV.CoordIsEqual2D (a.scale, b.scale)) {
if (!CoordIsEqual2D (a.scale, b.scale)) {
return false;
}
if (!OV.IsEqual (a.rotation, b.rotation)) {
if (!IsEqual (a.rotation, b.rotation)) {
return false;
}
return true;
};
}

View File

@ -1,4 +1,6 @@
OV.Mesh = class extends OV.ModelObject3D
import { ModelObject3D } from './object.js';
export class Mesh extends ModelObject3D
{
constructor ()
{
@ -136,7 +138,7 @@ OV.Mesh = class extends OV.ModelObject3D
Clone ()
{
let cloned = new OV.Mesh ();
let cloned = new Mesh ();
cloned.SetName (this.GetName ());
@ -167,4 +169,4 @@ OV.Mesh = class extends OV.ModelObject3D
return cloned;
}
};
}

View File

@ -1,4 +1,8 @@
OV.MeshPrimitiveBuffer = class
import { Coord2D, CoordIsEqual2D } from '../geometry/coord2d.js';
import { CoordIsEqual3D } from '../geometry/coord3d.js';
import { Color, ColorIsEqual } from './color.js';
export class MeshPrimitiveBuffer
{
constructor ()
{
@ -32,9 +36,9 @@ OV.MeshPrimitiveBuffer = class
let numberCount = this.vertices.length + this.colors.length + this.normals.length + this.uvs.length;
return indexCount * indexTypeSize + numberCount * numberTypeSize;
}
};
}
OV.MeshBuffer = class
export class MeshBuffer
{
constructor ()
{
@ -60,9 +64,9 @@ OV.MeshBuffer = class
}
return byteLength;
}
};
}
OV.ConvertMeshToMeshBuffer = function (mesh)
export function ConvertMeshToMeshBuffer (mesh)
{
function AddVertexToPrimitiveBuffer (mesh, indices, primitiveBuffer, meshVertexToPrimitiveVertices)
{
@ -71,7 +75,7 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
if (colorIndex !== null) {
return mesh.GetVertexColor (colorIndex);
} else if (forceColors) {
return new OV.Color (0, 0, 0);
return new Color (0, 0, 0);
} else {
return null;
}
@ -82,7 +86,7 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
if (uvIndex !== null) {
return mesh.GetTextureUV (uvIndex);
} else if (forceUVs) {
return new OV.Coord2D (0.0, 0.0);
return new Coord2D (0.0, 0.0);
} else {
return null;
}
@ -128,13 +132,13 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
return true;
}
let color = GetColorOrDefault (mesh, colorIndex, true);
return OV.ColorIsEqual (existingColor, color);
return ColorIsEqual (existingColor, color);
}
function IsEqualNormal (mesh, normalIndex, existingNormal)
{
let normal = mesh.GetNormal (normalIndex);
return OV.CoordIsEqual3D (existingNormal, normal);
return CoordIsEqual3D (existingNormal, normal);
}
function IsEqualUV (mesh, uvIndex, existingUv)
@ -143,7 +147,7 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
return true;
}
let uv = GetUVOrDefault (mesh, uvIndex, true);
return OV.CoordIsEqual2D (existingUv, uv);
return CoordIsEqual2D (existingUv, uv);
}
for (let i = 0; i < primitiveVertices.length; i++) {
@ -173,7 +177,7 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
}
}
let meshBuffer = new OV.MeshBuffer ();
let meshBuffer = new MeshBuffer ();
let triangleCount = mesh.TriangleCount ();
if (triangleCount === 0) {
@ -196,7 +200,7 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
let triangleIndex = triangleIndices[i];
let triangle = mesh.GetTriangle (triangleIndex);
if (primitiveBuffer === null || primitiveBuffer.material !== triangle.mat) {
primitiveBuffer = new OV.MeshPrimitiveBuffer ();
primitiveBuffer = new MeshPrimitiveBuffer ();
primitiveBuffer.material = triangle.mat;
meshVertexToPrimitiveVertices = new Map ();
meshBuffer.primitives.push (primitiveBuffer);
@ -226,4 +230,4 @@ OV.ConvertMeshToMeshBuffer = function (mesh)
}
return meshBuffer;
};
}

View File

@ -1,4 +1,7 @@
OV.MeshInstanceId = class
import { TransformMesh } from './meshutils.js';
import { ModelObject3D } from './object.js';
export class MeshInstanceId
{
constructor (nodeId, meshIndex)
{
@ -15,9 +18,9 @@ OV.MeshInstanceId = class
{
return this.nodeId.toString () + ':' + this.meshIndex.toString ();
}
};
}
OV.MeshInstance = class extends OV.ModelObject3D
export class MeshInstance extends ModelObject3D
{
constructor (id, node, mesh)
{
@ -119,7 +122,7 @@ OV.MeshInstance = class extends OV.ModelObject3D
{
let transformation = this.node.GetWorldTransformation ();
let transformed = this.mesh.Clone ();
OV.TransformMesh (transformed, transformation);
TransformMesh (transformed, transformation);
return transformed;
}
};
}

View File

@ -1,27 +1,31 @@
OV.MeshType =
import { Coord3D, CrossVector3D, SubCoord3D } from '../geometry/coord3d.js';
import { Matrix } from '../geometry/matrix.js';
import { Transformation } from '../geometry/transformation.js';
export const MeshType =
{
Empty : 0,
TriangleMesh : 1
};
OV.GetMeshType = function (mesh)
export function GetMeshType (mesh)
{
if (mesh.TriangleCount () > 0) {
return OV.MeshType.TriangleMesh;
return MeshType.TriangleMesh;
}
return OV.MeshType.Empty;
};
return MeshType.Empty;
}
OV.CalculateTriangleNormal = function (v0, v1, v2)
export function CalculateTriangleNormal (v0, v1, v2)
{
let v = OV.SubCoord3D (v1, v0);
let w = OV.SubCoord3D (v2, v0);
let normal = OV.CrossVector3D (v, w);
let v = SubCoord3D (v1, v0);
let w = SubCoord3D (v2, v0);
let normal = CrossVector3D (v, w);
normal.Normalize ();
return normal;
};
}
OV.TransformMesh = function (mesh, transformation)
export function TransformMesh (mesh, transformation)
{
if (transformation.IsIdentity ()) {
return;
@ -37,8 +41,8 @@ OV.TransformMesh = function (mesh, transformation)
if (mesh.NormalCount () > 0) {
let trs = transformation.GetMatrix ().DecomposeTRS ();
let normalMatrix = new OV.Matrix ().ComposeTRS (new OV.Coord3D (0.0, 0.0, 0.0), trs.rotation, new OV.Coord3D (1.0, 1.0, 1.0));
let normalTransformation = new OV.Transformation (normalMatrix);
let normalMatrix = new Matrix ().ComposeTRS (new Coord3D (0.0, 0.0, 0.0), trs.rotation, new Coord3D (1.0, 1.0, 1.0));
let normalTransformation = new Transformation (normalMatrix);
for (let i = 0; i < mesh.NormalCount (); i++) {
let normal = mesh.GetNormal (i);
let transformed = normalTransformation.TransformCoord3D (normal);
@ -47,9 +51,9 @@ OV.TransformMesh = function (mesh, transformation)
normal.z = transformed.z;
}
}
};
}
OV.FlipMeshTrianglesOrientation = function (mesh)
export function FlipMeshTrianglesOrientation (mesh)
{
for (let i = 0; i < mesh.TriangleCount (); i++) {
let triangle = mesh.GetTriangle (i);
@ -57,4 +61,4 @@ OV.FlipMeshTrianglesOrientation = function (mesh)
triangle.v1 = triangle.v2;
triangle.v2 = tmp;
}
};
}

View File

@ -1,9 +1,13 @@
OV.Model = class extends OV.ModelObject3D
import { MeshInstance, MeshInstanceId } from './meshinstance.js';
import { Node } from './node.js';
import { ModelObject3D } from './object.js';
export class Model extends ModelObject3D
{
constructor ()
{
super ();
this.root = new OV.Node ();
this.root = new Node ();
this.materials = [];
this.meshes = [];
}
@ -137,8 +141,8 @@ OV.Model = class extends OV.ModelObject3D
return null;
}
let foundMesh = this.GetMesh (instanceId.meshIndex);
let id = new OV.MeshInstanceId (foundNode.GetId (), instanceId.meshIndex);
return new OV.MeshInstance (id, foundNode, foundMesh);
let id = new MeshInstanceId (foundNode.GetId (), instanceId.meshIndex);
return new MeshInstance (id, foundNode, foundMesh);
}
EnumerateMeshes (onMesh)
@ -152,9 +156,9 @@ OV.Model = class extends OV.ModelObject3D
{
this.root.Enumerate ((node) => {
for (let meshIndex of node.GetMeshIndices ()) {
let id = new OV.MeshInstanceId (node.GetId (), meshIndex);
let id = new MeshInstanceId (node.GetId (), meshIndex);
let mesh = this.GetMesh (meshIndex);
let meshInstance = new OV.MeshInstance (id, node, mesh);
let meshInstance = new MeshInstance (id, node, mesh);
onMeshInstance (meshInstance);
}
});
@ -188,4 +192,4 @@ OV.Model = class extends OV.ModelObject3D
meshInstance.EnumerateTriangleVertices (onTriangleVertices);
});
}
};
}

View File

@ -1,13 +1,19 @@
OV.ModelFinalizer = class
import { CopyObjectAttributes } from '../core/core.js';
import { AddCoord3D, Coord3D, CoordIsEqual3D } from '../geometry/coord3d.js';
import { Color } from './color.js';
import { PhongMaterial } from './material.js';
import { CalculateTriangleNormal, GetMeshType, MeshType } from './meshutils.js';
export class ModelFinalizer
{
constructor (params)
{
this.params = {
getDefaultMaterialColor : () => {
return new OV.Color (0, 0, 0);
return new Color (0, 0, 0);
}
};
OV.CopyObjectAttributes (params, this.params);
CopyObjectAttributes (params, this.params);
this.defaultMaterialIndex = null;
}
@ -51,8 +57,8 @@ OV.ModelFinalizer = class
{
for (let meshIndex = 0; meshIndex < model.MeshCount (); meshIndex++) {
let mesh = model.GetMesh (meshIndex);
let type = OV.GetMeshType (mesh);
if (type === OV.MeshType.Empty) {
let type = GetMeshType (mesh);
if (type === MeshType.Empty) {
model.RemoveMesh (meshIndex);
meshIndex = meshIndex - 1;
continue;
@ -71,7 +77,7 @@ OV.ModelFinalizer = class
{
for (let i = 0; i < array.length; i++) {
let current = array[i];
if (OV.CoordIsEqual3D (current, normal)) {
if (CoordIsEqual3D (current, normal)) {
return true;
}
}
@ -91,9 +97,9 @@ OV.ModelFinalizer = class
}
}
let averageNormal = new OV.Coord3D (0.0, 0.0, 0.0);
let averageNormal = new Coord3D (0.0, 0.0, 0.0);
for (let i = 0; i < averageNormals.length; i++) {
averageNormal = OV.AddCoord3D (averageNormal, averageNormals[i]);
averageNormal = AddCoord3D (averageNormal, averageNormals[i]);
}
averageNormal.MultiplyScalar (1.0 / averageNormals.length);
averageNormal.Normalize ();
@ -112,7 +118,7 @@ OV.ModelFinalizer = class
let v0 = mesh.GetVertex (triangle.v0);
let v1 = mesh.GetVertex (triangle.v1);
let v2 = mesh.GetVertex (triangle.v2);
let normal = OV.CalculateTriangleNormal (v0, v1, v2);
let normal = CalculateTriangleNormal (v0, v1, v2);
triangleNormals.push (normal);
vertexToTriangles.get (triangle.v0).push (triangleIndex);
vertexToTriangles.get (triangle.v1).push (triangleIndex);
@ -155,7 +161,7 @@ OV.ModelFinalizer = class
let v0 = mesh.GetVertex (triangle.v0);
let v1 = mesh.GetVertex (triangle.v1);
let v2 = mesh.GetVertex (triangle.v2);
let normal = OV.CalculateTriangleNormal (v0, v1, v2);
let normal = CalculateTriangleNormal (v0, v1, v2);
let normalIndex = mesh.AddNormal (normal);
triangle.SetNormals (normalIndex, normalIndex, normalIndex);
} else {
@ -196,7 +202,7 @@ OV.ModelFinalizer = class
{
if (this.defaultMaterialIndex === null) {
let defaultMaterialColor = this.params.getDefaultMaterialColor ();
let defaultMaterial = new OV.PhongMaterial ();
let defaultMaterial = new PhongMaterial ();
defaultMaterial.color = defaultMaterialColor;
defaultMaterial.isDefault = true;
this.defaultMaterialIndex = model.AddMaterial (defaultMaterial);
@ -208,15 +214,15 @@ OV.ModelFinalizer = class
{
this.defaultMaterialIndex = null;
}
};
}
OV.FinalizeModel = function (model, params)
export function FinalizeModel (model, params)
{
let finalizer = new OV.ModelFinalizer (params);
let finalizer = new ModelFinalizer (params);
finalizer.Finalize (model);
};
}
OV.CheckModel = function (model)
export function CheckModel (model)
{
function IsCorrectValue (val)
{
@ -369,4 +375,4 @@ OV.CheckModel = function (model)
}
return true;
};
}

View File

@ -1,24 +1,29 @@
OV.IsModelEmpty = function (model)
import { BoundingBoxCalculator3D } from '../geometry/box3d.js';
import { Octree } from '../geometry/octree.js';
import { GetMeshType, MeshType } from './meshutils.js';
import { Topology } from './topology.js';
export function IsModelEmpty (model)
{
let isEmpty = true;
model.EnumerateMeshInstances ((meshInstance) => {
if (OV.GetMeshType (meshInstance) !== OV.MeshType.Empty) {
if (GetMeshType (meshInstance) !== MeshType.Empty) {
isEmpty = false;
}
});
return isEmpty;
};
}
OV.GetBoundingBox = function (object3D)
export function GetBoundingBox (object3D)
{
let calculator = new OV.BoundingBoxCalculator3D ();
let calculator = new BoundingBoxCalculator3D ();
object3D.EnumerateVertices ((vertex) => {
calculator.AddPoint (vertex);
});
return calculator.GetBox ();
};
}
OV.GetTopology = function (object3D)
export function GetTopology (object3D)
{
function GetVertexIndex (vertex, octree, topology)
{
@ -30,9 +35,9 @@ OV.GetTopology = function (object3D)
return index;
}
let boundingBox = OV.GetBoundingBox (object3D);
let octree = new OV.Octree (boundingBox);
let topology = new OV.Topology ();
let boundingBox = GetBoundingBox (object3D);
let octree = new Octree (boundingBox);
let topology = new Topology ();
object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
let v0Index = GetVertexIndex (v0, octree, topology);
@ -41,9 +46,9 @@ OV.GetTopology = function (object3D)
topology.AddTriangle (v0Index, v1Index, v2Index);
});
return topology;
};
}
OV.IsSolid = function (object3D)
export function IsSolid (object3D)
{
function GetEdgeOrientationInTriangle (topology, triangleIndex, edgeIndex)
{
@ -63,7 +68,7 @@ OV.IsSolid = function (object3D)
return null;
}
const topology = OV.GetTopology (object3D);
const topology = GetTopology (object3D);
for (let edgeIndex = 0; edgeIndex < topology.edges.length; edgeIndex++) {
const edge = topology.edges[edgeIndex];
let triCount = edge.triangles.length;
@ -85,9 +90,9 @@ OV.IsSolid = function (object3D)
}
}
return true;
};
}
OV.HasDefaultMaterial = function (model)
export function HasDefaultMaterial (model)
{
for (let i = 0; i < model.MaterialCount (); i++) {
let material = model.GetMaterial (i);
@ -96,9 +101,9 @@ OV.HasDefaultMaterial = function (model)
}
}
return false;
};
}
OV.ReplaceDefaultMaterialColor = function (model, color)
export function ReplaceDefaultMaterialColor (model, color)
{
for (let i = 0; i < model.MaterialCount (); i++) {
let material = model.GetMaterial (i);
@ -106,4 +111,4 @@ OV.ReplaceDefaultMaterialColor = function (model, color)
material.color = color;
}
}
};
}

View File

@ -1,10 +1,12 @@
OV.NodeType =
import { Transformation } from '../geometry/transformation.js';
export const NodeType =
{
GroupNode : 0,
MeshNode : 1
};
OV.NodeIdGenerator = class
export class NodeIdGenerator
{
constructor ()
{
@ -17,21 +19,21 @@ OV.NodeIdGenerator = class
this.nextId += 1;
return id;
}
};
}
OV.Node = class
export class Node
{
constructor ()
{
this.type = OV.NodeType.GroupNode;
this.type = NodeType.GroupNode;
this.name = '';
this.parent = null;
this.transformation = new OV.Transformation ();
this.transformation = new Transformation ();
this.childNodes = [];
this.meshIndices = [];
this.idGenerator = new OV.NodeIdGenerator ();
this.idGenerator = new NodeIdGenerator ();
this.id = this.idGenerator.GenerateId ();
}
@ -173,4 +175,4 @@ OV.Node = class
childNode.EnumerateMeshIndices (processor);
}
}
};
}

View File

@ -1,4 +1,4 @@
OV.Object3D = class
export class Object3D
{
constructor ()
{
@ -44,9 +44,9 @@ OV.Object3D = class
{
}
};
}
OV.ModelObject3D = class extends OV.Object3D
export class ModelObject3D extends Object3D
{
constructor ()
{
@ -80,4 +80,4 @@ OV.ModelObject3D = class extends OV.Object3D
{
return this.propertyGroups[index];
}
};
}

View File

@ -1,4 +1,4 @@
OV.PropertyType =
export const PropertyType =
{
Text : 1,
Integer : 2,
@ -8,7 +8,7 @@ OV.PropertyType =
Color : 6
};
OV.Property = class
export class Property
{
constructor (type, name, value)
{
@ -16,9 +16,9 @@ OV.Property = class
this.name = name;
this.value = value;
}
};
}
OV.PropertyGroup = class
export class PropertyGroup
{
constructor (name)
{
@ -40,4 +40,4 @@ OV.PropertyGroup = class
{
return this.properties[index];
}
};
}

View File

@ -0,0 +1,37 @@
import { CoordDistance3D, CrossVector3D, DotVector3D } from '../geometry/coord3d.js';
export function GetTriangleArea (v0, v1, v2)
{
const a = CoordDistance3D (v0, v1);
const b = CoordDistance3D (v1, v2);
const c = CoordDistance3D (v0, v2);
const s = (a + b + c) / 2.0;
const areaSquare = s * (s - a) * (s - b) * (s - c);
if (areaSquare < 0.0) {
return 0.0;
}
return Math.sqrt (areaSquare);
}
export function GetTetrahedronSignedVolume (v0, v1, v2)
{
return DotVector3D (v0, CrossVector3D (v1, v2)) / 6.0;
}
export function CalculateVolume (object3D)
{
let volume = 0.0;
object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
volume += GetTetrahedronSignedVolume (v0, v1, v2);
});
return volume;
}
export function CalculateSurfaceArea (object3D)
{
let surface = 0.0;
object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
surface += GetTriangleArea (v0, v1, v2);
});
return surface;
}

View File

@ -1,13 +1,13 @@
OV.TopologyVertex = class
export class TopologyVertex
{
constructor ()
{
this.edges = [];
this.triangles = [];
}
};
}
OV.TopologyEdge = class
export class TopologyEdge
{
constructor (vertex1, vertex2)
{
@ -15,18 +15,18 @@ OV.TopologyEdge = class
this.vertex2 = vertex2;
this.triangles = [];
}
};
}
OV.TopologyTriangleEdge = class
export class TopologyTriangleEdge
{
constructor (edge, reversed)
{
this.edge = edge;
this.reversed = reversed;
}
};
}
OV.TopologyTriangle = class
export class TopologyTriangle
{
constructor ()
{
@ -34,9 +34,9 @@ OV.TopologyTriangle = class
this.triEdge2 = null;
this.triEdge3 = null;
}
};
}
OV.Topology = class
export class Topology
{
constructor ()
{
@ -49,7 +49,7 @@ OV.Topology = class
AddVertex ()
{
this.vertices.push (new OV.TopologyVertex ());
this.vertices.push (new TopologyVertex ());
return this.vertices.length - 1;
}
@ -76,7 +76,7 @@ OV.Topology = class
}
let triangleIndex = this.triangles.length;
let triangle = new OV.TopologyTriangle ();
let triangle = new TopologyTriangle ();
triangle.triEdge1 = this.AddTriangleEdge (vertex1, vertex2);
triangle.triEdge2 = this.AddTriangleEdge (vertex2, vertex3);
triangle.triEdge3 = this.AddTriangleEdge (vertex3, vertex1);
@ -108,7 +108,7 @@ OV.Topology = class
}
let edgeIndex = this.AddEdge (startVertex, endVertex);
this.triangleEdges.push (new OV.TopologyTriangleEdge (edgeIndex, reversed));
this.triangleEdges.push (new TopologyTriangleEdge (edgeIndex, reversed));
return this.triangleEdges.length - 1;
}
@ -132,7 +132,7 @@ OV.Topology = class
edgeIndex : edgeIndex
});
this.edges.push (new OV.TopologyEdge (startVertex, endVertex));
this.edges.push (new TopologyEdge (startVertex, endVertex));
return edgeIndex;
}
};
}

View File

@ -1,4 +1,4 @@
OV.Triangle = class
export class Triangle
{
constructor (v0, v1, v2)
{
@ -88,7 +88,7 @@ OV.Triangle = class
Clone ()
{
let cloned = new OV.Triangle (this.v0, this.v1, this.v2);
let cloned = new Triangle (this.v0, this.v1, this.v2);
cloned.SetVertexColors (this.c0, this.c1, this.c2);
cloned.SetNormals (this.n0, this.n1, this.n2);
cloned.SetTextureUVs (this.u0, this.u1, this.u2);
@ -96,4 +96,4 @@ OV.Triangle = class
cloned.SetCurve (this.curve);
return cloned;
}
};
}

View File

@ -1,4 +1,8 @@
OV.ParameterConverter =
import { Coord3D } from '../geometry/coord3d.js';
import { Color } from '../model/color.js';
import { Camera } from '../viewer/navigation.js';
export let ParameterConverter =
{
IntegerToString (integer)
{
@ -59,10 +63,10 @@ OV.ParameterConverter =
if (paramParts.length !== 9) {
return null;
}
let camera = new OV.Camera (
new OV.Coord3D (this.StringToNumber (paramParts[0]), this.StringToNumber (paramParts[1]), this.StringToNumber (paramParts[2])),
new OV.Coord3D (this.StringToNumber (paramParts[3]), this.StringToNumber (paramParts[4]), this.StringToNumber (paramParts[5])),
new OV.Coord3D (this.StringToNumber (paramParts[6]), this.StringToNumber (paramParts[7]), this.StringToNumber (paramParts[8]))
let camera = new Camera (
new Coord3D (this.StringToNumber (paramParts[0]), this.StringToNumber (paramParts[1]), this.StringToNumber (paramParts[2])),
new Coord3D (this.StringToNumber (paramParts[3]), this.StringToNumber (paramParts[4]), this.StringToNumber (paramParts[5])),
new Coord3D (this.StringToNumber (paramParts[6]), this.StringToNumber (paramParts[7]), this.StringToNumber (paramParts[8]))
);
return camera;
},
@ -89,7 +93,7 @@ OV.ParameterConverter =
if (paramParts.length !== 3) {
return null;
}
let color = new OV.Color (
let color = new Color (
this.StringToInteger (paramParts[0]),
this.StringToInteger (paramParts[1]),
this.StringToInteger (paramParts[2])
@ -121,7 +125,7 @@ OV.ParameterConverter =
}
let edgeSettings = {
showEdges : paramParts[0] === 'on' ? true : false,
edgeColor : new OV.Color (
edgeColor : new Color (
this.StringToInteger (paramParts[1]),
this.StringToInteger (paramParts[2]),
this.StringToInteger (paramParts[3])
@ -132,7 +136,7 @@ OV.ParameterConverter =
}
};
OV.ParameterListBuilder = class
export class ParameterListBuilder
{
constructor (separator)
{
@ -142,31 +146,31 @@ OV.ParameterListBuilder = class
AddModelUrls (urls)
{
this.AddUrlPart ('model', OV.ParameterConverter.ModelUrlsToString (urls));
this.AddUrlPart ('model', ParameterConverter.ModelUrlsToString (urls));
return this;
}
AddCamera (camera)
{
this.AddUrlPart ('camera', OV.ParameterConverter.CameraToString (camera));
this.AddUrlPart ('camera', ParameterConverter.CameraToString (camera));
return this;
}
AddBackgroundColor (background)
{
this.AddUrlPart ('backgroundcolor', OV.ParameterConverter.ColorToString (background));
this.AddUrlPart ('backgroundcolor', ParameterConverter.ColorToString (background));
return this;
}
AddDefaultColor (color)
{
this.AddUrlPart ('defaultcolor', OV.ParameterConverter.ColorToString (color));
this.AddUrlPart ('defaultcolor', ParameterConverter.ColorToString (color));
return this;
}
AddEdgeSettings (edgeSettings)
{
this.AddUrlPart ('edgesettings', OV.ParameterConverter.EdgeSettingsToString (edgeSettings));
this.AddUrlPart ('edgesettings', ParameterConverter.EdgeSettingsToString (edgeSettings));
return this;
}
@ -185,9 +189,9 @@ OV.ParameterListBuilder = class
{
return this.paramList;
}
};
}
OV.ParameterListParser = class
export class ParameterListParser
{
constructor (paramList, separator)
{
@ -203,31 +207,31 @@ OV.ParameterListParser = class
}
let keywordParams = this.GetKeywordParams ('model');
return OV.ParameterConverter.StringToModelUrls (keywordParams);
return ParameterConverter.StringToModelUrls (keywordParams);
}
GetCamera ()
{
let keywordParams = this.GetKeywordParams ('camera');
return OV.ParameterConverter.StringToCamera (keywordParams);
return ParameterConverter.StringToCamera (keywordParams);
}
GetBackgroundColor ()
{
let backgroundParams = this.GetKeywordParams ('backgroundcolor');
return OV.ParameterConverter.StringToColor (backgroundParams);
return ParameterConverter.StringToColor (backgroundParams);
}
GetDefaultColor ()
{
let colorParams = this.GetKeywordParams ('defaultcolor');
return OV.ParameterConverter.StringToColor (colorParams);
return ParameterConverter.StringToColor (colorParams);
}
GetEdgeSettings ()
{
let edgeSettingsParams = this.GetKeywordParams ('edgesettings');
return OV.ParameterConverter.StringToEdgeSettings (edgeSettingsParams);
return ParameterConverter.StringToEdgeSettings (edgeSettingsParams);
}
GetKeywordParams (keyword)
@ -245,21 +249,21 @@ OV.ParameterListParser = class
}
return null;
}
};
}
OV.CreateUrlBuilder = function ()
export function CreateUrlBuilder ()
{
return new OV.ParameterListBuilder ('$');
};
return new ParameterListBuilder ('$');
}
OV.CreateUrlParser = function (urlParams)
export function CreateUrlParser (urlParams)
{
return new OV.ParameterListParser (urlParams, '$');
};
return new ParameterListParser (urlParams, '$');
}
OV.CreateModelUrlParameters = function (urls)
export function CreateModelUrlParameters (urls)
{
let builder = OV.CreateUrlBuilder ();
let builder = CreateUrlBuilder ();
builder.AddModelUrls (urls);
return builder.GetParameterList ();
};
}

View File

@ -1,20 +1,27 @@
OV.ModelToThreeConversionParams = class
import { RunTasksBatch } from '../core/taskrunner.js';
import { IsEqual } from '../geometry/geometry.js';
import { MaterialType } from '../model/material.js';
import { MeshInstanceId } from '../model/meshinstance.js';
import { GetMeshType, MeshType } from '../model/meshutils.js';
import { ConvertColorToThreeColor, GetShadingType, ShadingType } from './threeutils.js';
export class ModelToThreeConversionParams
{
constructor ()
{
this.forceMediumpForMaterials = false;
}
};
}
OV.ModelToThreeConversionOutput = class
export class ModelToThreeConversionOutput
{
constructor ()
{
this.defaultMaterial = null;
}
};
}
OV.ThreeConversionStateHandler = class
export class ThreeConversionStateHandler
{
constructor (callbacks)
{
@ -48,9 +55,9 @@ OV.ThreeConversionStateHandler = class
this.callbacks.onModelLoaded (this.threeObject);
}
}
};
}
OV.ThreeNodeTree = class
export class ThreeNodeTree
{
constructor (rootNode, threeRootNode)
{
@ -82,9 +89,9 @@ OV.ThreeNodeTree = class
{
return this.meshInstances;
}
};
}
OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
export function ConvertModelToThreeObject (model, params, output, callbacks)
{
function CreateThreeMaterial (stateHandler, model, materialIndex, shadingType, params, output)
{
@ -121,7 +128,7 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
}
let material = model.GetMaterial (materialIndex);
let baseColor = OV.ConvertColorToThreeColor (material.color);
let baseColor = ConvertColorToThreeColor (material.color);
if (material.vertexColors) {
baseColor.setRGB (1.0, 1.0, 1.0);
}
@ -140,11 +147,11 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
}
let threeMaterial = null;
if (shadingType === OV.ShadingType.Phong) {
if (shadingType === ShadingType.Phong) {
threeMaterial = new THREE.MeshPhongMaterial (materialParams);
if (material.type === OV.MaterialType.Phong) {
let specularColor = OV.ConvertColorToThreeColor (material.specular);
if (OV.IsEqual (material.shininess, 0.0)) {
if (material.type === MaterialType.Phong) {
let specularColor = ConvertColorToThreeColor (material.specular);
if (IsEqual (material.shininess, 0.0)) {
specularColor.setRGB (0.0, 0.0, 0.0);
}
threeMaterial.specular = specularColor;
@ -153,9 +160,9 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
threeMaterial.specularMap = threeTexture;
});
}
} else if (shadingType === OV.ShadingType.Physical) {
} else if (shadingType === ShadingType.Physical) {
threeMaterial = new THREE.MeshStandardMaterial (materialParams);
if (material.type === OV.MaterialType.Physical) {
if (material.type === MaterialType.Physical) {
threeMaterial.metalness = material.metalness;
threeMaterial.roughness = material.roughness;
LoadTexture (stateHandler, threeMaterial, material.metalnessMap, (threeTexture) => {
@ -167,7 +174,7 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
}
}
let emissiveColor = OV.ConvertColorToThreeColor (material.emissive);
let emissiveColor = ConvertColorToThreeColor (material.emissive);
threeMaterial.emissive = emissiveColor;
LoadTexture (stateHandler, threeMaterial, material.diffuseMap, (threeTexture) => {
@ -236,9 +243,9 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
vertices.push (v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z);
if (triangle.HasVertexColors ()) {
let vc0 = OV.ConvertColorToThreeColor (mesh.GetVertexColor (triangle.c0));
let vc1 = OV.ConvertColorToThreeColor (mesh.GetVertexColor (triangle.c1));
let vc2 = OV.ConvertColorToThreeColor (mesh.GetVertexColor (triangle.c2));
let vc0 = ConvertColorToThreeColor (mesh.GetVertexColor (triangle.c0));
let vc1 = ConvertColorToThreeColor (mesh.GetVertexColor (triangle.c1));
let vc2 = ConvertColorToThreeColor (mesh.GetVertexColor (triangle.c2));
vertexColors.push (
vc0.r, vc0.g, vc0.b,
vc1.r, vc1.g, vc1.b,
@ -309,8 +316,8 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
function ConvertMesh (threeObject, model, meshInstanceId, modelThreeMaterials)
{
let mesh = model.GetMesh (meshInstanceId.meshIndex);
let type = OV.GetMeshType (mesh);
if (type === OV.MeshType.TriangleMesh) {
let type = GetMeshType (mesh);
if (type === MeshType.TriangleMesh) {
let threeMesh = CreateThreeMesh (model, meshInstanceId, modelThreeMaterials);
threeObject.add (threeMesh);
}
@ -319,16 +326,16 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
function ConvertNodeHierarchy (threeRootNode, model, modelThreeMaterials, stateHandler)
{
let rootNode = model.GetRootNode ();
let nodeTree = new OV.ThreeNodeTree (rootNode, threeRootNode);
let nodeTree = new ThreeNodeTree (rootNode, threeRootNode);
let meshInstances = nodeTree.GetMeshInstances ();
OV.RunTasksBatch (meshInstances.length, 100, {
RunTasksBatch (meshInstances.length, 100, {
runTask : (firstMeshInstanceIndex, lastMeshInstanceIndex, onReady) => {
for (let meshInstanceIndex = firstMeshInstanceIndex; meshInstanceIndex <= lastMeshInstanceIndex; meshInstanceIndex++) {
let meshInstance = meshInstances[meshInstanceIndex];
let node = meshInstance.node;
let threeNode = meshInstance.threeNode;
let meshInstanceId = new OV.MeshInstanceId (node.GetId (), meshInstance.meshIndex);
let meshInstanceId = new MeshInstanceId (node.GetId (), meshInstance.meshIndex);
ConvertMesh (threeNode, model, meshInstanceId, modelThreeMaterials);
}
onReady ();
@ -339,8 +346,8 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
});
}
let stateHandler = new OV.ThreeConversionStateHandler (callbacks);
let shadingType = OV.GetShadingType (model);
let stateHandler = new ThreeConversionStateHandler (callbacks);
let shadingType = GetShadingType (model);
let modelThreeMaterials = [];
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
@ -350,4 +357,4 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
let threeObject = new THREE.Object3D ();
ConvertNodeHierarchy (threeObject, model, modelThreeMaterials, stateHandler);
};
}

View File

@ -1,11 +1,15 @@
OV.ThreeModelLoader = class
import { Importer } from '../import/importer.js';
import { ConvertModelToThreeObject, ModelToThreeConversionOutput, ModelToThreeConversionParams } from './threeconverter.js';
import { ConvertColorToThreeColor, HasHighpDriverIssue } from './threeutils.js';
export class ThreeModelLoader
{
constructor ()
{
this.importer = new OV.Importer ();
this.importer = new Importer ();
this.inProgress = false;
this.defaultMaterial = null;
this.hasHighpDriverIssue = OV.HasHighpDriverIssue ();
this.hasHighpDriverIssue = HasHighpDriverIssue ();
}
InProgress ()
@ -34,10 +38,10 @@ OV.ThreeModelLoader = class
},
onImportSuccess : (importResult) => {
callbacks.onVisualizationStart ();
let params = new OV.ModelToThreeConversionParams ();
let params = new ModelToThreeConversionParams ();
params.forceMediumpForMaterials = this.hasHighpDriverIssue;
let output = new OV.ModelToThreeConversionOutput ();
OV.ConvertModelToThreeObject (importResult.model, params, output, {
let output = new ModelToThreeConversionOutput ();
ConvertModelToThreeObject (importResult.model, params, output, {
onTextureLoaded : () => {
callbacks.onTextureLoaded ();
},
@ -68,7 +72,7 @@ OV.ThreeModelLoader = class
ReplaceDefaultMaterialColor (defaultColor)
{
if (this.defaultMaterial !== null && !this.defaultMaterial.vertexColors) {
this.defaultMaterial.color = OV.ConvertColorToThreeColor (defaultColor);
this.defaultMaterial.color = ConvertColorToThreeColor (defaultColor);
}
}
};
}

View File

@ -1,8 +1,16 @@
// Some mobile devices say that they support mediump, but in reality they don't. At the end
// all materials rendered as black. This hack renders a single plane with red material and
// it checks if it's really red. If it's not, then probably there is a driver issue.
import { Coord2D } from '../geometry/coord2d.js';
import { Coord3D } from '../geometry/coord3d.js';
import { ColorFromFloatComponents } from '../model/color.js';
import { MaterialType } from '../model/material.js';
import { Mesh } from '../model/mesh.js';
import { Triangle } from '../model/triangle.js';
// https://github.com/kovacsv/Online3DViewer/issues/69
OV.HasHighpDriverIssue = function ()
export function HasHighpDriverIssue ()
{
let canvas = document.createElement ('canvas');
document.body.appendChild (canvas);
@ -53,57 +61,57 @@ OV.HasHighpDriverIssue = function ()
return true;
}
return false;
};
}
OV.ShadingType =
export const ShadingType =
{
Phong : 1,
Physical : 2
};
OV.GetShadingType = function (model)
export function GetShadingType (model)
{
let phongCount = 0;
let physicalCount = 0;
for (let i = 0; i < model.MaterialCount (); i++) {
let material = model.GetMaterial (i);
if (material.type === OV.MaterialType.Phong) {
if (material.type === MaterialType.Phong) {
phongCount += 1;
} else if (material.type === OV.MaterialType.Physical) {
} else if (material.type === MaterialType.Physical) {
physicalCount += 1;
}
}
if (phongCount >= physicalCount) {
return OV.ShadingType.Phong;
return ShadingType.Phong;
} else {
return OV.ShadingType.Physical;
return ShadingType.Physical;
}
};
}
OV.ConvertThreeColorToColor = function (threeColor)
export function ConvertThreeColorToColor (threeColor)
{
return OV.ColorFromFloatComponents (threeColor.r, threeColor.g, threeColor.b);
};
return ColorFromFloatComponents (threeColor.r, threeColor.g, threeColor.b);
}
OV.ConvertColorToThreeColor = function (color)
export function ConvertColorToThreeColor (color)
{
return new THREE.Color (
color.r / 255.0,
color.g / 255.0,
color.b / 255.0
);
};
}
OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
export function ConvertThreeGeometryToMesh (threeGeometry, materialIndex)
{
let mesh = new OV.Mesh ();
let mesh = new Mesh ();
let vertices = threeGeometry.attributes.position.array;
for (let i = 0; i < vertices.length; i += 3) {
let x = vertices[i];
let y = vertices[i + 1];
let z = vertices[i + 2];
mesh.AddVertex (new OV.Coord3D (x, y, z));
mesh.AddVertex (new Coord3D (x, y, z));
}
let hasVertexColors = (threeGeometry.attributes.color !== undefined);
@ -112,7 +120,7 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
let itemSize = threeGeometry.attributes.color.itemSize;
for (let i = 0; i < colors.length; i += itemSize) {
let threeColor = new THREE.Color (colors[i], colors[i + 1], colors[i + 2]);
mesh.AddVertexColor (OV.ConvertThreeColorToColor (threeColor));
mesh.AddVertexColor (ConvertThreeColorToColor (threeColor));
}
}
@ -123,7 +131,7 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
let x = normals[i];
let y = normals[i + 1];
let z = normals[i + 2];
mesh.AddNormal (new OV.Coord3D (x, y, z));
mesh.AddNormal (new Coord3D (x, y, z));
}
}
@ -133,7 +141,7 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
for (let i = 0; i < uvs.length; i += 2) {
let x = uvs[i];
let y = uvs[i + 1];
mesh.AddTextureUV (new OV.Coord2D (x, y));
mesh.AddTextureUV (new Coord2D (x, y));
}
}
@ -151,7 +159,7 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
let v0 = indices[i];
let v1 = indices[i + 1];
let v2 = indices[i + 2];
let triangle = new OV.Triangle (v0, v1, v2);
let triangle = new Triangle (v0, v1, v2);
if (hasVertexColors) {
triangle.SetVertexColors (v0, v1, v2);
}
@ -168,4 +176,4 @@ OV.ConvertThreeGeometryToMesh = function (threeGeometry, materialIndex)
}
return mesh;
};
}

View File

@ -0,0 +1,225 @@
import { Coord2D } from '../geometry/coord2d.js';
export function GetIntegerFromStyle (parameter)
{
return Math.round (parseFloat (parameter));
}
export function GetDomElementExternalWidth (style)
{
let padding = GetIntegerFromStyle (style.paddingLeft) + GetIntegerFromStyle (style.paddingRight);
let border = GetIntegerFromStyle (style.borderLeftWidth) + GetIntegerFromStyle (style.borderRightWidth);
let margin = GetIntegerFromStyle (style.marginLeft) + GetIntegerFromStyle (style.marginRight);
return padding + border + margin;
}
export function GetDomElementExternalHeight (style)
{
let padding = GetIntegerFromStyle (style.paddingTop) + GetIntegerFromStyle (style.paddingBottom);
let border = GetIntegerFromStyle (style.borderTopWidth) + GetIntegerFromStyle (style.borderBottomWidth);
let margin = GetIntegerFromStyle (style.marginTop) + GetIntegerFromStyle (style.marginBottom);
return padding + border + margin;
}
export function GetDomElementInnerDimensions (element, outerWidth, outerHeight)
{
let style = getComputedStyle (element);
let width = outerWidth - GetDomElementExternalWidth (style);
let height = outerHeight - GetDomElementExternalHeight (style);
return {
width : width,
height : height
};
}
export function GetDomElementClientCoordinates (element, clientX, clientY)
{
if (element.getBoundingClientRect) {
let clientRect = element.getBoundingClientRect ();
clientX -= clientRect.left;
clientY -= clientRect.top;
}
if (window.pageXOffset && window.pageYOffset) {
clientX += window.pageXOffset;
clientY += window.pageYOffset;
}
return (new Coord2D (clientX, clientY));
}
export function CreateDomElement (elementType, className, innerHTML)
{
let element = document.createElement (elementType);
if (className) {
element.className = className;
}
if (innerHTML) {
element.innerHTML = innerHTML;
}
return element;
}
export function AddDomElement (parentElement, elementType, className, innerHTML)
{
let element = CreateDomElement (elementType, className, innerHTML);
parentElement.appendChild (element);
return element;
}
export function AddDiv (parentElement, className, innerHTML)
{
return AddDomElement (parentElement, 'div', className, innerHTML);
}
export function ClearDomElement (element)
{
while (element.firstChild) {
element.removeChild (element.firstChild);
}
}
export function InsertDomElementBefore (newElement, existingElement)
{
existingElement.parentNode.insertBefore (newElement, existingElement);
}
export function InsertDomElementAfter (newElement, existingElement)
{
existingElement.parentNode.insertBefore (newElement, existingElement.nextSibling);
}
export function ShowDomElement (element, show)
{
if (show) {
element.style.display = 'block';
} else {
element.style.display = 'none';
}
}
export function IsDomElementVisible (element)
{
return element.offsetParent !== null;
}
export function SetDomElementWidth (element, width)
{
element.style.width = width.toString () + 'px';
}
export function SetDomElementHeight (element, height)
{
element.style.height = height.toString () + 'px';
}
export function GetDomElementOuterWidth (element)
{
let style = getComputedStyle (element);
return element.offsetWidth + GetIntegerFromStyle (style.marginLeft) + GetIntegerFromStyle (style.marginRight);
}
export function GetDomElementOuterHeight (element)
{
let style = getComputedStyle (element);
return element.offsetHeight + GetIntegerFromStyle (style.marginTop) + GetIntegerFromStyle (style.marginBottom);
}
export function SetDomElementOuterWidth (element, width)
{
let style = getComputedStyle (element);
SetDomElementWidth (element, width - GetDomElementExternalWidth (style));
}
export function SetDomElementOuterHeight (element, height)
{
let style = getComputedStyle (element);
SetDomElementHeight (element, height - GetDomElementExternalHeight (style));
}
export function AddCheckbox (parentElement, id, text, isChecked, onChange)
{
let label = AddDomElement (parentElement, 'label');
label.setAttribute ('for', id);
let check = AddDomElement (label, 'input', 'ov_checkbox');
check.setAttribute ('type', 'checkbox');
check.setAttribute ('id', id);
check.checked = isChecked;
AddDomElement (label, 'span', null, text);
if (onChange) {
check.addEventListener ('change', onChange);
}
return check;
}
export function AddRangeSlider (parentElement, min, max)
{
let slider = AddDomElement (parentElement, 'input', 'ov_slider');
slider.setAttribute ('type', 'range');
slider.setAttribute ('min', min.toString ());
slider.setAttribute ('max', max.toString ());
return slider;
}
export function AddSelect (parentElement, options, selectedIndex, onChange)
{
let container = AddDiv (parentElement, 'ov_select_container');
let select = AddDomElement (container, 'select', 'ov_select');
for (let option of options) {
AddDomElement (select, 'option', null, option);
}
select.selectedIndex = selectedIndex;
if (onChange) {
select.addEventListener ('change', () => {
onChange (select.selectedIndex);
});
}
return select;
}
export function AddToggle (parentElement, className)
{
function UpdateStatus (toggle, status)
{
if (status) {
toggle.classList.add ('on');
} else {
toggle.classList.remove ('on');
}
}
let status = false;
let onChange = null;
let toggleClassName = 'ov_toggle';
if (className) {
toggleClassName += ' ' + className;
}
let toggle = AddDiv (parentElement, toggleClassName);
AddDiv (toggle, 'ov_toggle_slider');
toggle.addEventListener ('click', () => {
status = !status;
UpdateStatus (toggle, status);
if (onChange) {
onChange ();
}
});
return {
element : toggle,
GetStatus : () => {
return status;
},
SetStatus : (newStatus) => {
status = newStatus;
UpdateStatus (toggle, status);
},
OnChange : (onChangeHandler) => {
onChange = onChangeHandler;
}
};
}
export function CreateDiv (className, innerHTML)
{
return CreateDomElement ('div', className, innerHTML);
}

View File

@ -1,17 +1,24 @@
OV.EmbeddedViewer = class
import { IsDefined } from '../core/core.js';
import { ImportErrorCode, ImportSettings } from '../import/importer.js';
import { FileSource, TransformFileHostUrls } from '../io/fileutils.js';
import { ParameterConverter } from '../parameters/parameterlist.js';
import { ThreeModelLoader } from '../threejs/threemodelloader.js';
import { Viewer } from './viewer.js';
export class EmbeddedViewer
{
constructor (parentElement, parameters)
{
this.parentElement = parentElement;
this.parameters = {};
if (OV.IsDefined (parameters)) {
if (IsDefined (parameters)) {
this.parameters = parameters;
}
this.canvas = document.createElement ('canvas');
this.parentElement.appendChild (this.canvas);
this.viewer = new OV.Viewer ();
this.viewer = new Viewer ();
this.viewer.Init (this.canvas);
let width = this.parentElement.clientWidth;
@ -46,16 +53,16 @@ OV.EmbeddedViewer = class
if (modelUrls === null || modelUrls.length === 0) {
return null;
}
OV.TransformFileHostUrls (modelUrls);
TransformFileHostUrls (modelUrls);
let settings = new OV.ImportSettings ();
let settings = new ImportSettings ();
if (this.parameters.defaultColor) {
settings.defaultColor = this.parameters.defaultColor;
}
let progressDiv = null;
let loader = new OV.ThreeModelLoader ();
loader.LoadModel (modelUrls, OV.FileSource.Url, settings, {
let loader = new ThreeModelLoader ();
loader.LoadModel (modelUrls, FileSource.Url, settings, {
onLoadStart : () => {
this.canvas.style.display = 'none';
progressDiv = document.createElement ('div');
@ -88,11 +95,11 @@ OV.EmbeddedViewer = class
},
onLoadError : (importError) => {
let message = 'Unknown error';
if (importError.code === OV.ImportErrorCode.NoImportableFile) {
if (importError.code === ImportErrorCode.NoImportableFile) {
message = 'No importable file found';
} else if (importError.code === OV.ImportErrorCode.FailedToLoadFile) {
} else if (importError.code === ImportErrorCode.FailedToLoadFile) {
message = 'Failed to load file for import.';
} else if (importError.code === OV.ImportErrorCode.ImportFailed) {
} else if (importError.code === ImportErrorCode.ImportFailed) {
message = 'Failed to import model.';
}
if (importError.message !== null) {
@ -114,41 +121,41 @@ OV.EmbeddedViewer = class
let height = this.parentElement.clientHeight;
this.viewer.Resize (width, height);
}
};
}
OV.Init3DViewerElement = function (parentElement, modelUrls, parameters)
export function Init3DViewerElement (parentElement, modelUrls, parameters)
{
let viewer = new OV.EmbeddedViewer (parentElement, parameters);
let viewer = new EmbeddedViewer (parentElement, parameters);
viewer.LoadModelFromUrls (modelUrls);
return viewer;
};
}
OV.Init3DViewerElements = function (onReady)
export function Init3DViewerElements (onReady)
{
function LoadElement (element)
{
let camera = null;
let cameraParams = element.getAttribute ('camera');
if (cameraParams) {
camera = OV.ParameterConverter.StringToCamera (cameraParams);
camera = ParameterConverter.StringToCamera (cameraParams);
}
let backgroundColor = null;
let backgroundColorParams = element.getAttribute ('backgroundcolor');
if (backgroundColorParams) {
backgroundColor = OV.ParameterConverter.StringToColor (backgroundColorParams);
backgroundColor = ParameterConverter.StringToColor (backgroundColorParams);
}
let defaultColor = null;
let defaultColorParams = element.getAttribute ('defaultcolor');
if (defaultColorParams) {
defaultColor = OV.ParameterConverter.StringToColor (defaultColorParams);
defaultColor = ParameterConverter.StringToColor (defaultColorParams);
}
let edgeSettings = null;
let edgeSettingsParams = element.getAttribute ('edgesettings');
if (edgeSettingsParams) {
edgeSettings = OV.ParameterConverter.StringToEdgeSettings (edgeSettingsParams);
edgeSettings = ParameterConverter.StringToEdgeSettings (edgeSettingsParams);
}
let environmentMap = null;
@ -163,10 +170,10 @@ OV.Init3DViewerElements = function (onReady)
let modelUrls = null;
let modelParams = element.getAttribute ('model');
if (modelParams) {
modelUrls = OV.ParameterConverter.StringToModelUrls (modelParams);
modelUrls = ParameterConverter.StringToModelUrls (modelParams);
}
return OV.Init3DViewerElement (element, modelUrls, {
return Init3DViewerElement (element, modelUrls, {
camera : camera,
backgroundColor : backgroundColor,
defaultColor : defaultColor,
@ -187,4 +194,4 @@ OV.Init3DViewerElements = function (onReady)
onReady (viewerElements);
}
});
};
}

View File

@ -1,4 +1,6 @@
OV.MeasureTool = class
import { BigEps, IsEqualEps } from '../geometry/geometry.js';
export class MeasureTool
{
constructor ()
{
@ -72,7 +74,7 @@ OV.MeasureTool = class
const bNormal = this.GetFaceWorldNormal (b);
result.pointsDistance = a.point.distanceTo (b.point);
result.facesAngle = aNormal.angleTo (bNormal);
if (OV.IsEqualEps (result.facesAngle, 0.0, OV.BigEps) || OV.IsEqualEps (result.facesAngle, Math.PI, OV.BigEps)) {
if (IsEqualEps (result.facesAngle, 0.0, BigEps) || IsEqualEps (result.facesAngle, Math.PI, BigEps)) {
let aPlane = new THREE.Plane ().setFromNormalAndCoplanarPoint (aNormal, a.point);
result.parallelFacesDistance = Math.abs (aPlane.distanceToPoint (b.point));
}
@ -119,4 +121,4 @@ OV.MeasureTool = class
faceNormal.applyMatrix4 (normalMatrix);
return faceNormal;
}
};
}

View File

@ -1,4 +1,10 @@
OV.Camera = class
import { Coord2D, CoordDistance2D, SubCoord2D } from '../geometry/coord2d.js';
import { CoordDistance3D, CoordIsEqual3D, CrossVector3D, SubCoord3D, VectorAngle3D } from '../geometry/coord3d.js';
import { DegRad, IsGreater, IsLower, IsZero } from '../geometry/geometry.js';
import { ParabolicTweenFunction, TweenCoord3D } from '../geometry/tween.js';
import { GetDomElementClientCoordinates } from './domutils.js';
export class Camera
{
constructor (eye, center, up)
{
@ -9,26 +15,26 @@ OV.Camera = class
Clone ()
{
return new OV.Camera (
return new Camera (
this.eye.Clone (),
this.center.Clone (),
this.up.Clone ()
);
}
};
}
OV.CameraIsEqual3D = function (a, b)
export function CameraIsEqual3D (a, b)
{
return OV.CoordIsEqual3D (a.eye, b.eye) && OV.CoordIsEqual3D (a.center, b.center) && OV.CoordIsEqual3D (a.up, b.up);
};
return CoordIsEqual3D (a.eye, b.eye) && CoordIsEqual3D (a.center, b.center) && CoordIsEqual3D (a.up, b.up);
}
OV.MouseInteraction = class
export class MouseInteraction
{
constructor ()
{
this.prev = new OV.Coord2D (0.0, 0.0);
this.curr = new OV.Coord2D (0.0, 0.0);
this.diff = new OV.Coord2D (0.0, 0.0);
this.prev = new Coord2D (0.0, 0.0);
this.curr = new Coord2D (0.0, 0.0);
this.diff = new Coord2D (0.0, 0.0);
this.buttons = [];
}
@ -42,7 +48,7 @@ OV.MouseInteraction = class
Move (canvas, ev)
{
this.curr = this.GetPositionFromEvent (canvas, ev);
this.diff = OV.SubCoord2D (this.curr, this.prev);
this.diff = SubCoord2D (this.curr, this.prev);
this.prev = this.curr.Clone ();
}
@ -87,17 +93,17 @@ OV.MouseInteraction = class
GetPositionFromEvent (canvas, ev)
{
return OV.GetDomElementClientCoordinates (canvas, ev.clientX, ev.clientY);
return GetDomElementClientCoordinates (canvas, ev.clientX, ev.clientY);
}
};
}
OV.TouchInteraction = class
export class TouchInteraction
{
constructor ()
{
this.prevPos = new OV.Coord2D (0.0, 0.0);
this.currPos = new OV.Coord2D (0.0, 0.0);
this.diffPos = new OV.Coord2D (0.0, 0.0);
this.prevPos = new Coord2D (0.0, 0.0);
this.currPos = new Coord2D (0.0, 0.0);
this.diffPos = new Coord2D (0.0, 0.0);
this.prevDist = 0.0;
this.currDist = 0.0;
this.diffDist = 0.0;
@ -126,7 +132,7 @@ OV.TouchInteraction = class
}
this.currPos = this.GetPositionFromEvent (canvas, ev);
this.diffPos = OV.SubCoord2D (this.currPos, this.prevPos);
this.diffPos = SubCoord2D (this.currPos, this.prevPos);
this.prevPos = this.currPos.Clone ();
this.currDist = this.GetTouchDistanceFromEvent (canvas, ev);
@ -175,7 +181,7 @@ OV.TouchInteraction = class
let coord = null;
if (ev.touches.length !== 0) {
let touchEv = ev.touches[0];
coord = OV.GetDomElementClientCoordinates (canvas, touchEv.pageX, touchEv.pageY);
coord = GetDomElementClientCoordinates (canvas, touchEv.pageX, touchEv.pageY);
}
return coord;
}
@ -187,15 +193,15 @@ OV.TouchInteraction = class
}
let touchEv1 = ev.touches[0];
let touchEv2 = ev.touches[1];
let distance = OV.CoordDistance2D (
OV.GetDomElementClientCoordinates (canvas, touchEv1.pageX, touchEv1.pageY),
OV.GetDomElementClientCoordinates (canvas, touchEv2.pageX, touchEv2.pageY)
let distance = CoordDistance2D (
GetDomElementClientCoordinates (canvas, touchEv1.pageX, touchEv1.pageY),
GetDomElementClientCoordinates (canvas, touchEv2.pageX, touchEv2.pageY)
);
return distance;
}
};
}
OV.ClickDetector = class
export class ClickDetector
{
constructor ()
{
@ -217,7 +223,7 @@ OV.ClickDetector = class
if (this.startPosition !== null) {
const maxClickDistance = 3.0;
const currentDistance = OV.CoordDistance2D (this.startPosition, currentPosition);
const currentDistance = CoordDistance2D (this.startPosition, currentPosition);
if (currentDistance > maxClickDistance) {
this.Cancel ();
}
@ -241,9 +247,9 @@ OV.ClickDetector = class
{
return this.isClick;
}
};
}
OV.NavigationType =
export const NavigationType =
{
None : 0,
Orbit : 1,
@ -251,7 +257,7 @@ OV.NavigationType =
Zoom : 3
};
OV.Navigation = class
export class Navigation
{
constructor (canvas, camera, callbacks)
{
@ -260,9 +266,9 @@ OV.Navigation = class
this.callbacks = callbacks;
this.fixUpVector = true;
this.mouse = new OV.MouseInteraction ();
this.touch = new OV.TouchInteraction ();
this.clickDetector = new OV.ClickDetector ();
this.mouse = new MouseInteraction ();
this.touch = new TouchInteraction ();
this.clickDetector = new ClickDetector ();
this.onMouseClick = null;
this.onMouseMove = null;
@ -339,14 +345,14 @@ OV.Navigation = class
return;
}
if (stepCount === 0 || OV.CameraIsEqual3D (this.camera, newCamera)) {
if (stepCount === 0 || CameraIsEqual3D (this.camera, newCamera)) {
this.camera = newCamera;
} else {
let tweenFunc = OV.ParabolicTweenFunction;
let tweenFunc = ParabolicTweenFunction;
let steps = {
eye : OV.TweenCoord3D (this.camera.eye, newCamera.eye, stepCount, tweenFunc),
center : OV.TweenCoord3D (this.camera.center, newCamera.center, stepCount, tweenFunc),
up : OV.TweenCoord3D (this.camera.up, newCamera.up, stepCount, tweenFunc)
eye : TweenCoord3D (this.camera.eye, newCamera.eye, stepCount, tweenFunc),
center : TweenCoord3D (this.camera.center, newCamera.center, stepCount, tweenFunc),
up : TweenCoord3D (this.camera.up, newCamera.up, stepCount, tweenFunc)
};
requestAnimationFrame (() => {
Step (this, steps, stepCount, 0);
@ -358,22 +364,22 @@ OV.Navigation = class
GetFitToSphereCamera (center, radius, fov)
{
if (OV.IsZero (radius)) {
if (IsZero (radius)) {
return null;
}
let fitCamera = this.camera.Clone ();
let offsetToOrigo = OV.SubCoord3D (fitCamera.center, center);
fitCamera.eye = OV.SubCoord3D (fitCamera.eye, offsetToOrigo);
let offsetToOrigo = SubCoord3D (fitCamera.center, center);
fitCamera.eye = SubCoord3D (fitCamera.eye, offsetToOrigo);
fitCamera.center = center.Clone ();
let centerEyeDirection = OV.SubCoord3D (fitCamera.eye, fitCamera.center).Normalize ();
let centerEyeDirection = SubCoord3D (fitCamera.eye, fitCamera.center).Normalize ();
let fieldOfView = fov / 2.0;
if (this.canvas.width < this.canvas.height) {
fieldOfView = fieldOfView * this.canvas.width / this.canvas.height;
}
let distance = radius / Math.sin (fieldOfView * OV.DegRad);
let distance = radius / Math.sin (fieldOfView * DegRad);
fitCamera.eye = fitCamera.center.Clone ().Offset (centerEyeDirection, distance);
@ -393,7 +399,7 @@ OV.Navigation = class
this.mouse.Move (this.canvas, ev);
this.clickDetector.Move (this.mouse.GetPosition ());
if (this.onMouseMove) {
let mouseCoords = OV.GetDomElementClientCoordinates (this.canvas, ev.clientX, ev.clientY);
let mouseCoords = GetDomElementClientCoordinates (this.canvas, ev.clientX, ev.clientY);
this.onMouseMove (mouseCoords);
}
@ -404,27 +410,27 @@ OV.Navigation = class
let moveDiff = this.mouse.GetMoveDiff ();
let mouseButton = this.mouse.GetButton ();
let navigationType = OV.NavigationType.None;
let navigationType = NavigationType.None;
if (mouseButton === 1) {
if (ev.ctrlKey) {
navigationType = OV.NavigationType.Zoom;
navigationType = NavigationType.Zoom;
} else if (ev.shiftKey) {
navigationType = OV.NavigationType.Pan;
navigationType = NavigationType.Pan;
} else {
navigationType = OV.NavigationType.Orbit;
navigationType = NavigationType.Orbit;
}
} else if (mouseButton === 2 || mouseButton === 3) {
navigationType = OV.NavigationType.Pan;
navigationType = NavigationType.Pan;
}
if (navigationType === OV.NavigationType.Orbit) {
if (navigationType === NavigationType.Orbit) {
let orbitRatio = 0.5;
this.Orbit (moveDiff.x * orbitRatio, moveDiff.y * orbitRatio);
} else if (navigationType === OV.NavigationType.Pan) {
let eyeCenterDistance = OV.CoordDistance3D (this.camera.eye, this.camera.center);
} else if (navigationType === NavigationType.Pan) {
let eyeCenterDistance = CoordDistance3D (this.camera.eye, this.camera.center);
let panRatio = 0.001 * eyeCenterDistance;
this.Pan (moveDiff.x * panRatio, moveDiff.y * panRatio);
} else if (navigationType === OV.NavigationType.Zoom) {
} else if (navigationType === NavigationType.Zoom) {
let zoomRatio = 0.005;
this.Zoom (-moveDiff.y * zoomRatio);
}
@ -471,20 +477,20 @@ OV.Navigation = class
let distanceDiff = this.touch.GetDistanceDiff ();
let fingerCount = this.touch.GetFingerCount ();
let navigationType = OV.NavigationType.None;
let navigationType = NavigationType.None;
if (fingerCount === 1) {
navigationType = OV.NavigationType.Orbit;
navigationType = NavigationType.Orbit;
} else if (fingerCount === 2) {
navigationType = OV.NavigationType.Pan;
navigationType = NavigationType.Pan;
}
if (navigationType === OV.NavigationType.Orbit) {
if (navigationType === NavigationType.Orbit) {
let orbitRatio = 0.5;
this.Orbit (moveDiff.x * orbitRatio, moveDiff.y * orbitRatio);
} else if (navigationType === OV.NavigationType.Pan) {
} else if (navigationType === NavigationType.Pan) {
let zoomRatio = 0.005;
this.Zoom (distanceDiff * zoomRatio);
let panRatio = 0.001 * OV.CoordDistance3D (this.camera.eye, this.camera.center);
let panRatio = 0.001 * CoordDistance3D (this.camera.eye, this.camera.center);
this.Pan (moveDiff.x * panRatio, moveDiff.y * panRatio);
}
@ -534,21 +540,21 @@ OV.Navigation = class
Orbit (angleX, angleY)
{
let radAngleX = angleX * OV.DegRad;
let radAngleY = angleY * OV.DegRad;
let radAngleX = angleX * DegRad;
let radAngleY = angleY * DegRad;
let viewDirection = OV.SubCoord3D (this.camera.center, this.camera.eye).Normalize ();
let horizontalDirection = OV.CrossVector3D (viewDirection, this.camera.up).Normalize ();
let viewDirection = SubCoord3D (this.camera.center, this.camera.eye).Normalize ();
let horizontalDirection = CrossVector3D (viewDirection, this.camera.up).Normalize ();
if (this.fixUpVector) {
let originalAngle = OV.VectorAngle3D (viewDirection, this.camera.up);
let originalAngle = VectorAngle3D (viewDirection, this.camera.up);
let newAngle = originalAngle + radAngleY;
if (OV.IsGreater (newAngle, 0.0) && OV.IsLower (newAngle, Math.PI)) {
if (IsGreater (newAngle, 0.0) && IsLower (newAngle, Math.PI)) {
this.camera.eye.Rotate (horizontalDirection, -radAngleY, this.camera.center);
}
this.camera.eye.Rotate (this.camera.up, -radAngleX, this.camera.center);
} else {
let verticalDirection = OV.CrossVector3D (horizontalDirection, viewDirection).Normalize ();
let verticalDirection = CrossVector3D (horizontalDirection, viewDirection).Normalize ();
this.camera.eye.Rotate (horizontalDirection, -radAngleY, this.camera.center);
this.camera.eye.Rotate (verticalDirection, -radAngleX, this.camera.center);
this.camera.up = verticalDirection;
@ -557,9 +563,9 @@ OV.Navigation = class
Pan (moveX, moveY)
{
let viewDirection = OV.SubCoord3D (this.camera.center, this.camera.eye).Normalize ();
let horizontalDirection = OV.CrossVector3D (viewDirection, this.camera.up).Normalize ();
let verticalDirection = OV.CrossVector3D (horizontalDirection, viewDirection).Normalize ();
let viewDirection = SubCoord3D (this.camera.center, this.camera.eye).Normalize ();
let horizontalDirection = CrossVector3D (viewDirection, this.camera.up).Normalize ();
let verticalDirection = CrossVector3D (horizontalDirection, viewDirection).Normalize ();
this.camera.eye.Offset (horizontalDirection, -moveX);
this.camera.center.Offset (horizontalDirection, -moveX);
@ -570,7 +576,7 @@ OV.Navigation = class
Zoom (ratio)
{
let direction = OV.SubCoord3D (this.camera.center, this.camera.eye);
let direction = SubCoord3D (this.camera.center, this.camera.eye);
let distance = direction.Length ();
let move = distance * ratio;
this.camera.eye.Offset (direction, move);
@ -595,8 +601,8 @@ OV.Navigation = class
x : clientX,
y : clientY
};
let localCoords = OV.GetDomElementClientCoordinates (this.canvas, clientX, clientY);
let localCoords = GetDomElementClientCoordinates (this.canvas, clientX, clientY);
this.onContext (globalCoords, localCoords);
}
}
};
}

View File

@ -1,50 +1,58 @@
OV.GetDefaultCamera = function (direction)
import { Coord3D, CoordDistance3D, SubCoord3D } from '../geometry/coord3d.js';
import { Direction } from '../geometry/geometry.js';
import { ColorToHexString } from '../model/color.js';
import { ShadingType } from '../threejs/threeutils.js';
import { GetDomElementInnerDimensions } from './domutils.js';
import { Camera, CameraIsEqual3D, Navigation } from './navigation.js';
import { ViewerExtraGeometry, ViewerGeometry } from './viewergeometry.js';
export function GetDefaultCamera (direction)
{
if (direction === OV.Direction.X) {
return new OV.Camera (
new OV.Coord3D (2.0, -3.0, 1.5),
new OV.Coord3D (0.0, 0.0, 0.0),
new OV.Coord3D (1.0, 0.0, 0.0)
if (direction === Direction.X) {
return new CameraIsEqual3D (
new Coord3D (2.0, -3.0, 1.5),
new Coord3D (0.0, 0.0, 0.0),
new Coord3D (1.0, 0.0, 0.0)
);
} else if (direction === OV.Direction.Y) {
return new OV.Camera (
new OV.Coord3D (-1.5, 2.0, 3.0),
new OV.Coord3D (0.0, 0.0, 0.0),
new OV.Coord3D (0.0, 1.0, 0.0)
} else if (direction === Direction.Y) {
return new Camera (
new Coord3D (-1.5, 2.0, 3.0),
new Coord3D (0.0, 0.0, 0.0),
new Coord3D (0.0, 1.0, 0.0)
);
} else if (direction === OV.Direction.Z) {
return new OV.Camera (
new OV.Coord3D (-1.5, -3.0, 2.0),
new OV.Coord3D (0.0, 0.0, 0.0),
new OV.Coord3D (0.0, 0.0, 1.0)
} else if (direction === Direction.Z) {
return new Camera (
new Coord3D (-1.5, -3.0, 2.0),
new Coord3D (0.0, 0.0, 0.0),
new Coord3D (0.0, 0.0, 1.0)
);
}
return null;
};
}
OV.TraverseThreeObject = function (object, processor)
export function TraverseThreeObject (object, processor)
{
if (!processor (object)) {
return false;
}
for (let child of object.children) {
if (!OV.TraverseThreeObject (child, processor)) {
if (!TraverseThreeObject (child, processor)) {
return false;
}
}
return true;
};
}
OV.GetShadingTypeOfObject = function (mainObject)
export function GetShadingTypeOfObject (mainObject)
{
let shadingType = null;
OV.TraverseThreeObject (mainObject, (obj) => {
TraverseThreeObject (mainObject, (obj) => {
if (obj.isMesh) {
for (const material of obj.material) {
if (material.type === 'MeshPhongMaterial') {
shadingType = OV.ShadingType.Phong;
shadingType = ShadingType.Phong;
} else if (material.type === 'MeshStandardMaterial') {
shadingType = OV.ShadingType.Physical;
shadingType = ShadingType.Physical;
}
return false;
}
@ -52,13 +60,13 @@ OV.GetShadingTypeOfObject = function (mainObject)
return true;
});
return shadingType;
};
}
OV.UpVector = class
export class UpVector
{
constructor ()
{
this.direction = OV.Direction.Z;
this.direction = Direction.Z;
this.isFixed = true;
this.isFlipped = false;
}
@ -68,21 +76,21 @@ OV.UpVector = class
this.direction = newDirection;
this.isFlipped = false;
let defaultCamera = OV.GetDefaultCamera (this.direction);
let defaultDir = OV.SubCoord3D (defaultCamera.eye, defaultCamera.center);
let defaultCamera = GetDefaultCamera (this.direction);
let defaultDir = SubCoord3D (defaultCamera.eye, defaultCamera.center);
let distance = OV.CoordDistance3D (oldCamera.center, oldCamera.eye);
let distance = CoordDistance3D (oldCamera.center, oldCamera.eye);
let newEye = oldCamera.center.Clone ().Offset (defaultDir, distance);
let newCamera = oldCamera.Clone ();
if (this.direction === OV.Direction.X) {
newCamera.up = new OV.Coord3D (1.0, 0.0, 0.0);
if (this.direction === Direction.X) {
newCamera.up = new Coord3D (1.0, 0.0, 0.0);
newCamera.eye = newEye;
} if (this.direction === OV.Direction.Y) {
newCamera.up = new OV.Coord3D (0.0, 1.0, 0.0);
} if (this.direction === Direction.Y) {
newCamera.up = new Coord3D (0.0, 1.0, 0.0);
newCamera.eye = newEye;
} else if (this.direction === OV.Direction.Z) {
newCamera.up = new OV.Coord3D (0.0, 0.0, 1.0);
} else if (this.direction === Direction.Z) {
newCamera.up = new Coord3D (0.0, 0.0, 1.0);
newCamera.eye = newEye;
}
return newCamera;
@ -104,15 +112,15 @@ OV.UpVector = class
newCamera.up.MultiplyScalar (-1.0);
return newCamera;
}
};
}
OV.ShadingModel = class
export class ShadingModel
{
constructor (scene)
{
this.scene = scene;
this.type = OV.ShadingType.Phong;
this.type = ShadingType.Phong;
this.ambientLight = new THREE.AmbientLight (0x888888);
this.directionalLight = new THREE.DirectionalLight (0x888888);
this.environment = null;
@ -124,11 +132,11 @@ OV.ShadingModel = class
SetType (type)
{
this.type = type;
if (this.type === OV.ShadingType.Phong) {
if (this.type === ShadingType.Phong) {
this.ambientLight.color.set (0x888888);
this.directionalLight.color.set (0x888888);
this.scene.environment = null;
} else if (this.type === OV.ShadingType.Physical) {
} else if (this.type === ShadingType.Physical) {
this.ambientLight.color.set (0x000000);
this.directionalLight.color.set (0x555555);
this.scene.environment = this.environment;
@ -145,19 +153,19 @@ OV.ShadingModel = class
UpdateByCamera (camera)
{
const lightDir = OV.SubCoord3D (camera.eye, camera.center);
const lightDir = SubCoord3D (camera.eye, camera.center);
this.directionalLight.position.set (lightDir.x, lightDir.y, lightDir.z);
}
CreateHighlightMaterial (highlightColor, withOffset)
{
let material = null;
if (this.type === OV.ShadingType.Phong) {
if (this.type === ShadingType.Phong) {
material = new THREE.MeshPhongMaterial ({
color : highlightColor,
side : THREE.DoubleSide
});
} else if (this.type === OV.ShadingType.Physical) {
} else if (this.type === ShadingType.Physical) {
material = new THREE.MeshStandardMaterial ({
color : highlightColor,
side : THREE.DoubleSide
@ -170,9 +178,9 @@ OV.ShadingModel = class
}
return material;
}
};
}
OV.Viewer = class
export class Viewer
{
constructor ()
{
@ -208,8 +216,8 @@ OV.Viewer = class
this.renderer.setSize (this.canvas.width, this.canvas.height);
this.scene = new THREE.Scene ();
this.geometry = new OV.ViewerGeometry (this.scene);
this.extraGeometry = new OV.ViewerExtraGeometry (this.scene);
this.geometry = new ViewerGeometry (this.scene);
this.extraGeometry = new ViewerExtraGeometry (this.scene);
this.InitNavigation ();
this.InitShading ();
@ -234,7 +242,7 @@ OV.Viewer = class
SetBackgroundColor (color)
{
let hexColor = '#' + OV.ColorToHexString (color);
let hexColor = '#' + ColorToHexString (color);
this.renderer.setClearColor (hexColor, 1.0);
this.Render ();
}
@ -276,7 +284,7 @@ OV.Viewer = class
Resize (width, height)
{
let innerSize = OV.GetDomElementInnerDimensions (this.canvas, width, height);
let innerSize = GetDomElementInnerDimensions (this.canvas, width, height);
this.ResizeRenderer (innerSize.width, innerSize.height);
}
@ -296,7 +304,7 @@ OV.Viewer = class
if (boundingSphere === null) {
return;
}
let center = new OV.Coord3D (boundingSphere.center.x, boundingSphere.center.y, boundingSphere.center.z);
let center = new Coord3D (boundingSphere.center.x, boundingSphere.center.y, boundingSphere.center.z);
let radius = boundingSphere.radius;
let fov = this.camera.fov;
@ -372,7 +380,7 @@ OV.Viewer = class
SetMainObject (object)
{
const shadingType = OV.GetShadingTypeOfObject (object);
const shadingType = GetShadingTypeOfObject (object);
this.geometry.SetMainObject (object);
this.shading.SetType (shadingType);
@ -493,20 +501,20 @@ OV.Viewer = class
this.scene.add (this.camera);
let canvasElem = this.renderer.domElement;
let camera = OV.GetDefaultCamera (OV.Direction.Z);
let camera = GetDefaultCamera (Direction.Z);
this.navigation = new OV.Navigation (canvasElem, camera, {
this.navigation = new Navigation (canvasElem, camera, {
onUpdate : () => {
this.Render ();
}
});
this.upVector = new OV.UpVector ();
this.upVector = new UpVector ();
}
InitShading ()
{
this.shading = new OV.ShadingModel (this.scene);
this.shading = new ShadingModel (this.scene);
}
GetImageSize ()
@ -548,4 +556,4 @@ OV.Viewer = class
this.ResizeRenderer (originalSize.width, originalSize.height);
return url;
}
};
}

View File

@ -1,4 +1,8 @@
OV.SetThreeMeshPolygonOffset = function (mesh, offset)
import { IsEqual } from '../geometry/geometry.js';
import { Color } from '../model/color.js';
import { ConvertColorToThreeColor } from '../threejs/threeutils.js';
export function SetThreeMeshPolygonOffset (mesh, offset)
{
function SetMaterialsPolygonOffset (materials, offset)
{
@ -13,9 +17,9 @@ OV.SetThreeMeshPolygonOffset = function (mesh, offset)
if (mesh.userData.threeMaterials) {
SetMaterialsPolygonOffset (mesh.userData.threeMaterials, offset);
}
};
}
OV.ViewerGeometry = class
export class ViewerGeometry
{
constructor (scene)
{
@ -30,7 +34,7 @@ OV.ViewerGeometry = class
};
this.edgeSettings = {
showEdges : false,
edgeColor : new OV.Color (0, 0, 0),
edgeColor : new Color (0, 0, 0),
edgeThreshold : 1
};
}
@ -91,7 +95,7 @@ OV.ViewerGeometry = class
this.GenerateMainEdgeObject ();
} else {
let edgeColor = OV.ConvertColorToThreeColor (this.edgeSettings.edgeColor);
let edgeColor = ConvertColorToThreeColor (this.edgeSettings.edgeColor);
this.EnumerateEdges ((edge) => {
edge.material.color = edgeColor;
});
@ -148,14 +152,14 @@ OV.ViewerGeometry = class
let lineDist = alignedMinValue.x + step * cellSize;
let beg = new THREE.Vector3 (alignedMinValue.y, level, lineDist);
let end = new THREE.Vector3 (alignedMaxValue.y, level, lineDist);
let material = OV.IsEqual (lineDist, 0.0) ? strongMaterial : lightMaterial;
let material = IsEqual (lineDist, 0.0) ? strongMaterial : lightMaterial;
this.mainGridObject.add (CreateLine (beg, end, material));
}
for (let step = 0; step < cellCountY + 1; step++) {
let lineDist = alignedMinValue.y + step * cellSize;
let beg = new THREE.Vector3 (lineDist, level, alignedMinValue.x);
let end = new THREE.Vector3 (lineDist, level, alignedMaxValue.x);
let material = OV.IsEqual (lineDist, 0.0) ? strongMaterial : lightMaterial;
let material = IsEqual (lineDist, 0.0) ? strongMaterial : lightMaterial;
this.mainGridObject.add (CreateLine (beg, end, material));
}
this.scene.add (this.mainGridObject);
@ -164,12 +168,12 @@ OV.ViewerGeometry = class
GenerateMainEdgeObject ()
{
let edgeColor = OV.ConvertColorToThreeColor (this.edgeSettings.edgeColor);
let edgeColor = ConvertColorToThreeColor (this.edgeSettings.edgeColor);
this.mainEdgeObject = new THREE.Object3D ();
this.UpdateWorldMatrix ();
this.EnumerateMeshes ((mesh) => {
OV.SetThreeMeshPolygonOffset (mesh, true);
SetThreeMeshPolygonOffset (mesh, true);
let edges = new THREE.EdgesGeometry (mesh.geometry, this.edgeSettings.edgeThreshold);
let line = new THREE.LineSegments (edges, new THREE.LineBasicMaterial ({
color: edgeColor
@ -252,7 +256,7 @@ OV.ViewerGeometry = class
}
this.EnumerateMeshes ((mesh) => {
OV.SetThreeMeshPolygonOffset (mesh, false);
SetThreeMeshPolygonOffset (mesh, false);
});
this.EnumerateEdges ((edge) => {
edge.geometry.dispose ();
@ -306,9 +310,9 @@ OV.ViewerGeometry = class
return null;
}
};
}
OV.ViewerExtraGeometry = class
export class ViewerExtraGeometry
{
constructor (scene)
{
@ -338,4 +342,4 @@ OV.ViewerExtraGeometry = class
this.scene.remove (this.mainObject);
this.mainObject = null;
}
};
}

View File

@ -1,33 +0,0 @@
OV.Coord2D = class
{
constructor (x, y)
{
this.x = x;
this.y = y;
}
Clone ()
{
return new OV.Coord2D (this.x, this.y);
}
};
OV.CoordIsEqual2D = function (a, b)
{
return OV.IsEqual (a.x, b.x) && OV.IsEqual (a.y, b.y);
};
OV.AddCoord2D = function (a, b)
{
return new OV.Coord2D (a.x + b.x, a.y + b.y);
};
OV.SubCoord2D = function (a, b)
{
return new OV.Coord2D (a.x - b.x, a.y - b.y);
};
OV.CoordDistance2D = function (a, b)
{
return Math.sqrt ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
};

View File

@ -1,56 +0,0 @@
OV.Eps = 0.00000001;
OV.BigEps = 0.0001;
OV.RadDeg = 57.29577951308232;
OV.DegRad = 0.017453292519943;
OV.IsZero = function (a)
{
return Math.abs (a) < OV.Eps;
};
OV.IsLower = function (a, b)
{
return b - a > OV.Eps;
};
OV.IsGreater = function (a, b)
{
return a - b > OV.Eps;
};
OV.IsLowerOrEqual = function (a, b)
{
return b - a > -OV.Eps;
};
OV.IsGreaterOrEqual = function (a, b)
{
return a - b > -OV.Eps;
};
OV.IsEqual = function (a, b)
{
return Math.abs (b - a) < OV.Eps;
};
OV.IsEqualEps = function (a, b, eps)
{
return Math.abs (b - a) < eps;
};
OV.IsPositive = function (a)
{
return a > OV.Eps;
};
OV.IsNegative = function (a)
{
return a < -OV.Eps;
};
OV.Direction =
{
X : 1,
Y : 2,
Z : 3
};

View File

@ -1,35 +0,0 @@
OV.GetTriangleArea = function (v0, v1, v2)
{
const a = OV.CoordDistance3D (v0, v1);
const b = OV.CoordDistance3D (v1, v2);
const c = OV.CoordDistance3D (v0, v2);
const s = (a + b + c) / 2.0;
const areaSquare = s * (s - a) * (s - b) * (s - c);
if (areaSquare < 0.0) {
return 0.0;
}
return Math.sqrt (areaSquare);
};
OV.GetTetrahedronSignedVolume = function (v0, v1, v2)
{
return OV.DotVector3D (v0, OV.CrossVector3D (v1, v2)) / 6.0;
};
OV.CalculateVolume = function (object3D)
{
let volume = 0.0;
object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
volume += OV.GetTetrahedronSignedVolume (v0, v1, v2);
});
return volume;
};
OV.CalculateSurfaceArea = function (object3D)
{
let surface = 0.0;
object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
surface += OV.GetTriangleArea (v0, v1, v2);
});
return surface;
};

View File

@ -1,238 +0,0 @@
OV.GetIntegerFromStyle = function (parameter)
{
return Math.round (parseFloat (parameter));
};
OV.GetDomElementExternalWidth = function (style)
{
let padding = OV.GetIntegerFromStyle (style.paddingLeft) + OV.GetIntegerFromStyle (style.paddingRight);
let border = OV.GetIntegerFromStyle (style.borderLeftWidth) + OV.GetIntegerFromStyle (style.borderRightWidth);
let margin = OV.GetIntegerFromStyle (style.marginLeft) + OV.GetIntegerFromStyle (style.marginRight);
return padding + border + margin;
};
OV.GetDomElementExternalHeight = function (style)
{
let padding = OV.GetIntegerFromStyle (style.paddingTop) + OV.GetIntegerFromStyle (style.paddingBottom);
let border = OV.GetIntegerFromStyle (style.borderTopWidth) + OV.GetIntegerFromStyle (style.borderBottomWidth);
let margin = OV.GetIntegerFromStyle (style.marginTop) + OV.GetIntegerFromStyle (style.marginBottom);
return padding + border + margin;
};
OV.GetDomElementInnerDimensions = function (element, outerWidth, outerHeight)
{
let style = getComputedStyle (element);
let width = outerWidth - OV.GetDomElementExternalWidth (style);
let height = outerHeight - OV.GetDomElementExternalHeight (style);
return {
width : width,
height : height
};
};
OV.GetDomElementClientCoordinates = function (element, clientX, clientY)
{
if (element.getBoundingClientRect) {
let clientRect = element.getBoundingClientRect ();
clientX -= clientRect.left;
clientY -= clientRect.top;
}
if (window.pageXOffset && window.pageYOffset) {
clientX += window.pageXOffset;
clientY += window.pageYOffset;
}
return (new OV.Coord2D (clientX, clientY));
};
OV.CreateDomElement = function (elementType, className, innerHTML)
{
let element = document.createElement (elementType);
if (className) {
element.className = className;
}
if (innerHTML) {
element.innerHTML = innerHTML;
}
return element;
};
OV.AddDomElement = function (parentElement, elementType, className, innerHTML)
{
let element = OV.CreateDomElement (elementType, className, innerHTML);
parentElement.appendChild (element);
return element;
};
OV.ClearDomElement = function (element)
{
while (element.firstChild) {
element.removeChild (element.firstChild);
}
};
OV.InsertDomElementBefore = function (newElement, existingElement)
{
existingElement.parentNode.insertBefore (newElement, existingElement);
};
OV.InsertDomElementAfter = function (newElement, existingElement)
{
existingElement.parentNode.insertBefore (newElement, existingElement.nextSibling);
};
OV.ShowDomElement = function (element, show)
{
if (show) {
element.style.display = 'block';
} else {
element.style.display = 'none';
}
};
OV.IsDomElementVisible = function (element)
{
return element.offsetParent !== null;
};
OV.SetDomElementWidth = function (element, width)
{
element.style.width = width.toString () + 'px';
};
OV.SetDomElementHeight = function (element, height)
{
element.style.height = height.toString () + 'px';
};
OV.GetDomElementOuterWidth = function (element)
{
let style = getComputedStyle (element);
return element.offsetWidth + OV.GetIntegerFromStyle (style.marginLeft) + OV.GetIntegerFromStyle (style.marginRight);
};
OV.GetDomElementOuterHeight = function (element)
{
let style = getComputedStyle (element);
return element.offsetHeight + OV.GetIntegerFromStyle (style.marginTop) + OV.GetIntegerFromStyle (style.marginBottom);
};
OV.SetDomElementOuterWidth = function (element, width)
{
let style = getComputedStyle (element);
OV.SetDomElementWidth (element, width - OV.GetDomElementExternalWidth (style));
};
OV.SetDomElementOuterHeight = function (element, height)
{
let style = getComputedStyle (element);
OV.SetDomElementHeight (element, height - OV.GetDomElementExternalHeight (style));
};
OV.AddRadioButton = function (parentElement, name, id, text, onChange)
{
let label = OV.AddDomElement (parentElement, 'label');
label.setAttribute ('for', id);
let radio = OV.AddDomElement (label, 'input', 'ov_radio_button');
radio.setAttribute ('type', 'radio');
radio.setAttribute ('id', id);
radio.setAttribute ('name', name);
OV.AddDomElement (label, 'span', null, text);
if (onChange) {
radio.addEventListener ('change', onChange);
}
return radio;
};
OV.AddCheckbox = function (parentElement, id, text, isChecked, onChange)
{
let label = OV.AddDomElement (parentElement, 'label');
label.setAttribute ('for', id);
let check = OV.AddDomElement (label, 'input', 'ov_checkbox');
check.setAttribute ('type', 'checkbox');
check.setAttribute ('id', id);
check.checked = isChecked;
OV.AddDomElement (label, 'span', null, text);
if (onChange) {
check.addEventListener ('change', onChange);
}
return check;
};
OV.AddRangeSlider = function (parentElement, min, max)
{
let slider = OV.AddDomElement (parentElement, 'input', 'ov_slider');
slider.setAttribute ('type', 'range');
slider.setAttribute ('min', min.toString ());
slider.setAttribute ('max', max.toString ());
return slider;
};
OV.AddSelect = function (parentElement, options, selectedIndex, onChange)
{
let container = OV.AddDiv (parentElement, 'ov_select_container');
let select = OV.AddDomElement (container, 'select', 'ov_select');
for (let option of options) {
OV.AddDomElement (select, 'option', null, option);
}
select.selectedIndex = selectedIndex;
if (onChange) {
select.addEventListener ('change', () => {
onChange (select.selectedIndex);
});
}
return select;
};
OV.AddToggle = function (parentElement, className)
{
function UpdateStatus (toggle, status)
{
if (status) {
toggle.classList.add ('on');
} else {
toggle.classList.remove ('on');
}
}
let status = false;
let onChange = null;
let toggleClassName = 'ov_toggle';
if (className) {
toggleClassName += ' ' + className;
}
let toggle = OV.AddDiv (parentElement, toggleClassName);
OV.AddDiv (toggle, 'ov_toggle_slider');
toggle.addEventListener ('click', () => {
status = !status;
UpdateStatus (toggle, status);
if (onChange) {
onChange ();
}
});
return {
element : toggle,
GetStatus : () => {
return status;
},
SetStatus : (newStatus) => {
status = newStatus;
UpdateStatus (toggle, status);
},
OnChange : (onChangeHandler) => {
onChange = onChangeHandler;
}
};
};
OV.CreateDiv = function (className, innerHTML)
{
return OV.CreateDomElement ('div', className, innerHTML);
};
OV.AddDiv = function (parentElement, className, innerHTML)
{
return OV.AddDomElement (parentElement, 'div', className, innerHTML);
};

View File

@ -1,4 +1,6 @@
OV.CookieHandler = class
import { ParameterConverter } from '../engine/parameters/parameterlist.js';
export class CookieHandler
{
constructor ()
{
@ -42,7 +44,7 @@ OV.CookieHandler = class
SetBoolVal (key, value)
{
this.SetStringVal (key, value ? 'true' : 'false');
}
}
GetIntVal (key, defVal)
{
@ -64,11 +66,11 @@ OV.CookieHandler = class
if (stringVal === null) {
return defVal;
}
return OV.ParameterConverter.StringToColor (stringVal);
return ParameterConverter.StringToColor (stringVal);
}
SetColorVal (key, value)
{
this.SetStringVal (key, OV.ParameterConverter.ColorToString (value));
}
};
this.SetStringVal (key, ParameterConverter.ColorToString (value));
}
}

View File

@ -1,6 +1,9 @@
OV.ShowMessageDialog = function (title, message, subMessage)
import { AddDiv } from '../engine/viewer/domutils.js';
import { ButtonDialog, ListPopup } from './modal.js';
export function ShowMessageDialog (title, message, subMessage)
{
let dialog = new OV.ButtonDialog ();
let dialog = new ButtonDialog ();
let contentDiv = dialog.Init (title, [
{
name : 'OK',
@ -9,21 +12,21 @@ OV.ShowMessageDialog = function (title, message, subMessage)
}
}
]);
OV.AddDiv (contentDiv, 'ov_dialog_message', message);
AddDiv (contentDiv, 'ov_dialog_message', message);
if (subMessage !== null) {
OV.AddDiv (contentDiv, 'ov_dialog_submessage', subMessage);
AddDiv (contentDiv, 'ov_dialog_submessage', subMessage);
}
dialog.Show ();
return dialog;
};
}
OV.ShowListPopup = function (items, callbacks)
export function ShowListPopup (items, callbacks)
{
if (items.length === 0) {
return null;
}
let popup = new OV.ListPopup ();
let popup = new ListPopup ();
popup.Init (() => {
return callbacks.calculatePosition (popup.GetContentDiv ());
});
@ -48,18 +51,18 @@ OV.ShowListPopup = function (items, callbacks)
}
popup.Show ();
return popup;
};
}
OV.CalculatePopupPositionToElementBottomRight = function (elementDiv, contentDiv)
export function CalculatePopupPositionToElementBottomRight (elementDiv, contentDiv)
{
let offset = elementDiv.getBoundingClientRect ();
return {
x : offset.left + elementDiv.offsetWidth,
y : offset.top + elementDiv.offsetHeight - contentDiv.offsetHeight
};
};
}
OV.CalculatePopupPositionToScreen = function (globalMouseCoordinates, contentDiv)
export function CalculatePopupPositionToScreen (globalMouseCoordinates, contentDiv)
{
let windowWidth = window.innerWidth;
let windowHeight = window.innerHeight;
@ -77,4 +80,4 @@ OV.CalculatePopupPositionToScreen = function (globalMouseCoordinates, contentDiv
x : left,
y : top
};
};
}

View File

@ -1,16 +1,24 @@
OV.Embed = class
import { CreateModelUrlParameters } from '../engine/parameters/parameterlist.js';
import { FileSource, TransformFileHostUrls } from '../engine/io/fileutils.js';
import { ImportSettings } from '../engine/import/importer.js';
import { AddDomElement } from '../engine/viewer/domutils.js';
import { Viewer } from '../engine/viewer/viewer.js';
import { HashHandler } from './hashhandler.js';
import { ThreeModelLoaderUI } from './threemodelloaderui.js';
export class Embed
{
constructor (parameters)
{
this.parameters = parameters;
this.viewer = new OV.Viewer ();
this.hashHandler = new OV.HashHandler ();
this.modelLoaderUI = new OV.ThreeModelLoaderUI ();
this.viewer = new Viewer ();
this.hashHandler = new HashHandler ();
this.modelLoaderUI = new ThreeModelLoaderUI ();
}
Load ()
{
let canvas = OV.AddDomElement (this.parameters.viewerDiv, 'canvas');
let canvas = AddDomElement (this.parameters.viewerDiv, 'canvas');
this.InitViewer (canvas);
this.Resize ();
@ -19,7 +27,7 @@ OV.Embed = class
if (urls === null) {
return;
}
OV.TransformFileHostUrls (urls);
TransformFileHostUrls (urls);
let background = this.hashHandler.GetBackgroundFromHash ();
if (background !== null) {
this.viewer.SetBackgroundColor (background);
@ -32,12 +40,12 @@ OV.Embed = class
edgeSettings.edgeThreshold
);
}
let settings = new OV.ImportSettings ();
let settings = new ImportSettings ();
let defaultColor = this.hashHandler.GetDefaultColorFromHash ();
if (defaultColor !== null) {
settings.defaultColor = defaultColor;
}
this.modelLoaderUI.LoadModel (urls, OV.FileSource.Url, settings, {
this.modelLoaderUI.LoadModel (urls, FileSource.Url, settings, {
onStart : () =>
{
@ -55,7 +63,7 @@ OV.Embed = class
}
});
let hashParameters = OV.CreateModelUrlParameters (urls);
let hashParameters = CreateModelUrlParameters (urls);
let websiteUrl = this.parameters.websiteLinkDiv.getAttribute ('href') + '#' + hashParameters;
this.parameters.websiteLinkDiv.setAttribute ('href', websiteUrl);
}
@ -100,4 +108,4 @@ OV.Embed = class
'assets/envmaps/grayclouds/negz.jpg'
]);
}
};
}

View File

@ -1,4 +1,4 @@
OV.EventHandler = class
export class EventHandler
{
constructor (eventHandler)
{
@ -12,4 +12,4 @@ OV.EventHandler = class
}
this.eventHandler (eventName, eventData);
}
};
}

View File

@ -1,10 +1,22 @@
OV.ExportType =
import { RunTaskAsync } from '../engine/core/taskrunner.js';
import { Coord3D } from '../engine/geometry/coord3d.js';
import { Matrix } from '../engine/geometry/matrix.js';
import { FileFormat } from '../engine/io/fileutils.js';
import { LoadExternalLibrary } from '../engine/io/externallibs.js';
import { Exporter } from '../engine/export/exporter.js';
import { ExporterModel, ExporterSettings } from '../engine/export/exportermodel.js';
import { AddDiv, AddSelect, ClearDomElement } from '../engine/viewer/domutils.js';
import { ShowMessageDialog } from './dialogs.js';
import { ButtonDialog, ProgressDialog } from './modal.js';
import { DownloadArrayBufferAsFile, DownloadUrlAsFile } from './utils.js';
export const ExportType =
{
Model : 0,
Image : 1
};
OV.ExporterUI = class
export class ExporterUI
{
constructor (name)
{
@ -26,22 +38,16 @@ OV.ExporterUI = class
}
AddCheckbox (parentDiv, id, name, isChecked)
AddSelectItem (parametersDiv, name, values, defaultIndex)
{
let line = OV.AddDiv (parentDiv, 'ov_dialog_row');
return OV.AddCheckbox (line, id, name, isChecked);
let parameterRow = AddDiv (parametersDiv, 'ov_dialog_row');
AddDiv (parameterRow, 'ov_dialog_row_name', name);
let parameterValueDiv = AddDiv (parameterRow, 'ov_dialog_row_value');
return AddSelect (parameterValueDiv, values, defaultIndex);
}
}
AddSelect (parametersDiv, name, values, defaultIndex)
{
let parameterRow = OV.AddDiv (parametersDiv, 'ov_dialog_row');
OV.AddDiv (parameterRow, 'ov_dialog_row_name', name);
let parameterValueDiv = OV.AddDiv (parameterRow, 'ov_dialog_row_value');
return OV.AddSelect (parameterValueDiv, values, defaultIndex);
}
};
OV.ModelExporterUI = class extends OV.ExporterUI
export class ModelExporterUI extends ExporterUI
{
constructor (name, format, extension)
{
@ -54,18 +60,18 @@ OV.ModelExporterUI = class extends OV.ExporterUI
GetType ()
{
return OV.ExportType.Model;
return ExportType.Model;
}
GenerateParametersUI (parametersDiv)
{
this.visibleOnlySelect = this.AddSelect (parametersDiv, 'Scope', ['Entire Model', 'Visible Only'], 1);
this.rotationSelect = this.AddSelect (parametersDiv, 'Rotation', ['No Rotation', '-90 Degrees', '90 Degrees'], 0);
this.visibleOnlySelect = this.AddSelectItem (parametersDiv, 'Scope', ['Entire Model', 'Visible Only'], 1);
this.rotationSelect = this.AddSelectItem (parametersDiv, 'Rotation', ['No Rotation', '-90 Degrees', '90 Degrees'], 0);
}
ExportModel (model, callbacks)
{
let settings = new OV.ExporterSettings ();
let settings = new ExporterSettings ();
if (this.visibleOnlySelect.selectedIndex === 1) {
settings.isMeshVisible = (meshInstanceId) => {
return callbacks.isMeshVisible (meshInstanceId);
@ -73,16 +79,16 @@ OV.ModelExporterUI = class extends OV.ExporterUI
}
if (this.rotationSelect.selectedIndex === 1) {
let matrix = new OV.Matrix ().CreateRotationAxisAngle (new OV.Coord3D (1.0, 0.0, 0.0), -Math.PI / 2.0);
let matrix = new Matrix ().CreateRotationAxisAngle (new Coord3D (1.0, 0.0, 0.0), -Math.PI / 2.0);
settings.transformation.SetMatrix (matrix);
} else if (this.rotationSelect.selectedIndex === 2) {
let matrix = new OV.Matrix ().CreateRotationAxisAngle (new OV.Coord3D (1.0, 0.0, 0.0), Math.PI / 2.0);
let matrix = new Matrix ().CreateRotationAxisAngle (new Coord3D (1.0, 0.0, 0.0), Math.PI / 2.0);
settings.transformation.SetMatrix (matrix);
}
let exporterModel = new OV.ExporterModel (model, settings);
let exporterModel = new ExporterModel (model, settings);
if (exporterModel.MeshInstanceCount () === 0) {
let errorDialog = OV.ShowMessageDialog (
let errorDialog = ShowMessageDialog (
'Export Failed',
'The model doesn\'t contain any meshes.',
null
@ -91,12 +97,12 @@ OV.ModelExporterUI = class extends OV.ExporterUI
return;
}
let progressDialog = new OV.ProgressDialog ();
let progressDialog = new ProgressDialog ();
progressDialog.Init ('Exporting Model');
progressDialog.Show ();
OV.RunTaskAsync (() => {
let exporter = new OV.Exporter ();
RunTaskAsync (() => {
let exporter = new Exporter ();
exporter.Export (model, settings, this.format, this.extension, {
onError : () => {
progressDialog.Hide ();
@ -107,9 +113,9 @@ OV.ModelExporterUI = class extends OV.ExporterUI
} else if (files.length === 1) {
progressDialog.Hide ();
let file = files[0];
OV.DownloadArrayBufferAsFile (file.GetBufferContent (), file.GetName ());
DownloadArrayBufferAsFile (file.GetBufferContent (), file.GetName ());
} else if (files.length > 1) {
OV.LoadExternalLibrary ('loaders/fflate.min.js').then (() => {
LoadExternalLibrary ('loaders/fflate.min.js').then (() => {
let filesInZip = {};
for (let file of files) {
filesInZip[file.name] = new Uint8Array (file.content);
@ -117,7 +123,7 @@ OV.ModelExporterUI = class extends OV.ExporterUI
let zippedContent = fflate.zipSync (filesInZip);
let zippedBuffer = zippedContent.buffer;
progressDialog.Hide ();
OV.DownloadArrayBufferAsFile (zippedBuffer, 'model.zip');
DownloadArrayBufferAsFile (zippedBuffer, 'model.zip');
}).catch (() => {
progressDialog.Hide ();
});
@ -126,9 +132,9 @@ OV.ModelExporterUI = class extends OV.ExporterUI
});
});
}
};
}
OV.ImageExporterUI = class extends OV.ExporterUI
export class ImageExporterUI extends ExporterUI
{
constructor (name, extension)
{
@ -144,13 +150,13 @@ OV.ImageExporterUI = class extends OV.ExporterUI
GetType ()
{
return OV.ExportType.Image;
return ExportType.Image;
}
GenerateParametersUI (parametersDiv)
{
let sizeNames = this.sizes.map (size => size.name);
this.sizeSelect = this.AddSelect (parametersDiv, 'Image size', sizeNames, 1);
this.sizeSelect = this.AddSelectItem (parametersDiv, 'Image size', sizeNames, 1);
}
ExportImage (viewer)
@ -163,11 +169,11 @@ OV.ImageExporterUI = class extends OV.ExporterUI
} else {
url = viewer.GetImageAsDataUrl (selectedSize.value[0], selectedSize.value[1]);
}
OV.DownloadUrlAsFile (url, 'model.' + this.extension);
DownloadUrlAsFile (url, 'model.' + this.extension);
}
};
}
OV.ExportDialog = class
export class ExportDialog
{
constructor (callbacks, eventHandler)
{
@ -177,22 +183,22 @@ OV.ExportDialog = class
this.parametersDiv = null;
this.exporters = [
new OV.ModelExporterUI ('Wavefront (.obj)', OV.FileFormat.Text, 'obj'),
new OV.ModelExporterUI ('Stereolithography Text (.stl)', OV.FileFormat.Text, 'stl'),
new OV.ModelExporterUI ('Stereolithography Binary (.stl)', OV.FileFormat.Binary, 'stl'),
new OV.ModelExporterUI ('Polygon File Format Text (.ply)', OV.FileFormat.Text, 'ply'),
new OV.ModelExporterUI ('Polygon File Format Binary (.ply)', OV.FileFormat.Binary, 'ply'),
new OV.ModelExporterUI ('glTF Text (.gltf)', OV.FileFormat.Text, 'gltf'),
new OV.ModelExporterUI ('glTF Binary (.glb)', OV.FileFormat.Binary, 'glb'),
new OV.ModelExporterUI ('Object File Format Text (.off)', OV.FileFormat.Text, 'off'),
new OV.ModelExporterUI ('Rhinoceros 3D (.3dm)', OV.FileFormat.Binary, '3dm'),
new OV.ImageExporterUI ('PNG Image (.png)', 'png')
new ModelExporterUI ('Wavefront (.obj)', FileFormat.Text, 'obj'),
new ModelExporterUI ('Stereolithography Text (.stl)', FileFormat.Text, 'stl'),
new ModelExporterUI ('Stereolithography Binary (.stl)', FileFormat.Binary, 'stl'),
new ModelExporterUI ('Polygon File Format Text (.ply)', FileFormat.Text, 'ply'),
new ModelExporterUI ('Polygon File Format Binary (.ply)', FileFormat.Binary, 'ply'),
new ModelExporterUI ('glTF Text (.gltf)', FileFormat.Text, 'gltf'),
new ModelExporterUI ('glTF Binary (.glb)', FileFormat.Binary, 'glb'),
new ModelExporterUI ('Object File Format Text (.off)', FileFormat.Text, 'off'),
new ModelExporterUI ('Rhinoceros 3D (.3dm)', FileFormat.Binary, '3dm'),
new ImageExporterUI ('PNG Image (.png)', 'png')
];
}
Show (model, viewer)
{
let mainDialog = new OV.ButtonDialog ();
let mainDialog = new ButtonDialog ();
let contentDiv = mainDialog.Init ('Export', [
{
name : 'Close',
@ -211,13 +217,13 @@ OV.ExportDialog = class
]);
let text = 'Select the format from the list below, and adjust the settings of the selected format.';
OV.AddDiv (contentDiv, 'ov_dialog_section', text);
AddDiv (contentDiv, 'ov_dialog_section', text);
let formatRow = OV.AddDiv (contentDiv, 'ov_dialog_row');
this.parametersDiv = OV.AddDiv (contentDiv);
let formatRow = AddDiv (contentDiv, 'ov_dialog_row');
this.parametersDiv = AddDiv (contentDiv);
let formatNames = this.exporters.map (exporter => exporter.GetName ());
let defaultFormatIndex = 6;
OV.AddSelect (formatRow, formatNames, defaultFormatIndex, (selectedIndex) => {
AddSelect (formatRow, formatNames, defaultFormatIndex, (selectedIndex) => {
this.OnFormatSelected (selectedIndex);
});
this.OnFormatSelected (defaultFormatIndex);
@ -228,14 +234,14 @@ OV.ExportDialog = class
OnFormatSelected (selectedIndex)
{
OV.ClearDomElement (this.parametersDiv);
ClearDomElement (this.parametersDiv);
this.selectedExporter = this.exporters[selectedIndex];
this.selectedExporter.GenerateParametersUI (this.parametersDiv);
}
ExportFormat (model, viewer)
{
if (this.selectedExporter.GetType () === OV.ExportType.Model) {
if (this.selectedExporter.GetType () === ExportType.Model) {
this.selectedExporter.ExportModel (model, {
isMeshVisible : (meshInstanceId) => {
return this.callbacks.isMeshVisible (meshInstanceId);
@ -245,8 +251,8 @@ OV.ExportDialog = class
}
});
this.eventHandler.HandleEvent ('model_exported', this.selectedExporter.GetName ());
} else if (this.selectedExporter.GetType () === OV.ExportType.Image) {
} else if (this.selectedExporter.GetType () === ExportType.Image) {
this.selectedExporter.ExportImage (viewer);
}
}
};
}

View File

@ -1,4 +1,4 @@
OV.FeatureSet =
export const FeatureSet =
{
ShowGrid : false,
MeasureTool : false

View File

@ -1,4 +1,6 @@
OV.HashHandler = class
import { CreateModelUrlParameters, CreateUrlParser } from '../engine/parameters/parameterlist.js';
export class HashHandler
{
constructor ()
{
@ -30,37 +32,37 @@ OV.HashHandler = class
GetModelFilesFromHash ()
{
let parser = OV.CreateUrlParser (this.GetHash ());
let parser = CreateUrlParser (this.GetHash ());
return parser.GetModelUrls ();
}
SetModelFilesToHash (files)
{
let params = OV.CreateModelUrlParameters (files);
let params = CreateModelUrlParameters (files);
this.SetHash (params);
}
GetCameraFromHash ()
{
let parser = OV.CreateUrlParser (this.GetHash ());
let parser = CreateUrlParser (this.GetHash ());
return parser.GetCamera ();
}
GetBackgroundFromHash ()
{
let parser = OV.CreateUrlParser (this.GetHash ());
let parser = CreateUrlParser (this.GetHash ());
return parser.GetBackgroundColor ();
}
GetDefaultColorFromHash ()
{
let parser = OV.CreateUrlParser (this.GetHash ());
let parser = CreateUrlParser (this.GetHash ());
return parser.GetDefaultColor ();
}
GetEdgeSettingsFromHash ()
{
let parser = OV.CreateUrlParser (this.GetHash ());
let parser = CreateUrlParser (this.GetHash ());
return parser.GetEdgeSettings ();
}
@ -82,4 +84,4 @@ OV.HashHandler = class
}
this.eventListener ();
}
};
}

51
source/website/index.js Normal file
View File

@ -0,0 +1,51 @@
import { SetExternalLibLocation } from '../engine/io/externallibs.js';
import { CreateDomElement } from '../engine/viewer/domutils.js';
import { AddSvgIconElement, InstallTooltip } from './utils.js';
import { Embed } from './embed.js';
import { Website } from './website.js';
export function StartWebsite (externalLibLocation)
{
SetExternalLibLocation (externalLibLocation);
window.addEventListener ('load', () => {
let website = new Website ({
headerDiv : document.getElementById ('header'),
toolbarDiv : document.getElementById ('toolbar'),
mainDiv : document.getElementById ('main'),
introDiv : document.getElementById ('intro'),
fileNameDiv : document.getElementById ('main_file_name'),
navigatorDiv : document.getElementById ('main_navigator'),
navigatorSplitterDiv : document.getElementById ('main_navigator_splitter'),
sidebarDiv : document.getElementById ('main_sidebar'),
sidebarSplitterDiv : document.getElementById ('main_sidebar_splitter'),
viewerDiv : document.getElementById ('main_viewer'),
fileInput : document.getElementById ('open_file'),
eventHandler : window.viewerEventHandler
});
website.Load ();
});
}
export function StartEmbed (externalLibLocation)
{
SetExternalLibLocation (externalLibLocation);
window.addEventListener ('load', () => {
let embed = new Embed ({
viewerDiv : document.getElementById ('embed_viewer'),
websiteLinkDiv : document.getElementById ('website_link')
});
embed.Load ();
});
}
export function CreateHeaderButton (parentElement, iconName, title, link)
{
let buttonLink = CreateDomElement ('a');
buttonLink.setAttribute ('href', link);
buttonLink.setAttribute ('target', '_blank');
buttonLink.setAttribute ('rel', 'noopener noreferrer');
InstallTooltip (buttonLink, title);
AddSvgIconElement (buttonLink, iconName, 'header_button');
parentElement.appendChild (buttonLink);
return buttonLink;
}

View File

@ -1,8 +1,11 @@
OV.Modal = class
import { AddDiv, CreateDiv } from '../engine/viewer/domutils.js';
import { AddSvgIconElement, CreateInlineColorCircle, IsHoverEnabled } from './utils.js';
export class Modal
{
constructor ()
{
this.modalDiv = OV.CreateDiv ('ov_modal');
this.modalDiv = CreateDiv ('ov_modal');
this.overlayDiv = null;
this.resizeHandler = null;
this.positionCalculator = null;
@ -33,7 +36,7 @@ OV.Modal = class
Open ()
{
this.overlayDiv = OV.AddDiv (document.body, 'ov_modal_overlay');
this.overlayDiv = AddDiv (document.body, 'ov_modal_overlay');
document.body.appendChild (this.modalDiv);
this.resizeHandler = this.Resize.bind (this);
@ -91,13 +94,13 @@ OV.Modal = class
this.modalDiv.style.left = positionX + 'px';
this.modalDiv.style.top = positionY + 'px';
}
};
}
OV.Dialog = class
export class Dialog
{
constructor ()
{
this.modal = new OV.Modal ();
this.modal = new Modal ();
}
GetContentDiv ()
@ -129,9 +132,9 @@ OV.Dialog = class
{
this.modal.Close ();
}
};
}
OV.ProgressDialog = class extends OV.Dialog
export class ProgressDialog extends Dialog
{
constructor ()
{
@ -145,8 +148,8 @@ OV.ProgressDialog = class extends OV.Dialog
let contentDiv = this.modal.GetContentDiv ();
contentDiv.classList.add ('ov_progress');
OV.AddDiv (contentDiv, 'ov_progress_img', '<svg><use href="assets/images/3dviewer_net_logo.svg#logo"></use></svg>');
this.textDiv = OV.AddDiv (contentDiv, 'ov_progress_text');
AddDiv (contentDiv, 'ov_progress_img', '<svg><use href="assets/images/3dviewer_net_logo.svg#logo"></use></svg>');
this.textDiv = AddDiv (contentDiv, 'ov_progress_text');
this.SetText (text);
}
@ -154,9 +157,9 @@ OV.ProgressDialog = class extends OV.Dialog
{
this.textDiv.innerHTML = text;
}
};
}
OV.ButtonDialog = class extends OV.Dialog
export class ButtonDialog extends Dialog
{
constructor ()
{
@ -167,7 +170,7 @@ OV.ButtonDialog = class extends OV.Dialog
{
function AddButton (button, buttonsDiv)
{
let buttonDiv = OV.AddDiv (buttonsDiv, 'ov_button ov_dialog_button', button.name);
let buttonDiv = AddDiv (buttonsDiv, 'ov_button ov_dialog_button', button.name);
if (button.subClass) {
buttonDiv.classList.add (button.subClass);
}
@ -179,19 +182,19 @@ OV.ButtonDialog = class extends OV.Dialog
let contentDiv = this.modal.GetContentDiv ();
contentDiv.classList.add ('ov_dialog');
OV.AddDiv (contentDiv, 'ov_dialog_title', title);
let dialogContentDiv = OV.AddDiv (contentDiv, 'ov_dialog_content');
let buttonsDiv = OV.AddDiv (contentDiv, 'ov_dialog_buttons');
let buttonsInnerDiv = OV.AddDiv (buttonsDiv, 'ov_dialog_buttons_inner');
AddDiv (contentDiv, 'ov_dialog_title', title);
let dialogContentDiv = AddDiv (contentDiv, 'ov_dialog_content');
let buttonsDiv = AddDiv (contentDiv, 'ov_dialog_buttons');
let buttonsInnerDiv = AddDiv (buttonsDiv, 'ov_dialog_buttons_inner');
for (let i = 0; i < buttons.length; i++) {
AddButton (buttons[i], buttonsInnerDiv);
}
return dialogContentDiv;
}
};
}
OV.PopupDialog = class extends OV.Dialog
export class PopupDialog extends Dialog
{
constructor ()
{
@ -205,9 +208,9 @@ OV.PopupDialog = class extends OV.Dialog
this.modal.SetPositionCalculator (positionCalculator);
return contentDiv;
}
};
}
OV.ListPopup = class extends OV.PopupDialog
export class ListPopup extends PopupDialog
{
constructor ()
{
@ -218,24 +221,24 @@ OV.ListPopup = class extends OV.PopupDialog
Init (positionCalculator)
{
let contentDiv = super.Init (positionCalculator);
this.listDiv = OV.AddDiv (contentDiv, 'ov_popup_list ov_thin_scrollbar');
this.listDiv = AddDiv (contentDiv, 'ov_popup_list ov_thin_scrollbar');
return contentDiv;
}
AddListItem (item, callbacks)
{
let listItemDiv = OV.AddDiv (this.listDiv, 'ov_popup_list_item');
let listItemDiv = AddDiv (this.listDiv, 'ov_popup_list_item');
if (item.icon) {
OV.AddSvgIconElement (listItemDiv, item.icon, 'left_inline');
AddSvgIconElement (listItemDiv, item.icon, 'left_inline');
}
if (item.color) {
let iconDiv = OV.AddDiv (listItemDiv, 'ov_popup_list_item_icon');
let colorCircle = OV.CreateInlineColorCircle (item.color);
let iconDiv = AddDiv (listItemDiv, 'ov_popup_list_item_icon');
let colorCircle = CreateInlineColorCircle (item.color);
iconDiv.appendChild (colorCircle);
}
OV.AddDiv (listItemDiv, 'ov_popup_list_item_name', item.name);
AddDiv (listItemDiv, 'ov_popup_list_item_name', item.name);
listItemDiv.addEventListener ('click', callbacks.onClick);
if (OV.IsHoverEnabled () && callbacks.onHoverStart && callbacks.onHoverStop) {
if (IsHoverEnabled () && callbacks.onHoverStart && callbacks.onHoverStop) {
listItemDiv.addEventListener ('mouseover', () => {
callbacks.onHoverStart ();
});
@ -244,4 +247,4 @@ OV.ListPopup = class extends OV.PopupDialog
});
}
}
};
}

View File

@ -1,19 +1,26 @@
OV.SelectionType =
import { ShowDomElement, SetDomElementHeight, GetDomElementOuterWidth, SetDomElementOuterHeight } from '../engine/viewer/domutils.js';
import { NavigatorFilesPanel } from './navigatorfilespanel.js';
import { NavigatorMaterialsPanel } from './navigatormaterialspanel.js';
import { NavigatorMeshesPanel } from './navigatormeshespanel.js';
import { PanelSet } from './panelset.js';
import { InstallVerticalSplitter } from './utils.js';
export const SelectionType =
{
Material : 1,
Mesh : 2
};
OV.Selection = class
export class Selection
{
constructor (type, data)
{
this.type = type;
this.materialIndex = null;
this.meshInstanceId = null;
if (this.type === OV.SelectionType.Material) {
if (this.type === SelectionType.Material) {
this.materialIndex = data;
} else if (this.type === OV.SelectionType.Mesh) {
} else if (this.type === SelectionType.Mesh) {
this.meshInstanceId = data;
}
}
@ -23,29 +30,29 @@ OV.Selection = class
if (this.type !== rhs.type) {
return false;
}
if (this.type === OV.SelectionType.Material) {
if (this.type === SelectionType.Material) {
return this.materialIndex === rhs.materialIndex;
} else if (this.type === OV.SelectionType.Mesh) {
} else if (this.type === SelectionType.Mesh) {
return this.meshInstanceId.IsEqual (rhs.meshInstanceId);
}
}
};
}
OV.Navigator = class
export class Navigator
{
constructor (mainDiv, splitterDiv)
{
this.mainDiv = mainDiv;
this.splitterDiv = splitterDiv;
this.panelSet = new OV.PanelSet (mainDiv);
this.panelSet = new PanelSet (mainDiv);
this.callbacks = null;
this.selection = null;
this.tempSelectedMeshId = null;
this.filesPanel = new OV.NavigatorFilesPanel (this.panelSet.GetContentDiv ());
this.materialsPanel = new OV.NavigatorMaterialsPanel (this.panelSet.GetContentDiv ());
this.meshesPanel = new OV.NavigatorMeshesPanel (this.panelSet.GetContentDiv ());
this.filesPanel = new NavigatorFilesPanel (this.panelSet.GetContentDiv ());
this.materialsPanel = new NavigatorMaterialsPanel (this.panelSet.GetContentDiv ());
this.meshesPanel = new NavigatorMeshesPanel (this.panelSet.GetContentDiv ());
this.panelSet.AddPanel (this.filesPanel);
this.panelSet.AddPanel (this.materialsPanel);
@ -64,7 +71,7 @@ OV.Navigator = class
this.panelSet.Init ({
onResize : () => {
OV.ShowDomElement (this.splitterDiv, this.panelSet.IsPanelsVisible ());
ShowDomElement (this.splitterDiv, this.panelSet.IsPanelsVisible ());
this.callbacks.onResize ();
},
onShowHidePanels : (show) => {
@ -80,20 +87,20 @@ OV.Navigator = class
this.materialsPanel.Init ({
onMaterialSelected : (materialIndex) => {
this.SetSelection (new OV.Selection (OV.SelectionType.Material, materialIndex));
this.SetSelection (new Selection (SelectionType.Material, materialIndex));
},
onMeshTemporarySelected : (meshInstanceId) => {
this.tempSelectedMeshId = meshInstanceId;
this.callbacks.updateMeshesSelection ();
},
onMeshSelected : (meshInstanceId) => {
this.SetSelection (new OV.Selection (OV.SelectionType.Mesh, meshInstanceId));
this.SetSelection (new Selection (SelectionType.Mesh, meshInstanceId));
}
});
this.meshesPanel.Init ({
onMeshSelected : (meshId) => {
this.SetSelection (new OV.Selection (OV.SelectionType.Mesh, meshId));
this.SetSelection (new Selection (SelectionType.Mesh, meshId));
},
onMeshShowHide : (meshId) => {
this.ToggleMeshVisibility (meshId);
@ -108,21 +115,21 @@ OV.Navigator = class
this.FitNodeToWindow (nodeId);
},
onMaterialSelected : (materialIndex) => {
this.SetSelection (new OV.Selection (OV.SelectionType.Material, materialIndex));
this.SetSelection (new Selection (SelectionType.Material, materialIndex));
},
onViewTypeChanged : () => {
this.SetSelection (null);
}
});
OV.InstallVerticalSplitter (this.splitterDiv, this.mainDiv, false, () => {
InstallVerticalSplitter (this.splitterDiv, this.mainDiv, false, () => {
this.callbacks.onResize ();
});
}
GetWidth ()
{
let navigatorWidth = OV.GetDomElementOuterWidth (this.mainDiv);
let navigatorWidth = GetDomElementOuterWidth (this.mainDiv);
let splitterWidth = 0;
if (this.panelSet.IsPanelsVisible ()) {
splitterWidth = this.splitterDiv.offsetWidth;
@ -132,8 +139,8 @@ OV.Navigator = class
Resize (height)
{
OV.SetDomElementOuterHeight (this.mainDiv, height);
OV.SetDomElementHeight (this.splitterDiv, height);
SetDomElementOuterHeight (this.mainDiv, height);
SetDomElementHeight (this.splitterDiv, height);
this.panelSet.Resize ();
}
@ -199,7 +206,7 @@ OV.Navigator = class
if (this.tempSelectedMeshId !== null) {
return this.tempSelectedMeshId;
}
if (this.selection === null || this.selection.type !== OV.SelectionType.Mesh) {
if (this.selection === null || this.selection.type !== SelectionType.Mesh) {
return null;
}
return this.selection.meshInstanceId;
@ -209,12 +216,12 @@ OV.Navigator = class
{
function SetEntitySelection (navigator, selection, select)
{
if (selection.type === OV.SelectionType.Material) {
if (selection.type === SelectionType.Material) {
if (select && navigator.panelSet.IsPanelsVisible ()) {
navigator.panelSet.ShowPanel (navigator.materialsPanel);
}
navigator.materialsPanel.SelectMaterialItem (selection.materialIndex, select);
} else if (selection.type === OV.SelectionType.Mesh) {
} else if (selection.type === SelectionType.Mesh) {
if (select && navigator.panelSet.IsPanelsVisible ()) {
navigator.panelSet.ShowPanel (navigator.meshesPanel);
}
@ -253,9 +260,9 @@ OV.Navigator = class
if (this.selection === null) {
this.callbacks.onModelSelected ();
} else {
if (this.selection.type === OV.SelectionType.Material) {
if (this.selection.type === SelectionType.Material) {
this.callbacks.onMaterialSelected (this.selection.materialIndex);
} else if (this.selection.type === OV.SelectionType.Mesh) {
} else if (this.selection.type === SelectionType.Mesh) {
this.callbacks.onMeshSelected (this.selection.meshInstanceId);
}
}
@ -267,9 +274,9 @@ OV.Navigator = class
let materialIndex = null;
let meshInstanceId = null;
if (this.selection !== null) {
if (this.selection.type === OV.SelectionType.Material) {
if (this.selection.type === SelectionType.Material) {
materialIndex = this.selection.materialIndex;
} else if (this.selection.type === OV.SelectionType.Mesh) {
} else if (this.selection.type === SelectionType.Mesh) {
meshInstanceId = this.selection.meshInstanceId;
}
}
@ -301,4 +308,4 @@ OV.Navigator = class
this.panelSet.Clear ();
this.selection = null;
}
};
}

View File

@ -1,4 +1,8 @@
OV.NavigatorFilesPanel = class extends OV.NavigatorPanel
import { SetDomElementHeight, GetDomElementOuterHeight } from '../engine/viewer/domutils.js';
import { NavigatorPanel } from './navigatorpanel.js';
import { TreeViewButton, TreeViewButtonItem, TreeViewGroupItem, TreeViewSingleItem } from './treeview.js';
export class NavigatorFilesPanel extends NavigatorPanel
{
constructor (parentDiv)
{
@ -17,9 +21,9 @@ OV.NavigatorFilesPanel = class extends OV.NavigatorPanel
Resize ()
{
let titleHeight = OV.GetDomElementOuterHeight (this.titleDiv);
let titleHeight = GetDomElementOuterHeight (this.titleDiv);
let height = this.parentDiv.offsetHeight;
OV.SetDomElementHeight (this.treeDiv, height - titleHeight);
SetDomElementHeight (this.treeDiv, height - titleHeight);
}
Clear ()
@ -34,33 +38,33 @@ OV.NavigatorFilesPanel = class extends OV.NavigatorPanel
const missingFiles = importResult.missingFiles;
if (missingFiles.length > 0) {
let missingFilesItem = new OV.TreeViewGroupItem ('Missing Files', null);
let missingFilesItem = new TreeViewGroupItem ('Missing Files', null);
missingFilesItem.ShowChildren (true);
this.treeView.AddChild (missingFilesItem);
for (let i = 0; i < missingFiles.length; i++) {
let file = missingFiles[i];
let item = new OV.TreeViewButtonItem (file);
let browseButton = new OV.TreeViewButton ('open');
let item = new TreeViewButtonItem (file);
let browseButton = new TreeViewButton ('open');
browseButton.OnClick (() => {
this.callbacks.onFileBrowseButtonClicked ();
});
item.AppendButton (browseButton);
missingFilesItem.AddChild (item);
}
let filesItem = new OV.TreeViewGroupItem ('Available Files', null);
let filesItem = new TreeViewGroupItem ('Available Files', null);
filesItem.ShowChildren (true);
this.treeView.AddChild (filesItem);
for (let i = 0; i < usedFiles.length; i++) {
let file = usedFiles[i];
let item = new OV.TreeViewSingleItem (file);
let item = new TreeViewSingleItem (file);
filesItem.AddChild (item);
}
} else {
for (let i = 0; i < usedFiles.length; i++) {
let file = usedFiles[i];
let item = new OV.TreeViewSingleItem (file);
let item = new TreeViewSingleItem (file);
this.treeView.AddChild (item);
}
}
}
};
}

View File

@ -1,4 +1,7 @@
OV.NavigatorItemRecurse =
import { IsDefined } from '../engine/core/core.js';
import { TreeViewButton, TreeViewButtonItem, TreeViewGroupButtonItem, TreeViewSingleItem } from './treeview.js';
export const NavigatorItemRecurse =
{
No : 0,
Parents : 1,
@ -6,7 +9,7 @@ OV.NavigatorItemRecurse =
All : 3
};
OV.MaterialItem = class extends OV.TreeViewSingleItem
export class MaterialItem extends TreeViewSingleItem
{
constructor (name, materialIndex, callbacks)
{
@ -15,9 +18,9 @@ OV.MaterialItem = class extends OV.TreeViewSingleItem
callbacks.onSelected (materialIndex);
});
}
};
}
OV.MeshItem = class extends OV.TreeViewButtonItem
export class MeshItem extends TreeViewButtonItem
{
constructor (name, icon, meshInstanceId, callbacks)
{
@ -26,13 +29,13 @@ OV.MeshItem = class extends OV.TreeViewButtonItem
this.meshInstanceId = meshInstanceId;
this.visible = true;
this.fitToWindowButton = new OV.TreeViewButton ('fit');
this.fitToWindowButton = new TreeViewButton ('fit');
this.fitToWindowButton.OnClick (() => {
callbacks.onFitToWindow (this.meshInstanceId);
});
this.AppendButton (this.fitToWindowButton);
this.showHideButton = new OV.TreeViewButton ('visible');
this.showHideButton = new TreeViewButton ('visible');
this.showHideButton.OnClick (() => {
callbacks.onShowHide (this.meshInstanceId);
});
@ -64,16 +67,16 @@ OV.MeshItem = class extends OV.TreeViewButtonItem
} else {
this.showHideButton.SetImage ('hidden');
}
if (recurse === OV.NavigatorItemRecurse.Parents) {
if (this.parent instanceof OV.NodeItem) {
if (recurse === NavigatorItemRecurse.Parents) {
if (this.parent instanceof NodeItem) {
let parentIsVisible = this.parent.CalculateIsVisible ();
this.parent.SetVisible (parentIsVisible, OV.NavigatorItemRecurse.Parents);
this.parent.SetVisible (parentIsVisible, NavigatorItemRecurse.Parents);
}
}
}
};
}
OV.NodeItem = class extends OV.TreeViewGroupButtonItem
export class NodeItem extends TreeViewGroupButtonItem
{
constructor (name, nodeId, callbacks)
{
@ -82,13 +85,13 @@ OV.NodeItem = class extends OV.TreeViewGroupButtonItem
this.callbacks = callbacks;
this.visible = true;
this.fitToWindowButton = new OV.TreeViewButton ('fit');
this.fitToWindowButton = new TreeViewButton ('fit');
this.fitToWindowButton.OnClick (() => {
this.callbacks.onFitToWindow (nodeId);
});
this.AppendButton (this.fitToWindowButton);
this.showHideButton = new OV.TreeViewButton ('visible');
this.showHideButton = new TreeViewButton ('visible');
this.showHideButton.OnClick (() => {
this.callbacks.onShowHide (nodeId);
});
@ -109,7 +112,7 @@ OV.NodeItem = class extends OV.TreeViewGroupButtonItem
{
let isVisible = false;
for (let child of this.children) {
if (child instanceof OV.NodeItem || child instanceof OV.MeshItem) {
if (child instanceof NodeItem || child instanceof MeshItem) {
if (child.IsVisible ()) {
isVisible = true;
break;
@ -130,20 +133,20 @@ OV.NodeItem = class extends OV.TreeViewGroupButtonItem
} else {
this.showHideButton.SetImage ('hidden');
}
if (OV.IsDefined (this.callbacks.onVisibilityChanged)) {
if (IsDefined (this.callbacks.onVisibilityChanged)) {
this.callbacks.onVisibilityChanged (this.visible);
}
if (recurse === OV.NavigatorItemRecurse.Children || recurse === OV.NavigatorItemRecurse.All) {
if (recurse === NavigatorItemRecurse.Children || recurse === NavigatorItemRecurse.All) {
for (let child of this.children) {
if (child instanceof OV.NodeItem || child instanceof OV.MeshItem) {
child.SetVisible (this.visible, OV.NavigatorItemRecurse.Children);
if (child instanceof NodeItem || child instanceof MeshItem) {
child.SetVisible (this.visible, NavigatorItemRecurse.Children);
}
}
}
if (recurse === OV.NavigatorItemRecurse.Parents || recurse === OV.NavigatorItemRecurse.All) {
if (this.parent instanceof OV.NodeItem) {
if (recurse === NavigatorItemRecurse.Parents || recurse === NavigatorItemRecurse.All) {
if (this.parent instanceof NodeItem) {
let parentIsVisible = this.parent.CalculateIsVisible ();
this.parent.SetVisible (parentIsVisible, OV.NavigatorItemRecurse.Parents);
this.parent.SetVisible (parentIsVisible, NavigatorItemRecurse.Parents);
}
}
}
@ -151,11 +154,11 @@ OV.NodeItem = class extends OV.TreeViewGroupButtonItem
EnumerateMeshItems (processor)
{
for (let child of this.children) {
if (child instanceof OV.NodeItem) {
if (child instanceof NodeItem) {
child.EnumerateMeshItems (processor);
} else if (child instanceof OV.MeshItem) {
} else if (child instanceof MeshItem) {
processor (child);
}
}
}
};
}

View File

@ -1,4 +1,10 @@
OV.NavigatorMeshesPopupButton = class extends OV.NavigatorPopupButton
import { AddDiv, SetDomElementHeight, GetDomElementOuterHeight } from '../engine/viewer/domutils.js';
import { CalculatePopupPositionToElementBottomRight, ShowListPopup } from './dialogs.js';
import { MaterialItem } from './navigatoritems.js';
import { NavigatorPanel, NavigatorPopupButton } from './navigatorpanel.js';
import { GetMaterialName, GetMeshName } from './utils.js';
export class NavigatorMeshesPopupButton extends NavigatorPopupButton
{
constructor (parentDiv)
{
@ -27,7 +33,7 @@ OV.NavigatorMeshesPopupButton = class extends OV.NavigatorPopupButton
for (let i = 0; i < this.meshInfoArray.length; i++) {
let meshInfo = this.meshInfoArray[i];
meshItems.push ({
name : OV.GetMeshName (meshInfo.name)
name : GetMeshName (meshInfo.name)
});
}
@ -35,9 +41,9 @@ OV.NavigatorMeshesPopupButton = class extends OV.NavigatorPopupButton
return;
}
this.popup = OV.ShowListPopup (meshItems, {
this.popup = ShowListPopup (meshItems, {
calculatePosition : (contentDiv) => {
return OV.CalculatePopupPositionToElementBottomRight (this.button, contentDiv);
return CalculatePopupPositionToElementBottomRight (this.button, contentDiv);
},
onHoverStart : (index) => {
const meshData = this.meshInfoArray[index];
@ -52,9 +58,9 @@ OV.NavigatorMeshesPopupButton = class extends OV.NavigatorPopupButton
}
});
}
};
}
OV.NavigatorMaterialsPanel = class extends OV.NavigatorPanel
export class NavigatorMaterialsPanel extends NavigatorPanel
{
constructor (parentDiv)
{
@ -62,8 +68,8 @@ OV.NavigatorMaterialsPanel = class extends OV.NavigatorPanel
this.callbacks = null;
this.materialIndexToItem = new Map ();
this.popupDiv = OV.AddDiv (this.panelDiv, 'ov_navigator_info_panel');
this.meshesButton = new OV.NavigatorMeshesPopupButton (this.popupDiv);
this.popupDiv = AddDiv (this.panelDiv, 'ov_navigator_info_panel');
this.meshesButton = new NavigatorMeshesPopupButton (this.popupDiv);
}
GetName ()
@ -78,10 +84,10 @@ OV.NavigatorMaterialsPanel = class extends OV.NavigatorPanel
Resize ()
{
let titleHeight = OV.GetDomElementOuterHeight (this.titleDiv);
let popupHeight = OV.GetDomElementOuterHeight (this.popupDiv);
let titleHeight = GetDomElementOuterHeight (this.titleDiv);
let popupHeight = GetDomElementOuterHeight (this.popupDiv);
let height = this.parentDiv.offsetHeight;
OV.SetDomElementHeight (this.treeDiv, height - titleHeight - popupHeight);
SetDomElementHeight (this.treeDiv, height - titleHeight - popupHeight);
}
Clear ()
@ -110,8 +116,8 @@ OV.NavigatorMaterialsPanel = class extends OV.NavigatorPanel
const model = importResult.model;
for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) {
let material = model.GetMaterial (materialIndex);
let materialName = OV.GetMaterialName (material.name);
let materialItem = new OV.MaterialItem (materialName, materialIndex, {
let materialName = GetMaterialName (material.name);
let materialItem = new MaterialItem (materialName, materialIndex, {
onSelected : (materialIndex) => {
this.callbacks.onMaterialSelected (materialIndex);
}
@ -135,4 +141,4 @@ OV.NavigatorMaterialsPanel = class extends OV.NavigatorPanel
{
this.meshesButton.Update (meshInfoArray);
}
};
}

Some files were not shown because too many files have changed in this diff Show More