From 589afaa9b8fb6a7535d85c9b12054a264a571433 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Aug 2019 22:29:26 +0300 Subject: [PATCH 01/55] Group logic redone. Thee wrapper classes moved to the project --- .../vis/common/AbstractVisualGroup.kt | 104 +++++ .../vis/common/AbstractVisualObject.kt | 60 +++ .../hep/dataforge/vis/common/VisualGroup.kt | 140 ++----- .../hep/dataforge/vis/common/VisualObject.kt | 54 --- .../vis/common/VisualObjectDelegates.kt | 9 +- dataforge-vis-spatial/build.gradle.kts | 1 - .../kotlin/hep/dataforge/vis/spatial/Box.kt | 2 +- .../hep/dataforge/vis/spatial/Composite.kt | 8 +- .../hep/dataforge/vis/spatial/ConeSegment.kt | 2 +- .../hep/dataforge/vis/spatial/Convex.kt | 2 +- .../hep/dataforge/vis/spatial/Extruded.kt | 2 +- .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 2 +- .../hep/dataforge/vis/spatial/Sphere.kt | 2 +- .../kotlin/hep/dataforge/vis/spatial/Tube.kt | 2 +- .../dataforge/vis/spatial/VisualObject3D.kt | 45 +- .../hep/dataforge/vis/spatial/serilization.kt | 12 +- .../vis/spatial/three/ThreeFactory.kt | 5 - .../vis/spatial/three/ThreePlugin.kt | 27 +- .../jsMain/kotlin/info/laht/threekt/THREE.kt | 156 +++++++ .../laht/threekt/animation/AnimationAction.kt | 128 ++++++ .../laht/threekt/animation/AnimationClip.kt | 53 +++ .../laht/threekt/animation/AnimationMixer.kt | 37 ++ .../laht/threekt/animation/AnimationUtils.kt | 8 + .../laht/threekt/animation/KeyFrameTrack.kt | 35 ++ .../kotlin/info/laht/threekt/audio/Audio.kt | 155 +++++++ .../info/laht/threekt/audio/AudioContext.kt | 24 ++ .../info/laht/threekt/audio/AudioListener.kt | 41 ++ .../laht/threekt/audio/PositionalAudio.kt | 63 +++ .../info/laht/threekt/cameras/Camera.kt | 87 ++++ .../threekt/cameras/OrthographicCamera.kt | 57 +++ .../laht/threekt/cameras/PerspectiveCamera.kt | 50 +++ .../info/laht/threekt/core/BufferAttribute.kt | 207 ++++++++++ .../info/laht/threekt/core/BufferGeometry.kt | 117 ++++++ .../kotlin/info/laht/threekt/core/Clock.kt | 82 ++++ .../info/laht/threekt/core/DirectGeometry.kt | 48 +++ .../info/laht/threekt/core/EventDispatcher.kt | 37 ++ .../kotlin/info/laht/threekt/core/Face3.kt | 68 +++ .../kotlin/info/laht/threekt/core/Geometry.kt | 109 +++++ .../threekt/core/InstancedBufferGeometry.kt | 38 ++ .../kotlin/info/laht/threekt/core/Layers.kt | 75 ++++ .../kotlin/info/laht/threekt/core/Object3D.kt | 328 +++++++++++++++ .../info/laht/threekt/core/Raycaster.kt | 69 ++++ .../kotlin/info/laht/threekt/core/Uniform.kt | 39 ++ .../info/laht/threekt/external/Detector.kt | 42 ++ .../laht/threekt/external/ImprovedNoise.kt | 34 ++ .../laht/threekt/external/SimplexNoise.kt | 33 ++ .../threekt/external/controls/FlyControls.kt | 51 +++ .../external/controls/OrbitControls.kt | 110 +++++ .../external/controls/TrackballControls.kt | 60 +++ .../external/controls/TransformControls.kt | 47 +++ .../threekt/external/exporters/OBJExporter.kt | 36 ++ .../threekt/external/exporters/STLExporter.kt | 43 ++ .../external/geometries/ConvexGeometry.kt | 11 + .../laht/threekt/external/libs/GUIParams.kt | 21 + .../info/laht/threekt/external/libs/Stats.kt | 41 ++ .../info/laht/threekt/external/libs/datgui.kt | 154 +++++++ .../threekt/external/loaders/BabylonLoader.kt | 55 +++ .../threekt/external/loaders/GLTFLoader.kt | 61 +++ .../threekt/external/loaders/LoaderSupport.kt | 41 ++ .../threekt/external/loaders/MTLLoader.kt | 53 +++ .../threekt/external/loaders/OBJLoader.kt | 57 +++ .../threekt/external/loaders/OBJLoader2.kt | 74 ++++ .../threekt/external/loaders/STLLoader.kt | 46 +++ .../info/laht/threekt/external/objects/Sky.kt | 32 ++ .../laht/threekt/external/objects/Water.kt | 32 ++ .../threekt/external/objects/WaterOptions.kt | 47 +++ .../info/laht/threekt/extras/SceneUtils.kt | 44 ++ .../info/laht/threekt/extras/core/Curve.kt | 35 ++ .../laht/threekt/extras/core/CurvePath.kt | 22 + .../info/laht/threekt/extras/core/Path.kt | 12 + .../info/laht/threekt/extras/core/Shape.kt | 8 + .../laht/threekt/extras/core/ShapePath.kt | 6 + .../laht/threekt/extras/curves/ArcCurve.kt | 20 + .../threekt/extras/curves/CatmullRomCurve3.kt | 24 ++ .../threekt/extras/curves/EllipseCurve.kt | 37 ++ .../laht/threekt/extras/curves/LineCurve.kt | 17 + .../laht/threekt/extras/curves/LineCurve3.kt | 18 + .../extras/curves/QuadricBezierCurve.kt | 21 + .../extras/curves/QuadricBezierCurve3.kt | 21 + .../laht/threekt/extras/curves/SplineCurve.kt | 18 + .../laht/threekt/geometries/BoxGeometry.kt | 27 ++ .../laht/threekt/geometries/ConeGeometry.kt | 27 ++ .../threekt/geometries/CylinderGeometry.kt | 29 ++ .../laht/threekt/geometries/EdgesGeometry.kt | 11 + .../laht/threekt/geometries/PlaneGeometry.kt | 25 ++ .../laht/threekt/geometries/SphereGeometry.kt | 27 ++ .../laht/threekt/geometries/TorusGeometry.kt | 23 ++ .../laht/threekt/geometries/TubeGeometry.kt | 46 +++ .../threekt/geometries/WireframeGeometry.kt | 17 + .../info/laht/threekt/helpers/ArrowHelper.kt | 54 +++ .../info/laht/threekt/helpers/AxesHelper.kt | 34 ++ .../info/laht/threekt/helpers/Box3Helper.kt | 49 +++ .../info/laht/threekt/helpers/CameraHelper.kt | 43 ++ .../info/laht/threekt/helpers/GridHelper.kt | 38 ++ .../threekt/helpers/HemisphereLightHelper.kt | 51 +++ .../kotlin/info/laht/threekt/ktutils.kt | 9 + .../info/laht/threekt/lights/AmbientLight.kt | 39 ++ .../laht/threekt/lights/DirectionalLight.kt | 41 ++ .../threekt/lights/DirectionalLightShadow.kt | 32 ++ .../laht/threekt/lights/HemiSphereLight.kt | 47 +++ .../kotlin/info/laht/threekt/lights/Light.kt | 59 +++ .../info/laht/threekt/lights/LightShadow.kt | 48 +++ .../info/laht/threekt/lights/PointLight.kt | 43 ++ .../info/laht/threekt/lights/SpotLight.kt | 54 +++ .../laht/threekt/lights/SpotLightShadow.kt | 34 ++ .../kotlin/info/laht/threekt/loaders/Cache.kt | 44 ++ .../loaders/CompressedTextureLoader.kt | 73 ++++ .../info/laht/threekt/loaders/ImageLoader.kt | 80 ++++ .../info/laht/threekt/loaders/JSONLoader.kt | 84 ++++ .../info/laht/threekt/loaders/Loader.kt | 46 +++ .../laht/threekt/loaders/LoadingManager.kt | 49 +++ .../laht/threekt/loaders/MaterialLoader.kt | 47 +++ .../laht/threekt/loaders/TextureLoader.kt | 84 ++++ .../threekt/materials/LineBasicMaterial.kt | 44 ++ .../threekt/materials/LineDashedMaterial.kt | 39 ++ .../info/laht/threekt/materials/Material.kt | 130 ++++++ .../threekt/materials/MeshBasicMaterial.kt | 67 +++ .../threekt/materials/MeshDepthMaterial.kt | 55 +++ .../threekt/materials/MeshLambertMaterial.kt | 70 ++++ .../threekt/materials/MeshNormalMaterial.kt | 56 +++ .../threekt/materials/MeshPhongMaterial.kt | 86 ++++ .../threekt/materials/MeshPhysicalMaterial.kt | 41 ++ .../threekt/materials/MeshStandardMaterial.kt | 86 ++++ .../laht/threekt/materials/PointsMaterial.kt | 45 ++ .../threekt/materials/RawShaderMaterial.kt | 35 ++ .../laht/threekt/materials/ShaderMaterial.kt | 65 +++ .../laht/threekt/materials/SpriteMaterial.kt | 44 ++ .../kotlin/info/laht/threekt/math/Box2.kt | 43 ++ .../kotlin/info/laht/threekt/math/Box3.kt | 162 ++++++++ .../kotlin/info/laht/threekt/math/Color.kt | 58 +++ .../info/laht/threekt/math/ColorConstants.kt | 203 +++++++++ .../info/laht/threekt/math/Cylindrical.kt | 46 +++ .../kotlin/info/laht/threekt/math/Euler.kt | 74 ++++ .../kotlin/info/laht/threekt/math/Frustrum.kt | 43 ++ .../kotlin/info/laht/threekt/math/Line3.kt | 60 +++ .../kotlin/info/laht/threekt/math/Math.kt | 52 +++ .../kotlin/info/laht/threekt/math/Matrix3.kt | 82 ++++ .../kotlin/info/laht/threekt/math/Matrix4.kt | 178 ++++++++ .../kotlin/info/laht/threekt/math/Plane.kt | 44 ++ .../info/laht/threekt/math/Quaternion.kt | 86 ++++ .../kotlin/info/laht/threekt/math/Ray.kt | 49 +++ .../kotlin/info/laht/threekt/math/Sphere.kt | 61 +++ .../info/laht/threekt/math/Spherical.kt | 45 ++ .../kotlin/info/laht/threekt/math/Triangle.kt | 67 +++ .../kotlin/info/laht/threekt/math/Vector2.kt | 130 ++++++ .../kotlin/info/laht/threekt/math/Vector3.kt | 388 ++++++++++++++++++ .../kotlin/info/laht/threekt/math/Vector4.kt | 146 +++++++ .../info/laht/threekt/math/operators.kt | 46 +++ .../kotlin/info/laht/threekt/objects/Group.kt | 33 ++ .../kotlin/info/laht/threekt/objects/LOD.kt | 48 +++ .../kotlin/info/laht/threekt/objects/Line.kt | 47 +++ .../info/laht/threekt/objects/LineLoop.kt | 33 ++ .../info/laht/threekt/objects/LineSegments.kt | 34 ++ .../kotlin/info/laht/threekt/objects/Mesh.kt | 49 +++ .../info/laht/threekt/objects/Points.kt | 44 ++ .../info/laht/threekt/objects/Sprite.kt | 43 ++ .../laht/threekt/renderers/WebGL2Renderer.kt | 49 +++ .../threekt/renderers/WebGL2RendererParams.kt | 37 ++ .../threekt/renderers/WebGLRenderTarget.kt | 60 +++ .../renderers/WebGLRenderTargetOptions.kt | 38 ++ .../laht/threekt/renderers/WebGLRenderer.kt | 101 +++++ .../threekt/renderers/WebGLRendererParams.kt | 37 ++ .../threekt/renderers/shaders/ShaderChunk.kt | 141 +++++++ .../threekt/renderers/shaders/ShaderLib.kt | 32 ++ .../threekt/renderers/shaders/UniformsUtil.kt | 37 ++ .../kotlin/info/laht/threekt/scenes/Fog.kt | 45 ++ .../info/laht/threekt/scenes/FogExp2.kt | 44 ++ .../kotlin/info/laht/threekt/scenes/Scene.kt | 62 +++ .../threekt/textures/CompressedTexture.kt | 59 +++ .../info/laht/threekt/textures/CubeTexture.kt | 47 +++ .../laht/threekt/textures/DepthTexture.kt | 41 ++ .../info/laht/threekt/textures/Texture.kt | 238 +++++++++++ 172 files changed, 9609 insertions(+), 204 deletions(-) create mode 100644 dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt create mode 100644 dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/THREE.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationAction.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationClip.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationMixer.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationUtils.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/KeyFrameTrack.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/Audio.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioContext.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioListener.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/PositionalAudio.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/Camera.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/OrthographicCamera.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/PerspectiveCamera.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferAttribute.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Clock.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/DirectGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/EventDispatcher.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Face3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/InstancedBufferGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Raycaster.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Uniform.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/Detector.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/ImprovedNoise.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/SimplexNoise.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/FlyControls.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/OrbitControls.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TrackballControls.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TransformControls.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/OBJExporter.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/STLExporter.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/geometries/ConvexGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/GUIParams.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/Stats.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/datgui.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/BabylonLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/GLTFLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/LoaderSupport.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/MTLLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader2.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/STLLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Sky.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Water.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/WaterOptions.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/SceneUtils.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Curve.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/CurvePath.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Path.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Shape.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/ShapePath.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/ArcCurve.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/CatmullRomCurve3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/EllipseCurve.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/SplineCurve.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/BoxGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/ConeGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/CylinderGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/EdgesGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/PlaneGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/SphereGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TorusGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TubeGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/WireframeGeometry.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/ArrowHelper.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/AxesHelper.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/Box3Helper.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/CameraHelper.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/GridHelper.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/HemisphereLightHelper.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/ktutils.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/AmbientLight.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLight.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLightShadow.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/HemiSphereLight.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/Light.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/LightShadow.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/PointLight.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLight.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLightShadow.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Cache.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/CompressedTextureLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/ImageLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/JSONLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Loader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/LoadingManager.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/MaterialLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/TextureLoader.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineBasicMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineDashedMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/Material.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshBasicMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshDepthMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshLambertMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshNormalMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhongMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhysicalMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshStandardMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/PointsMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/RawShaderMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/ShaderMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/SpriteMaterial.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box2.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Color.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/ColorConstants.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Cylindrical.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Euler.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Frustrum.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Line3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Math.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix4.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Plane.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Quaternion.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Ray.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Sphere.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Spherical.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Triangle.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector2.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector3.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector4.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/operators.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Group.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LOD.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Line.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineLoop.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineSegments.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Mesh.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Points.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Sprite.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2Renderer.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2RendererParams.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTarget.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTargetOptions.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderer.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRendererParams.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderChunk.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderLib.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/UniformsUtil.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Fog.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/FogExp2.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Scene.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CompressedTexture.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CubeTexture.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/DepthTexture.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/Texture.kt diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt new file mode 100644 index 00000000..939a2ec6 --- /dev/null +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -0,0 +1,104 @@ +package hep.dataforge.vis.common + +import hep.dataforge.meta.MetaBuilder +import hep.dataforge.meta.MetaItem +import hep.dataforge.names.Name +import hep.dataforge.names.NameToken +import hep.dataforge.names.asName +import hep.dataforge.names.isEmpty +import kotlinx.serialization.Transient + + +/** + * Abstract implementation of group of [VisualObject] + */ +abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { + + //protected abstract val _children: MutableMap + + /** + * A map of top level named children + */ + abstract override val children: Map //get() = _children + + override fun propertyChanged(name: Name, before: MetaItem<*>?, after: MetaItem<*>?) { + super.propertyChanged(name, before, after) + forEach { + it.propertyChanged(name, before, after) + } + } + + private data class Listener(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) + + @Transient + private val listeners = HashSet() + + /** + * Add listener for children change + */ + override fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) { + listeners.add(Listener(owner, action)) + } + + /** + * Remove children change listener + */ + override fun removeChildrenChangeListener(owner: Any?) { + listeners.removeAll { it.owner === owner } + } + +// /** +// * Propagate children change event upwards +// */ +// protected fun childrenChanged(name: Name, child: VisualObject?) { +// +// } + + protected abstract fun removeChild(token: NameToken) + + protected abstract fun setChild(token: NameToken, child: VisualObject?) + + protected abstract fun createGroup(name: Name): VisualGroup + + /** + * Add named or unnamed child to the group. If key is [null] the child is considered unnamed. Both key and value are not + * allowed to be null in the same time. If name is present and [child] is null, the appropriate element is removed. + */ + override fun set(name: Name, child: VisualObject?) { + when { + name.isEmpty() -> error("") + name.length == 1 -> { + val token = name.first()!! + if (child == null) { + removeChild(token) + } else { + if (child.parent == null) { + child.parent = this + } else { + error("Can't reassign existing parent for $child") + } + setChild(token, child) + } + } + else -> { + //TODO add safety check + val parent = (get(name.cutLast()) as? VisualGroup) ?: createGroup(name.cutLast()) + parent[name.last()!!.asName()] = child + } + } + listeners.forEach { it.callback(name, child) } + } + + operator fun set(key: String, child: VisualObject?) = set(key.asName(), child) + + protected fun MetaBuilder.updateChildren() { + //adding named children + children.forEach { + "children[${it.key}]" to it.value.toMeta() + } + } + + override fun MetaBuilder.updateMeta() { + updateChildren() + } +} \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt new file mode 100644 index 00000000..61ae9b7c --- /dev/null +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -0,0 +1,60 @@ +package hep.dataforge.vis.common + +import hep.dataforge.meta.* +import hep.dataforge.names.Name +import kotlinx.serialization.Transient + +internal data class PropertyListener( + val owner: Any? = null, + val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit +) + +abstract class AbstractVisualObject : VisualObject { + + @Transient + override var parent: VisualObject? = null + + @Transient + private val listeners = HashSet() + + override fun propertyChanged(name: Name, before: MetaItem<*>?, after: MetaItem<*>?) { + for (l in listeners) { + l.action(name, before, after) + } + } + + override fun onPropertyChange(owner: Any?, action: (Name, before: MetaItem<*>?, after: MetaItem<*>?) -> Unit) { + listeners.add(PropertyListener(owner, action)) + } + + override fun removeChangeListener(owner: Any?) { + listeners.removeAll { it.owner == owner } + } + + abstract var properties: Config? + override val config: Config + get() = properties ?: Config().also { config -> + properties = config + config.onChange(this, ::propertyChanged) + } + + override fun setProperty(name: Name, value: Any?) { + config[name] = value + } + + override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { + return if (inherit) { + properties?.get(name) ?: parent?.getProperty(name, inherit) + } else { + properties?.get(name) + } + } + + protected open fun MetaBuilder.updateMeta() {} + + override fun toMeta(): Meta = buildMeta { + "type" to this::class.simpleName + "properties" to properties + updateMeta() + } +} \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt index 144f26e6..749938bd 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt @@ -1,131 +1,53 @@ package hep.dataforge.vis.common -import hep.dataforge.meta.Config -import hep.dataforge.meta.MetaBuilder -import hep.dataforge.meta.MetaItem -import hep.dataforge.names.Name -import hep.dataforge.names.toName +import hep.dataforge.names.* import hep.dataforge.provider.Provider -import kotlinx.serialization.Transient -import kotlin.collections.set -open class VisualGroup : AbstractVisualObject(), Iterable, Provider { - - protected open val namedChildren: MutableMap = HashMap() - protected open val unnamedChildren: MutableList = ArrayList() - - override var properties: Config? = null +interface VisualGroup : VisualObject, Provider, Iterable { + /** + * A map of top level named children + */ + val children: Map override val defaultTarget: String get() = VisualObject.TYPE - override fun iterator(): Iterator = (namedChildren.values + unnamedChildren).iterator() - - override fun provideTop(target: String): Map { - return when (target) { - VisualObject.TYPE -> namedChildren - else -> emptyMap() - } + override fun provideTop(target: String): Map = if (target == VisualObject.TYPE) { + children.flatMap { (key, value) -> + val res: Map = if (value is VisualGroup) { + value.provideTop(target).mapKeys { key + it.key } + } else { + mapOf(key.asName() to value) + } + res.entries + }.associate { it.toPair() } + } else { + emptyMap() } - override fun propertyChanged(name: Name, before: MetaItem<*>?, after: MetaItem<*>?) { - super.propertyChanged(name, before, after) - forEach { - it.propertyChanged(name, before, after) - } - } - - private data class Listener(val owner: Any?, val callback: (Name?, T?) -> Unit) - - @Transient - private val listeners = HashSet>() + /** + * Iterate over children of this group + */ + override fun iterator(): Iterator = children.values.iterator() /** * Add listener for children change */ - fun onChildrenChange(owner: Any?, action: (Name?, T?) -> Unit) { - listeners.add(Listener(owner, action)) - } - + fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) /** * Remove children change listener */ - fun removeChildrenChangeListener(owner: Any?) { - listeners.removeAll { it.owner === owner } - } + fun removeChildrenChangeListener(owner: Any?) - /** - * Add named or unnamed child to the group. If key is [null] the child is considered unnamed. Both key and value are not - * allowed to be null in the same time. If name is present and [child] is null, the appropriate element is removed. - */ - operator fun set(name: Name?, child: T?) { - when { - name != null -> { - if (child == null) { - namedChildren.remove(name) - } else { - if (child.parent == null) { - child.parent = this - } else { - error("Can't reassign existing parent for $child") - } - namedChildren[name] = child - } - listeners.forEach { it.callback(name, child) } - } - child != null -> add(child) - else -> error("Both key and child element are empty") + operator fun get(name: Name): VisualObject? { + return when { + name.isEmpty() -> this + name.length == 1 -> children[name.first()!!] + else -> (children[name.first()!!] as? VisualGroup)?.get(name.cutFirst()) } } - operator fun set(key: String?, child: T?) = set(key?.asName(), child) + operator fun set(name: Name, child: VisualObject?) +} - /** - * Get named child by name - */ - operator fun get(name: Name): T? = namedChildren[name] - - /** - * Get named child by string - */ - operator fun get(key: String): T? = namedChildren[key.toName()] - - /** - * Get an unnamed child - */ - operator fun get(index: Int): T? = unnamedChildren[index] - - /** - * Append unnamed child - */ - fun add(child: T) { - if (child.parent == null) { - child.parent = this - } else { - error("Can't reassign existing parent for $child") - } - unnamedChildren.add(child) - listeners.forEach { it.callback(null, child) } - } - - /** - * remove unnamed child - */ - fun remove(child: VisualObject) { - unnamedChildren.remove(child) - listeners.forEach { it.callback(null, null) } - } - - protected fun MetaBuilder.updateChildren() { - //adding unnamed children - "unnamedChildren" to unnamedChildren.map { it.toMeta() } - //adding named children - namedChildren.forEach { - "children[${it.key}]" to it.value.toMeta() - } - } - - override fun MetaBuilder.updateMeta() { - updateChildren() - } -} \ No newline at end of file +operator fun VisualGroup.get(str: String) = get(str.toName()) \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt index 6f131fe2..1c15a0a5 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt @@ -54,57 +54,3 @@ interface VisualObject : MetaRepr, Configurable { } } -internal data class MetaListener( - val owner: Any? = null, - val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit -) - -abstract class AbstractVisualObject: VisualObject { - - @Transient - override var parent: VisualObject? = null - - @Transient - private val listeners = HashSet() - - override fun propertyChanged(name: Name, before: MetaItem<*>?, after: MetaItem<*>?) { - for (l in listeners) { - l.action(name, before, after) - } - } - - override fun onPropertyChange(owner: Any?, action: (Name, before: MetaItem<*>?, after: MetaItem<*>?) -> Unit) { - listeners.add(MetaListener(owner, action)) - } - - override fun removeChangeListener(owner: Any?) { - listeners.removeAll { it.owner == owner } - } - - abstract var properties: Config? - override val config: Config - get() = properties ?: Config().also { config -> - properties = config - config.onChange(this, ::propertyChanged) - } - - override fun setProperty(name: Name, value: Any?) { - config[name] = value - } - - override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { - return if (inherit) { - properties?.get(name) ?: parent?.getProperty(name, inherit) - } else { - properties?.get(name) - } - } - - protected open fun MetaBuilder.updateMeta() {} - - override fun toMeta(): Meta = buildMeta { - "type" to this::class.simpleName - "properties" to properties - updateMeta() - } -} \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt index 748e537b..c9b88bb3 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt @@ -1,6 +1,7 @@ package hep.dataforge.vis.common import hep.dataforge.meta.* +import hep.dataforge.names.EmptyName import hep.dataforge.names.Name import hep.dataforge.names.NameToken import hep.dataforge.names.asName @@ -10,7 +11,7 @@ import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty -fun String.asName() = NameToken(this).asName() +fun String.asName() = if (isBlank()) EmptyName else NameToken(this).asName() /** * A delegate for display object properties @@ -110,7 +111,11 @@ fun VisualObject.int(default: Int, key: String? = null, inherited: Boolean = fal inline fun > VisualObject.enum(default: E, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.let{ NameToken(it).asName()}, default, inherited) { item -> item.string?.let { enumValueOf(it) } } + DisplayObjectDelegateWrapper( + key?.let { NameToken(it).asName() }, + default, + inherited + ) { item -> item.string?.let { enumValueOf(it) } } //merge properties diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index 17715a94..d2eb5d37 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -27,7 +27,6 @@ kotlin { } jsMain{ dependencies { - api("info.laht.threekt:threejs-wrapper:0.106-npm-3") implementation(npm("three", "0.106.2")) implementation(npm("@hi-level/three-csg", "1.0.6")) implementation(npm("style-loader")) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt index 7f362248..40ee092d 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt @@ -76,6 +76,6 @@ inline fun VisualGroup3D.box( xSize: Number, ySize: Number, zSize: Number, - name: String? = null, + name: String = "", action: Box.() -> Unit = {} ) = Box(xSize.toFloat(), ySize.toFloat(), zSize.toFloat()).apply(action).also { set(name, it) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt index 8e6970ad..8c31dd8f 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Composite.kt @@ -39,7 +39,7 @@ class Composite( inline fun VisualGroup3D.composite( type: CompositeType, - name: String? = null, + name: String = "", builder: VisualGroup3D.() -> Unit ): Composite { val group = VisualGroup3D().apply(builder) @@ -57,11 +57,11 @@ inline fun VisualGroup3D.composite( } } -fun VisualGroup3D.union(name: String? = null, builder: VisualGroup3D.() -> Unit) = +fun VisualGroup3D.union(name: String = "", builder: VisualGroup3D.() -> Unit) = composite(CompositeType.UNION, name, builder = builder) -fun VisualGroup3D.subtract(name: String? = null, builder: VisualGroup3D.() -> Unit) = +fun VisualGroup3D.subtract(name: String = "", builder: VisualGroup3D.() -> Unit) = composite(CompositeType.SUBTRACT, name, builder = builder) -fun VisualGroup3D.intersect(name: String? = null, builder: VisualGroup3D.() -> Unit) = +fun VisualGroup3D.intersect(name: String = "", builder: VisualGroup3D.() -> Unit) = composite(CompositeType.INTERSECT, name, builder = builder) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt index fdecbf3c..26d4942f 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/ConeSegment.kt @@ -31,7 +31,7 @@ class ConeSegment( inline fun VisualGroup3D.cylinder( r: Number, height: Number, - name: String? = null, + name: String = "", block: ConeSegment.() -> Unit = {} ): ConeSegment = ConeSegment( r.toFloat(), diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt index 1bfa5e7b..56062ca8 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Convex.kt @@ -31,7 +31,7 @@ class Convex(val points: List) : AbstractVisualObject(), VisualObject3D } } -inline fun VisualGroup3D.convex(name: String? = null, action: ConvexBuilder.() -> Unit = {}) = +inline fun VisualGroup3D.convex(name: String = "", action: ConvexBuilder.() -> Unit = {}) = ConvexBuilder().apply(action).build().also { set(name, it) } class ConvexBuilder { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt index 5a464521..32e8082d 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt @@ -110,5 +110,5 @@ class Extruded( } } -fun VisualGroup3D.extrude(name: String? = null, action: Extruded.() -> Unit = {}) = +fun VisualGroup3D.extrude(name: String = "", action: Extruded.() -> Unit = {}) = Extruded().apply(action).also { set(name, it) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 15ea2f28..f91ec56a 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -58,6 +58,6 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualObject3D { inline fun VisualGroup3D.ref( templateName: Name, - name: String? = null, + name: String = "", action: Proxy.() -> Unit = {} ) = Proxy(templateName).apply(action).also { set(name, it) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt index 28f83960..7cc2c411 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt @@ -30,7 +30,7 @@ inline fun VisualGroup3D.sphere( radius: Number, phi: Number = 2 * PI, theta: Number = PI, - name: String? = null, + name: String = "", action: Sphere.() -> Unit = {} ) = Sphere( radius.toFloat(), diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt index 6b869d7f..77f707ee 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Tube.kt @@ -131,7 +131,7 @@ inline fun VisualGroup3D.tube( innerRadius: Number = 0f, startAngle: Number = 0f, angle: Number = 2 * PI, - name: String? = null, + name: String = "", block: Tube.() -> Unit = {} ): Tube = Tube( r.toFloat(), diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index 0a51c6cb..564349bc 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -1,14 +1,13 @@ -@file:UseSerializers(Point3DSerializer::class, NameSerializer::class) +@file:UseSerializers(Point3DSerializer::class, NameSerializer::class, NameTokenSerializer::class) package hep.dataforge.vis.spatial import hep.dataforge.io.ConfigSerializer import hep.dataforge.io.NameSerializer import hep.dataforge.meta.* -import hep.dataforge.names.Name -import hep.dataforge.names.plus +import hep.dataforge.names.* import hep.dataforge.output.Output -import hep.dataforge.vis.common.VisualGroup +import hep.dataforge.vis.common.AbstractVisualGroup import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY @@ -66,7 +65,7 @@ interface VisualObject3D : VisualObject { } @Serializable -class VisualGroup3D : VisualGroup(), VisualObject3D, Configurable { +class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, Configurable { /** * A container for templates visible inside this group */ @@ -83,10 +82,38 @@ class VisualGroup3D : VisualGroup(), VisualObject3D, Configurabl override var rotation: Point3D? = null override var scale: Point3D? = null - override val namedChildren: MutableMap = HashMap() - override val unnamedChildren: MutableList = ArrayList() + private val _children = HashMap() + override val children: Map get() = _children - fun getTemplate(name: Name): VisualObject3D? = templates?.get(name) ?: (parent as? VisualGroup3D)?.getTemplate(name) + override fun removeChild(token: NameToken) { + _children.remove(token) + } + + override fun setChild(token: NameToken, child: VisualObject?) { + if (child == null) { + _children.remove(token) + } else { + _children[token] = child + } + } + + override fun createGroup(name: Name): VisualGroup3D { + return when{ + name.isEmpty() -> error("Should be unreachable") + name.length == 1 -> { + val token = name.first()!! + when (val current = children[token]) { + null -> VisualGroup3D().also { setChild(token, it) } + is VisualGroup3D -> current + else -> error("Can't create group with name $name because it exists and not a group") + } + } + else -> createGroup(name.first()!!.asName()).createGroup(name.cutFirst()) + } + } + + fun getTemplate(name: Name): VisualObject3D? = + templates?.get(name) as? VisualGroup3D ?: (parent as? VisualGroup3D)?.getTemplate(name) override fun MetaBuilder.updateMeta() { set(TEMPLATES_KEY, templates?.toMeta()) @@ -99,7 +126,7 @@ class VisualGroup3D : VisualGroup(), VisualObject3D, Configurabl } } -fun VisualGroup3D.group(key: String? = null, action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = +fun VisualGroup3D.group(key: String = "", action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = VisualGroup3D().apply(action).also { set(key, it) } fun Output.render(meta: Meta = EmptyMeta, action: VisualGroup3D.() -> Unit) = diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt index e353d655..ffa92ae6 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt @@ -1,5 +1,6 @@ package hep.dataforge.vis.spatial +import hep.dataforge.names.NameToken import kotlinx.serialization.* @Serializable @@ -9,7 +10,7 @@ private data class Point2DSerial(val x: Double, val y: Double) private data class Point3DSerial(val x: Double, val y: Double, val z: Double) @Serializer(Point3D::class) -object Point3DSerializer : KSerializer { +object Point3DSerializer : KSerializer{ private val serializer = Point3DSerial.serializer() override val descriptor: SerialDescriptor get() = serializer.descriptor @@ -20,12 +21,12 @@ object Point3DSerializer : KSerializer { } override fun serialize(encoder: Encoder, obj: Point3D) { - serializer.serialize(encoder, Point3DSerial(obj.x, obj.y, obj.z) ) + serializer.serialize(encoder, Point3DSerial(obj.x, obj.y, obj.z)) } } @Serializer(Point2D::class) -object Point2DSerializer : KSerializer { +object Point2DSerializer : KSerializer{ private val serializer = Point2DSerial.serializer() override val descriptor: SerialDescriptor get() = serializer.descriptor @@ -38,4 +39,7 @@ object Point2DSerializer : KSerializer { override fun serialize(encoder: Encoder, obj: Point2D) { serializer.serialize(encoder, Point2DSerial(obj.x, obj.y)) } -} \ No newline at end of file +} + +@Serializer(NameToken::class) +object NameTokenSerializer : KSerializer \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index c50f5139..1b93b1bc 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -38,11 +38,6 @@ interface ThreeFactory { internal fun Object3D.updatePosition(obj: VisualObject3D) { visible = obj.visible ?: true position.set(obj.x, obj.y, obj.z) -// obj.rotation?.let{ -// rotateZ(it.z) -// rotateX(it.x) -// rotateY(it.y) -// } setRotationFromEuler(obj.euler) scale.set(obj.scaleX, obj.scaleY, obj.scaleZ) updateMatrix() diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt index 50de48f4..da642588 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt @@ -37,16 +37,25 @@ class ThreePlugin : AbstractPlugin() { fun buildObject3D(obj: VisualObject3D): Object3D { return when (obj) { - is VisualGroup3D -> Group(obj.mapNotNull { - try { - buildObject3D(it) - } catch (ex: Throwable) { - console.error(ex) - logger.error(ex) { "Failed to render $it" } - null + is VisualGroup3D -> { + val group = info.laht.threekt.objects.Group() + obj.children.forEach { (name, child) -> + if (child is VisualObject3D) { + try { + val object3D = buildObject3D(child) + object3D.name = name.toString() + group.add(object3D) + } catch (ex: Throwable) { + console.error(ex) + logger.error(ex) { "Failed to render $name" } + } + } + } + + group.apply { + updatePosition(obj) + //obj.onChildrenChange() } - }).apply { - updatePosition(obj) } is Composite -> compositeFactory(obj) is Proxy -> proxyFactory(obj) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/THREE.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/THREE.kt new file mode 100644 index 00000000..d3844561 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/THREE.kt @@ -0,0 +1,156 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt + + +external val REVISION: String +external val CullFaceNone: Int +external val CullFaceBack: Int +external val CullFaceFront: Int +external val CullFaceFrontBack: Int +external val FrontFaceDirectionCW: Int +external val FrontFaceDirectionCCW: Int +external val BasicShadowMap: Int +external val PCFShadowMap: Int +external val PCFSoftShadowMap: Int +external val FrontSide: Int +external val BackSide: Int +external val DoubleSide: Int +external val FlatShading: Int +external val SmoothShading: Int +external val NoColors: Int +external val FaceColors: Int +external val VertexColors: Int +external val NoBlending: Int +external val NormalBlending: Int +external val AdditiveBlending: Int +external val SubtractiveBlending: Int +external val MultiplyBlending: Int +external val CustomBlending: Int +external val AddEquation: Int +external val SubtractEquation: Int +external val ReverseSubtractEquation: Int +external val MinEquation: Int +external val MaxEquation: Int +external val ZeroFactor: Int +external val OneFactor: Int +external val SrcColorFactor: Int +external val OneMinusSrcColorFactor: Int +external val SrcAlphaFactor: Int +external val OneMinusSrcAlphaFactor: Int +external val DstAlphaFactor: Int +external val OneMinusDstAlphaFactor: Int +external val DstColorFactor: Int +external val OneMinusDstColorFactor: Int +external val SrcAlphaSaturateFactor: Int +external val NeverDepth: Int +external val AlwaysDepth: Int +external val LessDepth: Int +external val LessEqualDepth: Int +external val EqualDepth: Int +external val GreaterEqualDepth: Int +external val GreaterDepth: Int +external val NotEqualDepth: Int +external val MultiplyOperation: Int +external val MixOperation: Int +external val AddOperation: Int +external val NoToneMapping: Int +external val LinearToneMapping: Int +external val ReinhardToneMapping: Int +external val Uncharted2ToneMapping: Int +external val CineonToneMapping: Int +external val UVMapping: Int +external val CubeReflectionMapping: Int +external val CubeRefractionMapping: Int +external val EquirectangularReflectionMapping: Int +external val EquirectangularRefractionMapping: Int +external val SphericalReflectionMapping: Int +external val CubeUVReflectionMapping: Int +external val CubeUVRefractionMapping: Int +external val RepeatWrapping: Int +external val ClampToEdgeWrapping: Int +external val MirroredRepeatWrapping: Int +external val NearestFilter: Int +external val NearestMipMapNearestFilter: Int +external val NearestMipMapLinearFilter: Int +external val LinearFilter: Int +external val LinearMipMapNearestFilter: Int +external val LinearMipMapLinearFilter: Int +external val UnsignedByteType: Int +external val ByteType: Int +external val ShortType: Int +external val UnsignedShortType: Int +external val IntType: Int +external val UnsignedIntType: Int +external val FloatType: Int +external val HalfFloatType: Int +external val UnsignedShort4444Type: Int +external val UnsignedShort5551Type: Int +external val UnsignedShort565Type: Int +external val UnsignedInt248Type: Int +external val AlphaFormat: Int +external val RGBFormat: Int +external val RGBAFormat: Int +external val LuminanceFormat: Int +external val LuminanceAlphaFormat: Int +external val RGBEFormat: Int +external val DepthFormat: Int +external val DepthStencilFormat: Int +external val RGB_S3TC_DXT1_Format: Int +external val RGBA_S3TC_DXT1_Format: Int +external val RGBA_S3TC_DXT3_Format: Int +external val RGBA_S3TC_DXT5_Format: Int +external val RGB_PVRTC_4BPPV1_Format: Int +external val RGB_PVRTC_2BPPV1_Format: Int +external val RGBA_PVRTC_4BPPV1_Format: Int +external val RGBA_PVRTC_2BPPV1_Format: Int +external val RGB_ETC1_Format: Int +external val LoopOnce: Int +external val LoopRepeat: Int +external val LoopPingPong: Int +external val InterpolateDiscrete: Int +external val InterpolateLinear: Int +external val InterpolateSmooth: Int +external val ZeroCurvatureEnding: Int +external val ZeroSlopeEnding: Int +external val WrapAroundEnding: Int +external val TrianglesDrawMode: Int +external val TriangleStripDrawMode: Int +external val TriangleFanDrawMode: Int +external val LinearEncoding: Int +external val sRGBEncoding: Int +external val GammaEncoding: Int +external val RGBEEncoding: Int +external val LogLuvEncoding: Int +external val RGBM7Encoding: Int +external val RGBM16Encoding: Int +external val RGBDEncoding: Int +external val BasicDepthPacking: Int +external val RGBADepthPacking: Int + + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationAction.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationAction.kt new file mode 100644 index 00000000..8abbc8ae --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationAction.kt @@ -0,0 +1,128 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.animation + +import info.laht.threekt.core.Object3D + +external class AnimationAction( + mixer: AnimationMixer, + clip: AnimationClip, + localRoot: Object3D +) { + + /** + * Setting enabled to false disables this action, so that it has no impact. Default is true. + * + * When the action is re-enabled, the animation continues from its current time + * (setting enabled to false doesn't reset the action). + * + * Note: Setting enabled to true doesn’t automatically restart the animation. + * Setting enabled to true will only restart the animation immediately if the following condition + * is fulfilled: paused is false, this action has not been deactivated in the meantime + * (by executing a stop or reset command), and neither weight nor timeScale is 0. + */ + var enabled: Boolean + + /** + * The looping mode (can be changed with setLoop). Default is THREE.LoopRepeat (with an infinite number of repetitions) + */ + var loop: Int + + /** + * Setting paused to true pauses the execution of the action by setting the effective time scale to 0. Default is false. + */ + var paused: Boolean + + var repetitions: Int + + var time: Double + + var timeScale: Double + + /** + * The degree of influence of this action (in the interval [0, 1]). + * Values between 0 (no impact) and 1 (full impact) can be used to blend between several actions. Default is 1. + * + * Properties/methods concerning weight are: crossFadeFrom, crossFadeTo, enabled, fadeIn, fadeOut, + * getEffectiveWeight, setEffectiveWeight, stopFading. + */ + var weight: Double + + /** + * Enables smooth interpolation without separate clips for start, loop and end. Default is true. + */ + var zeroSlopeAtEnd: Boolean + + /** + * Enables smooth interpolation without separate clips for start, loop and end. Default is true. + */ + var zeroSlopeAtStart: Boolean + + + // State & Scheduling + + fun play(): AnimationAction + + fun stop(): AnimationAction + + fun reset(): AnimationAction + + fun isRunning(): Boolean + + // return true when play has been called + fun isScheduled(): Boolean + + fun startAt(time: Number): AnimationAction + fun setLoop(mode: Int, repetitions: Int): AnimationAction + + // Weight + + // set the weight stopping any scheduled fading + // although .enabled = false yields an effective weight of zero, this + // method does *not* change .enabled, because it would be confusing + fun setEffectiveWeight(weight: Number) + + // return the weight considering fading and .enabled + fun getEffectiveWeight() + + fun fadeIn(duration: Number): AnimationAction + + fun fadeOut(duration: Number): AnimationAction + + fun crossFadeFrom(fadeOutAction: AnimationAction, duration: Number, warp: Boolean) + + fun crossFadeTo(fadeInAction: AnimationAction, duration: Number, warp: Boolean) + + fun stopFading(): AnimationAction + + // Time Scale Control + + // set the time scale stopping any scheduled warping + // although .paused = true yields an effective time scale of zero, this + // method does *not* change .paused, because it would be confusing + fun setEffectiveTimeScale(timeScale: Number): AnimationAction + + // return the time scale considering warping and .paused + fun getEffectiveTimeScale(): Double + + fun setDuration(duration: Number): AnimationAction + + fun syncWith(action: AnimationAction) + + fun halt(duration: Number): AnimationAction + + fun warp(startTimeScale: Number, endTimeScale: Number, duration: Number): AnimationAction + + fun stopWarping(): AnimationAction + + // Object Accessors + + fun getMixer(): AnimationMixer + + fun getClip(): AnimationClip + + fun getRoot(): Object3D + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationClip.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationClip.kt new file mode 100644 index 00000000..262f02dc --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationClip.kt @@ -0,0 +1,53 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.animation + +/** + * An AnimationClip is a reusable set of keyframe tracks which represent an animation. + +For an overview of the different elements of the three.js animation system see the "Animation System" article in the "Next Steps" section of the manual. + * + * @param name a name for this clip. + * @param duration the duration of this clip (in seconds). If a negative value is passed, the duration will be calculated from the passed tracks array. + * @param tracks an array of KeyframeTracks. + */ +external class AnimationClip( + name: String, + duration: Number, + tracks: Array +) { + + companion object { + /** + * Parses the animation.hierarchy format and returns an AnimationClip. + */ + fun parse(json: String): AnimationClip + + /** + * Takes an AnimationClip and returns a JSON object. + */ + fun toJSON(clip: AnimationClip): dynamic + } + + var uuid: String + var name: String + var duration: Double + var tracks: Array + + /** + * Optimizes each track by removing equivalent sequential keys (which are common in morph target sequences). + */ + fun optimize(): AnimationClip + + /** + * Sets the duration of the clip to the duration of its longest KeyframeTrack. + */ + fun resetDuration() + + /** + * Trims all tracks to the clip's duration. + */ + fun trim(): AnimationClip + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationMixer.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationMixer.kt new file mode 100644 index 00000000..383f88f7 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationMixer.kt @@ -0,0 +1,37 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.animation + +import info.laht.threekt.core.Object3D + +/** + * The AnimationMixer is a player for animations on a particular object in the scene. + * When multiple objects in the scene are animated independently, one AnimationMixer may be used for each object. + + * For an overview of the different elements of the three.js animation system see the "Animation System" article + * in the "Next Steps" section of the manual. + */ +external class AnimationMixer( + root: Object3D +) { + + var time: Double + var timeScale: Double + + fun clipAction(clip: AnimationClip, optionalRoot: Object3D = definedExternally): AnimationClip + fun existingAction(clip: AnimationClip, optionalRoot: Object3D = definedExternally): AnimationClip + + fun getRoot(): Object3D + + fun stopAllAction() + + fun update(deltaTimeInSeconds: Number) + + fun uncacheClip(clip: AnimationClip) + + fun unchacheRoot(root: Object3D) + + fun uncacheAction(clip: AnimationClip, optionalRoot: Object3D) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationUtils.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationUtils.kt new file mode 100644 index 00000000..34a9633b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/AnimationUtils.kt @@ -0,0 +1,8 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.animation + +external object AnimationUtils { + //TODO +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/KeyFrameTrack.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/KeyFrameTrack.kt new file mode 100644 index 00000000..478fd1f6 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/animation/KeyFrameTrack.kt @@ -0,0 +1,35 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.animation + +import org.khronos.webgl.Float32Array + +/** + * @param name the identifier for the KeyframeTrack. + * @param times an array of keyframe times, converted internally to a Float32Array. + * @param values an array with the values related to the times array, converted internally to a Float32Array. + * @param interpolation the type of interpolation to use. See Animation Constants for possible values. Default is InterpolateLinear. + */ +external class KeyFrameTrack( + name: String, + times: Array, + values: Array, + interpolation: Int +) { + + companion object { + var DefaultInterpolation: Int + } + + var name: String + var times: Float32Array + var values: Float32Array + + /** + * Returns the interpolation type + */ + fun getInterpolation(): Int + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/Audio.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/Audio.kt new file mode 100644 index 00000000..f6266c41 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/Audio.kt @@ -0,0 +1,155 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.audio + +/** + * Create a non-positional ( global ) audio object. + * + * This uses the Web Audio API. + */ +open external class Audio(listener: AudioListener) { + + /** + * Whether to start playback automatically. Default is false. + */ + var autoPlay: Boolean + /** + * The AudioContext of the listener given in the constructor. + */ + var context: dynamic + /** + * Whether the audio is currently playing. Default is empty array. + */ + var filters: Array + /** + * A GainNode created using AudioContext.createGain(). + */ + var gain: dynamic + + /** + * Whether playback can be controlled using the play(), pause() etc. methods. Default is true. + */ + var hasPlaybackControl: Boolean + /** + * Speed of playback. Default is 1. + */ + var playbackRate: Double + + /** + * Whether the audio is currently playing. + */ + var isPlaying: Boolean + + /** + * The time at which the sound should begin to play. Same as the when paramter of AudioBufferSourceNode.start(). Default is 0. + */ + var startTime: Double + + /** + * Type of the audio source. Default is string 'empty'. + */ + var sourceType: String + + /** + * Return the gainNode. + */ + open fun getOutput(): dynamic + + /** + * Setup the source to the audioBuffer, and sets sourceType to 'audioNode'. + * Also sets hasPlaybackControl to false. + */ + fun setNodeSource(audioNode: dynamic): Audio + + /** + * Setup the source to the audioBuffer, and sets sourceType to 'buffer'. + * If autoplay, also starts playback. + */ + fun setBuffer(audioBuffer: dynamic): Audio + + /** + * If hasPlaybackControl is true, starts playback. + */ + fun play(): Audio + + /** + * If hasPlaybackControl is true, pauses playback. + */ + fun pause(): Audio + + /** + * If hasPlaybackControl is enabled, stops playback, + * resets startTime to 0 and sets isPlaying to false. + */ + fun stop(): Audio + + /** + * Connect to the Audio.source. This is used internally on initialisation and when setting / removing filters. + */ + fun connect(): Audio + + /** + * Disconnect from the Audio.source. This is used internally when setting / removing filters. + */ + fun disconnect(): Audio + + /** + * Returns the filters array. + */ + fun getFilters(): Array + + /** + * value - arrays of filters. + * Set the filters array to value. + */ + fun setFilters(value: Array): Audio + + /** + * Returns the first element of the filters array. + */ + fun getFilter(): dynamic + + /** + * Add the filter to the filters array. + */ + fun setFilter(filter: dynamic) + + /** + * If hasPlaybackControl is enabled, set the playbackRate to value. + */ + fun setPlaybackRate(value: Number): Double + + /** + * Return the value of playbackRate. + */ + fun getPlaybackRate(): Double + + /** + * Called automatically when playback finished. Sets If isPlaying to false. + */ + fun onEnded() + + /** + * Return the value of source.loop (whether playback should loop). + */ + fun getLoop(): Boolean + + /** + * Set source.loop to value. + * @param value whether playback should loop + */ + fun setLoop(value: Boolean): Audio + + /** + * Return the current volume. + */ + fun getVolume(): Double + + /** + * Set the volume. + * @param value the volume + */ + fun setVolume(value: Number): Audio + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioContext.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioContext.kt new file mode 100644 index 00000000..3bccd0ac --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioContext.kt @@ -0,0 +1,24 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.audio + +/** + * This contains methods for setting up an AudioContext. + * Used internally by the AudioListener and AudioLoader classes. + * + * This uses the Web Audio API. + */ +external object AudioContext { + + /** + * Return the value of the variable context in the outer scope, if defined, otherwise set it to a new AudioContext. + */ + fun getContext(): dynamic + + /** + * Set the variable context in the outer scope to value. + */ + fun setContext(value: dynamic) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioListener.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioListener.kt new file mode 100644 index 00000000..e99b9b13 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/AudioListener.kt @@ -0,0 +1,41 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.audio + +import info.laht.threekt.core.Object3D + +/** + * Create a non-positional ( global ) audio object. + * + * This uses the Web Audio API. + */ +external class AudioListener : Object3D { + + var context: dynamic + + /** + * Return the gainNode. + */ + fun getInput(): dynamic + + /** + * Set the filter property to null. + */ + fun removeFilter() + + /** + * Returns the value of the filter property. + */ + fun getFilter(): dynamic + + /** + * Set the filter property to value. + */ + fun setFilter(value: dynamic) + + fun getMasterVolume(): Double + + fun setMasterVolume(value: Number) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/PositionalAudio.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/PositionalAudio.kt new file mode 100644 index 00000000..19c17bea --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/audio/PositionalAudio.kt @@ -0,0 +1,63 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.audio + +/** + * Create a positional audio object. + * + * This uses the Web Audio API. + */ +external class PositionalAudio(listener: AudioListener) : Audio { + + /** + * The PositionalAudio's PannerNode. + */ + var panner: dynamic + + /** + * Returns the panner. + */ + override fun getOutput(): dynamic + + /** + * Returns the value of panner.refDistance. + */ + fun getRefDistance(): Double + + /** + * Sets the value of panner.refDistance. + */ + fun setRefDistance(value: Number) + + /** + * Returns the value of panner.rolloffFactor. + */ + fun getRolloffFactor(): Double + + /** + * Sets the value of panner.rolloffFactor. + */ + fun setRolloffFactor(value: Number) + + /** + * Returns the value of panner.distanceModel. + */ + fun getDistanceModel(): String + + /** + * Sets the value of panner.distanceModel. + */ + fun setDistanceModel(value: String) + + /** + * Returns the value of panner.maxDistance. + */ + fun getMaxDistance(): Double + + /** + * Sets the value of panner.maxDistance. + */ + fun setMaxDistance(value: Number) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/Camera.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/Camera.kt new file mode 100644 index 00000000..6ab80298 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/Camera.kt @@ -0,0 +1,87 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.cameras + +import info.laht.threekt.core.Object3D +import info.laht.threekt.math.Matrix4 +import info.laht.threekt.math.Vector3 + +external interface View { + var enabled: Boolean + var fullwidth: Int + var fullHeight: Int + var offsetX: Int + var offsetY: Int + var width: Int + var height: Int +} + + +/** + * Creates a new Camera. Note that this class is not intended to be called directly; + * you probably want a PerspectiveCamera or OrthographicCamera instead. + */ +open external class Camera : Object3D { + + + /** + * This is the inverse of matrixWorld. MatrixWorld contains the Matrix which has the world transform of the Camera. + */ + var matrixWorldInverse: Matrix4 + /** + * /** + * This is the matrix which contains the projection. + */ + */ + var projectionMatrix: Matrix4 + + + /** + * Returns a Vector3 representing the world space direction in which the camera is looking. + * + * Note: This is not the camera’s positive, but its negative z-axis, in contrast to getWorldDirection of the base class (Object3D). + * + */ + fun getWorldDirection(): Vector3 + + /** + * Returns a Vector3 representing the world space direction in which the camera is looking. + * + * Note: This is not the camera’s positive, but its negative z-axis, in contrast to getWorldDirection of the base class (Object3D). + * + * If an optionalTarget vector is specified, the result will be copied into this vector (which can be reused in this way), + * otherwise a new vector will be created. + */ + override fun getWorldDirection(optionalTarget: Vector3): Vector3 + + override fun updateMatrixWorld(force: Boolean) + + fun clone(): Camera + fun copy(source: Camera, recursive: Boolean) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/OrthographicCamera.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/OrthographicCamera.kt new file mode 100644 index 00000000..320d71b5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/OrthographicCamera.kt @@ -0,0 +1,57 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.cameras + +external class OrthographicCamera( + varleft: Int, + right: Int, + top: Int, + bottom: Int, + near: Number = definedExternally, + far: Number = definedExternally +) : Camera { + + var zoom: Int + var view: View + + var left: Int + var right: Int + var top: Int + var bottom: Int + + var near: Double + var far: Double + + fun copy(camera: OrthographicCamera): OrthographicCamera + + fun setViewOffset(fullwidth: Int, fullHeight: Int, x: Int, y: Int, width: Int, height: Int) + fun clearViewOffset() + fun updateProjectionMatrix() + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/PerspectiveCamera.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/PerspectiveCamera.kt new file mode 100644 index 00000000..4deee300 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/cameras/PerspectiveCamera.kt @@ -0,0 +1,50 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.cameras + + +external class PerspectiveCamera(fov: Int, aspect: Double, near: Number, far: Number) : Camera { + var fov: Int + var zoom: Double + + var near: Double + var far: Double + var focus: Double + + var aspect: Double + var view: View + + var filmGauge: Int + var filmOffset: Int + + fun copy(source: PerspectiveCamera, recursive: Boolean = definedExternally) + + fun setViewOffset(fullwidth: Int, fullHeight: Int, x: Int, y: Int, width: Int, height: Int) + fun clearViewOffset() + fun updateProjectionMatrix() +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferAttribute.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferAttribute.kt new file mode 100644 index 00000000..001aa20c --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferAttribute.kt @@ -0,0 +1,207 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +import info.laht.threekt.math.Color +import info.laht.threekt.math.Vector2 +import info.laht.threekt.math.Vector3 +import info.laht.threekt.math.Vector4 + +abstract external class BufferAttribute protected constructor( + array: dynamic, + itemSize: Int, + normalized: Boolean = definedExternally +) { + + + interface UpdateRange { + /** + * Default is 0. Position at whcih to start update. + */ + var offset: Int + /** + * Default is -1, which means don't use update ranges. + + */ + var count: Int + } + + + /** + * UUID of this object instance. This gets automatically assigned and this shouldn't be edited. + */ + val uuid: String + /** + * Optional name for this attribute instance. Default is an empty string. + */ + var name: String + + var array: dynamic + /** + * The length of vectors that are being stored in the array. + */ + val itemSize: Int + /** + * Stores the array's length divided by the itemSize. + * + * If the buffer is storing a 3-component vector (such as a position, normal, or color), + * then this will count the number of such vectors stored. + */ + val count: Int + /** + * Indicates how the underlying data in the buffer maps to the values in the GLSL shader code. See the constructor above for details. + */ + var normalized: Boolean + + /** + * Whether the buffer is dynamic or not. Default is false. + * If false, the GPU is informed that contents of the buffer are likely to be used often and not change often. + * This corresponds to the glfun sTATIC_DRAW flag. + * if true, the GPU is informed that contents of the buffer are likely to be used often and change often. + * This corresponds to the gl.DYNAMIC_DRAW flag. + */ + var dynamic: Boolean + /** + * This can be used to only update some components of stored vectors ( + * for example, just the component related to color). + */ + var updateRange: UpdateRange + + /** + * Flag to indicate that this attribute has changed and should be re-sent to the GPU. Set this to true when you modify the value of the array. + * + * Setting this to true also increments the version. + */ + var needsUpdate: Boolean + + var onUploadCallback: () -> Unit + + /** + * A version number, incremented every time the needsUpdate property is set to true. + */ + val version: Int + + fun setArray(array: dynamic) + + /** + * Set dynamic to value. + */ + fun setDynamic(value: Boolean) + + /** + * Returns the w component of the vector at the given index. + */ + fun getW(index: Int): Number + + fun copy(source: BufferAttribute): BufferAttribute + /** + * Copy a vector from bufferAttribute[index2] to array[index1]. + */ + fun copyAt(index1: Int, attribute: BufferAttribute, index2: Int): BufferAttribute + + /** + * Copy an array representing Face3 indices into array. + */ + fun copyIndicesArray(indices: Array) + + /** + * Copy an array representing RGB color values into array. + */ + fun copyColorsArray(colors: Array) + + /** + * Copy an array representing Vector2s into array. + */ + fun copyVector2sArray(vectors: Array) + + /** + * Copy an array representing Vector3s into array. + */ + fun copyVector3sArray(vectors: Array) + + /** + * Copy an array representing Vector4s into array. + */ + fun copyVector4sArray(vectors: Array) + + /** + * Return a copy of this bufferAttribute. + */ + open fun clone(): BufferAttribute + + + /** + * Returns the x component of the vector at the given index. + */ + fun getX(index: Int): Number + + /** + * Returns the y component of the vector at the given index. + */ + fun getY(index: Int): Number + + /** + * Returns the z component of the vector at the given index. + */ + fun getZ(index: Int): Number + + /** + * Sets the x component of the vector at the given index. + */ + fun setX(index: Int, x: Number) + + /** + * Sets the y component of the vector at the given index. + */ + fun setY(index: Int, y: Number) + + /** + * Sets the z component of the vector at the given index. + */ + fun setZ(index: Int, z: Number) + + /** + * Sets the w component of the vector at the given index. + */ + fun setW(index: Int, w: Number) + + /** + * Sets the x, y component of the vector at the given index. + */ + fun setXY(index: Int, x: Number, y: Number) + + /** + * Sets the x, y, z component of the vector at the given index. + */ + fun setXYZ(index: Int, x: Number, y: Number, z: Number) + + /** + * Sets the x, y, z, w component of the vector at the given index. + */ + fun setXYZW(index: Int, x: Number, y: Number, z: Number, w: Number) +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt new file mode 100644 index 00000000..a4219aeb --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt @@ -0,0 +1,117 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +import info.laht.threekt.math.Box3 +import info.laht.threekt.math.Matrix4 +import info.laht.threekt.math.Sphere +import info.laht.threekt.math.Vector3 + +/** + * This class is an efficient alternative to Geometry, because it stores all data, including vertex positions, + * face indices, normals, colors, UVs, and custom attributes within buffers; this reduces the cost of passing all + * this data to the GPU. + * This also makes BufferGeometry harder to work with than Geometry; rather than accessing position data as Vector3 + * objects, color data as Color objects, and so on, you have to access the raw data from the appropriate attribute buffer. + * This makes BufferGeometry best-suited for static objects where you don't need to manipulate the geometry much + * after instantiating it. + */ +open external class BufferGeometry { + + interface DrawRange { + var start: Int + var count: Int + } + + interface Group { + var start: Int + var count: Int + var materialIndex: Int + } + + val uuid: String + val id: String + + var name: String + var type: String + + var index: dynamic + var attributes: Map + + var morphAttributes: Map + + var groups: List + + var boundingBox: Box3? + var boundingSphere: Sphere? + + var drawRange: DrawRange + + + open fun clone(): BufferGeometry + fun copy(bufferGeometry: BufferGeometry): BufferGeometry + + fun computeBoundingBox() + fun computeBoundingSphere() + + fun center(): Vector3 + + fun dispose() + fun clearGroups() + fun addGroup(start: Int, count: Int, materialIndex: Int = definedExternally) + + fun addAttribute(name: String, attribute: BufferAttribute) + fun getAttribute(name: String): BufferAttribute + fun removeAttribute(name: String): BufferGeometry + + fun setIndex(index: BufferAttribute) + fun setDrawRange(start: Int, count: Int) + + fun fromGeometry(geometry: Geometry) + fun setFromObject(`object`: Object3D): BufferGeometry + fun updateFromObject(`object`: Object3D): BufferGeometry + fun setFromPoints(points: Array): BufferGeometry + fun merge(bufferGeometry: BufferGeometry, offset: Int = definedExternally): BufferGeometry + + + fun applyMatrix(matrix: Matrix4) + fun lookAt(vector: Vector3): BufferGeometry + fun rotateX(radians: Double): BufferGeometry + fun rotateY(radians: Double): BufferGeometry + fun rotateZ(radians: Double): BufferGeometry + fun scale(x: Double, y: Double, z: Double): BufferGeometry + fun translate(x: Double, y: Double, z: Double): BufferGeometry + + + fun computeVertexNormals() + fun normalizeNormals() + fun toNonIndexed(): BufferGeometry + + fun toJSON(): Any + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Clock.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Clock.kt new file mode 100644 index 00000000..8cce902c --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Clock.kt @@ -0,0 +1,82 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +/** + * Object for keeping track of time. + * This uses performance.now() if it is available, otherwise it reverts to the less accurate Date.now(). + * @param autoStart (optional) whether to automatically start the clock. Default is true. + */ +external class Clock(autoStart: Boolean = definedExternally) { + + /** + * If set, starts the clock automatically when the first update is called. Default is true. + */ + var autoStart: Boolean + + /** + * Holds the time at which the clock's start method was last called. + */ + val startTime: Double + /** + * Holds the time at which the clock's start, getElapsedTime or getDelta methods were last called. + */ + val oldTime: Double + /** + * Keeps track of the total time that the clock has been running. + */ + val elapsedTime: Double + + /** + * Whether the clock is running or not. + */ + val running: Boolean + + /** + * Starts clock. Also sets the startTime and oldTime to the current time, sets elapsedTime to 0 and running to true. + */ + fun start() + + /** + * Stops clock and sets oldTime to the current time. + */ + fun stop() + + /** + * Get the seconds passed since the clock started and sets oldTime to the current time. + * If autoStart is true and the clock is not running, also starts the clock. + */ + fun getElapsedTime(): Double + + /** + * Get the seconds passed since the time oldTime was set and sets oldTime to the current time. + * If autoStart is true and the clock is not running, also starts the clock. + */ + fun getDelta(): Double + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/DirectGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/DirectGeometry.kt new file mode 100644 index 00000000..bae8ce28 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/DirectGeometry.kt @@ -0,0 +1,48 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +import info.laht.threekt.math.Box3 +import info.laht.threekt.math.Sphere + +external class DirectGeometry { + + var verticesNeedUpdate: Boolean + var normalsNeedUpdate: Boolean + var colorsNeedUpdate: Boolean + var uvsNeedUpdate: Boolean + var groupsNeedUpdate: Boolean + + fun computeBoundingBox(): Box3 + fun computeBoundingSphere(): Sphere + + fun dispose() + + fun fromGeometry(geometry: Geometry) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/EventDispatcher.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/EventDispatcher.kt new file mode 100644 index 00000000..459da88b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/EventDispatcher.kt @@ -0,0 +1,37 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +external open class EventDispatcher { + + fun addEventListener(type: String, listener: (dynamic) -> Unit) + fun hasEventListener(type: String, listener: (dynamic) -> Unit) + fun removeEventListener(type: String, listener: (dynamic) -> Unit) + fun dispatchEvent(event: dynamic) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Face3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Face3.kt new file mode 100644 index 00000000..ff48d022 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Face3.kt @@ -0,0 +1,68 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +import info.laht.threekt.math.Color +import info.laht.threekt.math.Vector3 + +external class Face3 { + + constructor( + a: Int, + b: Int, + c: Int, + normal: Vector3 = definedExternally, + color: Color = definedExternally, + materialIndex: Int = definedExternally + ) + + constructor( + a: Int, + b: Int, + c: Int, + normal: Array = definedExternally, + color: Array = definedExternally, + materialIndex: Int = definedExternally + ) + + var a: Int + var b: Int + var c: Int + + var normal: Vector3? + var vertexNormals: Array? + + var color: Color? + var vertexColors: Array? + + var materialIndex: Int? + + fun clone(): Face3 + fun copy(source: Face3): Face3 + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt new file mode 100644 index 00000000..518cc6d6 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt @@ -0,0 +1,109 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +import info.laht.threekt.math.* +import info.laht.threekt.objects.Mesh + +external interface MorphTarget { + val name: String + val vertices: Array +} + +external interface MorphNormal { + val name: String + val normals: Array +} + +open external class Geometry { + + val id: Int + + var vertices: Array + var colors: Array + var faces: Array + var faceVertexUvs: Array> + + var morphTargets: Array + var morphNormals: Array + + var skinWeights: Array + var skinIndices: Array + + var lineDistances: List + + var boundingBox: Box3? + var boundingSphere: Sphere? + + // update flags + + var elementsNeedUpdate: Boolean + var verticesNeedUpdate: Boolean + var uvsNeedUpdate: Boolean + var normalsNeedUpdate: Boolean + var colorsNeedUpdate: Boolean + var lineDistancesNeedUpdate: Boolean + var groupsNeedUpdate: Boolean + + fun applyMatrix(matrix: Matrix4): Geometry + fun rotateX(angle: Number): Geometry + fun rotateY(angle: Number): Geometry + fun rotateZ(angle: Number): Geometry + fun translate(x: Number, y: Number, z: Number): Geometry + fun scale(x: Number, y: Number, z: Number): Geometry + fun lookAt(vector: Vector3): Geometry + fun fromBufferGeometry(geometry: BufferGeometry): Geometry + fun addFace(a: Int, b: Int, c: Int, materialIndexOffset: Int = definedExternally) + fun center(): Vector3 + fun normalize(): Geometry + fun computeFaceNormals() + fun computeVertexNormals(areaWeighted: Boolean = definedExternally) + fun computeFlatVertexNormals() + fun computeMorphNormals() + fun computeLineDistances() + fun computeBoundingBox() + fun computeBoundingSphere() + + fun merge(geometry: Geometry, matrix: Matrix4 = definedExternally, materialIndexOffset: Int = definedExternally) + + fun mergeMesh(mesh: Mesh) + + fun mergeVertices() + + fun setFromPoint(points: Array): Geometry + + fun sortFacesByMaterialIndex() + + fun toJSON(): Any + + open fun clone(): Geometry + fun copy(geometry: Geometry): Geometry + + fun dispose() + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/InstancedBufferGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/InstancedBufferGeometry.kt new file mode 100644 index 00000000..92137432 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/InstancedBufferGeometry.kt @@ -0,0 +1,38 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +external class InstancedBufferGeometry : BufferGeometry { + + var maxInstancedCount: Int? + + fun copy(source: InstancedBufferGeometry): InstancedBufferGeometry + + override fun clone(): InstancedBufferGeometry + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt new file mode 100644 index 00000000..b33a302b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt @@ -0,0 +1,75 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +/** + * A Layers object assigns an Object3D to 1 or more of 32 layers numbered 0 to 31 - internally the + * layers are stored as a bit mask, and by default all Object3Ds are a member of layer 0. + * + * This can be used to control visibility - an object must share a layer with a camera to be visible when that + * camera's view is renderered. + * + * All classes that inherit from Object3D have an Object3D.layers property which is an instance of this class. + */ +external class Layers { + + /** + * A bit mask storing which of the 32 layers this layers object is currently a member of. + */ + var mask: Int + + /** + * Set membership to layer, and remove membership all other layers. + * @param layer layer - an integer from 0 to 31. + */ + fun set(layer: Int) + + /** + * Add membership of this layer. + * @param layer an integer from 0 to 31. + */ + fun enable(layer: Int) + + /** + * Toggle membership of layer. + * @layer - an integer from 0 to 31. + */ + fun toggle(layer: Int) + + /** + * Remove membership of this layer. + * @layer - an integer from 0 to 31. + */ + fun disable(layer: Int) + + /** + * Returns true if this and the passed layers object are members of the same set of layers. + * @param layers a Layers object + */ + fun test(layers: Int) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt new file mode 100644 index 00000000..c8b6e2a2 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt @@ -0,0 +1,328 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + + +package info.laht.threekt.core + +import info.laht.threekt.math.* + +/** + * This is the base class for most objects in three.js and provides a set of properties and methods for manipulating objects in 3D space. + * + * Note that this can be used for grouping objects via the .add( object ) method which adds the object as a child, however it is better to use Group for this. + */ +open external class Object3D { + + companion object { + val DefaultUp: Vector3 + val DefaultMatrixAutoUpdate: Boolean + } + + /** + * readonly – Unique number for this object instance. + */ + val id: Int + + /** + * UUID of this object instance. This gets automatically assigned, so this shouldn't be edited. + */ + val uuid: String + + /** + * Optional name of the object (doesn't need to be unique). Default is an empty string. + */ + var name: String + + /** + * Object's parent in the scene graph. + */ + val parent: Object3D? + /** + * Array with object's children. See Group for info on manually grouping objects. + */ + val children: Array + + /** + * This is used by the lookAt method, for example, to determine the orientation of the result. + * Default is Object3D.DefaultUp - that is, ( 0, 1, 0 ). + */ + val up: Vector3 + + /** + * A Vector3 representing the object's local position. Default is (0, 0, 0). + */ + val position: Vector3 + /** + * Object's local rotation (see Euler angles), in radians. + */ + val rotation: Euler + /** + * Object's local rotation as a Quaternion. + */ + val quaternion: Quaternion + /** + * The object's local # .scale . Default is Vector3( 1, 1, 1 ). + */ + val scale: Vector3 + /** + * This is passed to the shader and used to calculate the position of the object. + */ + val modelViewMatrix: Matrix4 + /** + * This is passed to the shader and used to calculate lighting for the object. + * It is the transpose of the inverse of the upper left 3x3 sub-matrix of this object's modelViewMatrix. + * + * The reason for this special matrix is that simply using the modelViewMatrix could result in a non-unit + * length of normals (on scaling) or in a non-perpendicular direction (on non-uniform scaling). + * + * On the other hand the translation part of the modelViewMatrix is not relevant for the calculation of normals. + * Thus a Matrix3 is sufficient. + */ + val normalMatrix: Matrix3 + + /** + * The local transform matrix. + */ + var matrix: Matrix4 + /** + * The global transform of the object. If the Object3D has no parent, then it's identical to the local transform .matrix. + */ + var matrixWorld: Matrix4 + + /** + * When this is set, it calculates the matrix of position, (rotation or quaternion) and scale every frame and + * also recalculates the matrixWorld property. Default is Object3D.DefaultMatrixAutoUpdate (true). + */ + var matrixAutoUpdate: Boolean + /** + * When this is set, it calculates the matrixWorld in that frame and resets this property to false. Default is false. + */ + var matrixWorldNeedsUpdate: Boolean + + var layers: Layers + /** + * Object gets rendered if true. Default is true. + */ + var visible: Boolean + + /** + * Whether the object gets rendered into shadow map. Default is false. + */ + var castShadow: Boolean + /** + * Whether the material receives shadows. Default is false. + */ + var receiveShadows: Boolean + + /** + * When this is set, it checks every frame if the object is in the frustum of the camera before rendering the object. + * Otherwise the object gets renderered every frame even if it isn't visible. Default is true. + */ + var frustrumCulled: Boolean + /** + * This value allows the default rendering order of scene graph objects to be overridden although opaque and transparent objects remain sorted independently. + * Sorting is from lowest to highest renderOrder. Default value is 0. + */ + var renderOrder: Int + + /** + * An object that can be used to store custom data about the Object3D. + * It should not hold references to functions as these will not be cloned. + */ + var userData: Map + + /** + * An optional callback that is executed immediately before the Object3D is rendered. + * This function is called with the following parameters: renderer, scene, camera, geometry, material, group. + */ + var onBeforeRender: () -> Unit + var onAfterRender: () -> Unit + + /** + * Applies the matrix transform to the object and updates the object's position, rotation and scale. + */ + fun applyMatrix(matrix: Matrix4) + + /** + * Applies the rotation represented by the quaternion to the object. + */ + fun applyQuaternion(q: Quaternion) + + fun setRotationFromAxisAngle(axis: Vector3, angle: Number) + fun setRotationFromEuler(euler: Euler) + fun setRotationFromMatrix(m: Matrix3) + fun setRotationFromQuaternion(q: Quaternion) + fun rotateOnAxis(axis: Vector3, angle: Number) + fun rotateOnWorldAxis(axis: Vector3, angle: Double) + fun rotateX(angle: Number) + fun rotateY(angle: Number) + fun rotateZ(angle: Number) + /** + * Translate an object by distance along an axis in object space. The axis is assumed to be normalized. + * @param axis A normalized vector in object space. + * @param distance The distance to translate. + */ + fun translateOnAxis(axis: Vector3, distance: Number) + + /** + * Translates object along x axis by distance units. + */ + fun translateX(distance: Number) + + /** + * Translates object along y axis by distance units. + */ + fun translateY(distance: Number) + + /** + * Translates object along z axis by distance units. + */ + fun translateZ(distance: Number) + + /** + * Converts the vector from local space to world space. + * @param vector A vector representing a position in local (object) space. + */ + fun localToWorld(vector: Vector3): Vector3 + + /** + * + * Updates the vector from world space to local space. + * @param vector A world vector. + */ + fun worldToLocal(vector: Vector3): Vector3 + + /** + * Rotates the object to face a point in world space. + * This method does not support objects with rotated and/or translated parent(s). + * @param v A vector representing a position in world space. + */ + fun lookAt(v: Vector3) + + /** + * Rotates the object to face a point in world space. + * This method does not support objects with rotated and/or translated parent(s). + * @param x the x component of the world space position. + * @param y the y component of the world space position. + * @param z the z component of the world space position. + */ + fun lookAt(x: Number, y: Number, z: Number) + + /** + * Adds object as child of this object. An arbitrary number of objects may be added. + */ + fun add(`object`: Object3D) + + /** + * Removes object as child of this object. An arbitrary number of objects may be removed. + */ + fun remove(`object`: Object3D) + + /** + * Searches through the object's children and returns the first with a matching id. + * Note that ids are assigned in chronological order: 1, 2, 3, ..., incrementing by one for each new object. + * @param id Unique number of the object instance + */ + fun getObjectById(id: Int): Object3D? + + /** + * Searches through the object's children and returns the first with a matching name. + * Note that for most objects the # .name is an empty string by default. You will have to set + * it manually to make use of this method. + * @param name String to match to the children's Object3D.name property. + */ + fun getObjectByName(name: String): Object3D? + + fun getObjectByProperty(name: String, value: dynamic): Object3D? + /** + * Returns a vector representing the position of the object in world space. + */ + fun getWorldPosition(optionalTarget: Vector3 = definedExternally): Vector3 + + /** + * Returns a quaternion representing the rotation of the object in world space. + */ + fun getWorldQuaternion(optionalTarget: Quaternion = definedExternally): Quaternion + + /** + * Returns the euler angles representing the rotation of the object in world space. + */ + fun getWorldRotation(optionalTarget: Euler = definedExternally): Euler + + /** + * + Returns a vector of the scaling factors applied to the object for each axis in world space. + */ + fun getWorldScale(optionalTarget: Vector3 = definedExternally): Vector3 + + /** + * Returns a vector representing the direction of object's positive z-axis in world space + */ + open fun getWorldDirection(optionalTarget: Vector3 = definedExternally): Vector3 + + /** + * Abstract (empty) method to get intersections between a casted ray and this object. + * Subclasses such as Mesh, Line, and Points implement this method in order to use raycasting. + */ + open fun raycast() + + /** + * Executes the callback on this object and all descendants. + */ + fun traverse(callback: (Object3D) -> Unit) + + /** + * Like traverse, but the callback will only be executed for visible objects. + * Descendants of invisible objects are not traversed. + */ + fun traverseVisible(callback: (Object3D) -> Unit) + + /** + * Executes the callback on all ancestors. + */ + fun traverseAncestors(callback: (Object3D) -> Unit) + + /** + * Update the local transform + */ + fun updateMatrix() + + /** + * Update the global transform of the object and its children. + */ + open fun updateMatrixWorld(force: Boolean = definedExternally) + + /** + * Convert the object to JSON format. + */ + fun toJSON(meta: String = definedExternally): Any + + open fun clone(recursive: Boolean = definedExternally): Object3D + open fun copy(source: Object3D, recursive: Boolean = definedExternally): Object3D + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Raycaster.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Raycaster.kt new file mode 100644 index 00000000..bc9e0820 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Raycaster.kt @@ -0,0 +1,69 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.math.Ray +import info.laht.threekt.math.Vector2 +import info.laht.threekt.math.Vector3 + +external interface Params { + var Mesh: dynamic + var Line: dynamic + var LOD: dynamic + var Points: dynamic + var Sprite: dynamic +} + +external interface Intersect { + var distance: Double + var distanceToRay: Double? + var point: Vector3 + var index: Int + var face: Face3? + var faceIndex: Int? + var `object`: Object3D +} + +external class Raycaster { + + constructor(origin: Vector3, direction: Vector3, near: Number, far: Number) + + var ray: Ray + var near: Double + var far: Double + + fun set(origin: Vector3, direction: Vector3): Raycaster + + fun setFromCamera(coord: Vector2, camera: Camera) + + fun intersectObject(object3D: Object3D, recursive: Boolean): List + + fun intersectObjects(objects: List, recursive: Boolean): List + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Uniform.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Uniform.kt new file mode 100644 index 00000000..a92cdf2a --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Uniform.kt @@ -0,0 +1,39 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.core + +external class Uniform { + + constructor(value: dynamic) + + var value: dynamic + + fun clone(): Uniform + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/Detector.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/Detector.kt new file mode 100644 index 00000000..716e5d74 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/Detector.kt @@ -0,0 +1,42 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external + +import org.w3c.dom.Element + +external object Detector { + + val webgl: Boolean + val canvas: Boolean + val workers: Boolean + val fileapi: Boolean + + fun getWebGLErrorMessage(): Element + fun addGetWebGLMessage(parameters: dynamic) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/ImprovedNoise.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/ImprovedNoise.kt new file mode 100644 index 00000000..bc380022 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/ImprovedNoise.kt @@ -0,0 +1,34 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external + +external object ImprovedNoise { + + fun noise(x: Double, y: Double, z: Double): Double + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/SimplexNoise.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/SimplexNoise.kt new file mode 100644 index 00000000..f8ab5a82 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/SimplexNoise.kt @@ -0,0 +1,33 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external + +external object SimplexNoise { + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/FlyControls.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/FlyControls.kt new file mode 100644 index 00000000..11e25207 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/FlyControls.kt @@ -0,0 +1,51 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three/examples/jsm/controls/FlyControls.js") +@file:JsNonModule + +package info.laht.threekt.external.controls + +import info.laht.threekt.core.Object3D +import org.w3c.dom.Node + +external class FlyControls(`object`: Object3D, domElement: Node = definedExternally) { + + var `object`: Object3D + var domElement: Node + + // API + + var movementSpeed: Double + var rollSpeed: Double + + var dragToLook: Boolean + var autoForward: Boolean + + + fun update(delta: Number) + + fun dispose() + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/OrbitControls.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/OrbitControls.kt new file mode 100644 index 00000000..db7f2ac9 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/OrbitControls.kt @@ -0,0 +1,110 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three/examples/jsm/controls/OrbitControls.js") +@file:JsNonModule + +package info.laht.threekt.external.controls + +import info.laht.threekt.core.Object3D +import info.laht.threekt.math.Vector3 +import org.w3c.dom.Node + +/** + * This set of controls performs orbiting, dollying (zooming), and panning. + * Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default). + * + * Orbit - left mouse / touch: one finger move + * Zoom - middle mouse, or mousewheel / touch: two finger spread or squish + * Pan - right mouse, or arrow keys / touch: three finger swipe + */ + +external class OrbitControls(`object`: Object3D, domElement: Node = definedExternally) { + + var `object`: Object3D + + var domElement: Node + + var enabled: Boolean + + var target: Vector3 + + var minDistance: Double + var maxDistance: Double + + var minZoom: Double + var maxZoom: Double + + /** + * How far you can orbit vertically, lower limit. + * In radians + */ + var minPolarAngle: Double + /** + * How far you can orbit vertically, upper limit. + * In radians + */ + var maxPolarAngle: Double + + var minAzimuthAngle: Double + var maxAzimuthAngle: Double + + var enableDamping: Boolean + var dampingFactor: Double + + var enableZoom: Boolean + var zoomSpeed: Double + + var enableRotate: Boolean + var rotateSpeed: Double + + var enablePan: Boolean + var keyPanSpeed: Double + + var autoRotate: Boolean + var autoRotateSpeed: Double + + var enableKeys: Boolean + + interface Keys { + var LEFT: Int + var UP: Int + var RIGHT: Int + var BOTTOM: Int + } + + var keys: Keys + + fun getPolarAngle(): Double + + fun getAzimutAngle(): Double + + fun saveState() + + fun reset() + + fun update() + + fun dispose() +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TrackballControls.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TrackballControls.kt new file mode 100644 index 00000000..b128553e --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TrackballControls.kt @@ -0,0 +1,60 @@ +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION", + "NESTED_CLASS_IN_EXTERNAL_INTERFACE" +) +@file:JsModule("three/examples/jsm/controls/TrackballControls.js") +@file:JsNonModule + +package info.laht.threekt.external.controls + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.core.EventDispatcher +import info.laht.threekt.math.Vector3 +import org.w3c.dom.HTMLElement +import org.w3c.dom.Node + +external interface `T$0` { + var left: Number + var top: Number + var width: Number + var height: Number +} + +external open class TrackballControls( + `object`: Camera, + domElement: Node = definedExternally /* null */ +) : EventDispatcher { + open var `object`: Camera + open var domElement: HTMLElement + open var enabled: Boolean + open var screen: `T$0` + open var rotateSpeed: Number + open var zoomSpeed: Number + open var panSpeed: Number + open var noRotate: Boolean + open var noZoom: Boolean + open var noPan: Boolean + open var noRoll: Boolean + open var staticMoving: Boolean + open var dynamicDampingFactor: Number + open var minDistance: Number + open var maxDistance: Number + open var keys: Array + open var target: Vector3 + open var position0: Vector3 + open var target0: Vector3 + open var up0: Vector3 + open fun update(): Unit + open fun reset(): Unit + open fun dispose(): Unit + open fun checkDistances(): Unit + open fun zoomCamera(): Unit + open fun panCamera(): Unit + open fun rotateCamera(): Unit + open fun handleResize(): Unit + open fun handleEvent(event: Any): Unit +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TransformControls.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TransformControls.kt new file mode 100644 index 00000000..0a1c7a43 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/controls/TransformControls.kt @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three/examples/jsm/controls/TransformControls.js") +@file:JsNonModule + +package info.laht.threekt.external.controls + +import info.laht.threekt.core.Object3D +import org.w3c.dom.Node + +external class TransformControls(`object`: Object3D, domElement: Node = definedExternally) : Object3D { + + var `object`: Object3D + var domElement: Node + + fun setSpace(space: String) + fun setTranslationSnap(snap: Number) + fun setRotationSnap(snap: Number) + fun setMode(mode: String) + fun setSize(size: Number) + + fun update() + fun addEventListener(event: String, listener: () -> Unit) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/OBJExporter.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/OBJExporter.kt new file mode 100644 index 00000000..36eefa9f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/OBJExporter.kt @@ -0,0 +1,36 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three/examples/jsm/exporters/OBJExporter.js") +@file:JsNonModule + +package info.laht.threekt.external.exporters + +import info.laht.threekt.core.Object3D + +external class OBJExporter { + + fun parse(`object`: Object3D): String + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/STLExporter.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/STLExporter.kt new file mode 100644 index 00000000..4c6e3fb1 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/exporters/STLExporter.kt @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three/examples/jsm/exporters/STLExporter.js") +@file:JsNonModule + +package info.laht.threekt.external.exporters + +import info.laht.threekt.core.Object3D +import org.khronos.webgl.DataView + +external class STLExporter { + + fun parse(scene: Object3D): String + +} + +external class STLBinaryExporter { + + fun parse(scene: Object3D): DataView + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/geometries/ConvexGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/geometries/ConvexGeometry.kt new file mode 100644 index 00000000..cbc0fbb5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/geometries/ConvexGeometry.kt @@ -0,0 +1,11 @@ +@file:JsModule("three/examples/jsm/geometries/ConvexGeometry.js") +@file:JsNonModule + +package info.laht.threekt.external.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.math.Vector3 + +external class ConvexGeometry(points: Array) : BufferGeometry + +external class ConvexBufferGeometry(points: Array) : BufferGeometry \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/GUIParams.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/GUIParams.kt new file mode 100644 index 00000000..13d08a29 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/GUIParams.kt @@ -0,0 +1,21 @@ +package info.laht.threekt.external.libs + +/** + * @param name The name of this GUI + * @param load JSON object representing the saved state of this GUI + * @param auto default true + * @param parent The GUI I'm nested in + * @param closed If true, starts closed + * @param closeOnTop If true, close/open button shows on top of the GUI + * @param width + */ +data class GUIParams( + var name: String? = undefined, + var auto: Boolean? = undefined, + var load: dynamic = undefined, + var parent: dat.GUI? = undefined, + var closed: Boolean? = undefined, + var closeOnTop: Boolean? = undefined, + var autoPlace: Boolean? = undefined, + var width: Int? = undefined +) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/Stats.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/Stats.kt new file mode 100644 index 00000000..a6c2e86f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/Stats.kt @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three/examples/jsm/libs/stats.module.js") +@file:JsNonModule + +package info.laht.threekt.external.libs + +import org.w3c.dom.Node + +/** + * https://github.com/mrdoob/stats.js/ + */ +external class Stats { + + val dom: Node + + fun update() + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/datgui.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/datgui.kt new file mode 100644 index 00000000..c3496ea0 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/libs/datgui.kt @@ -0,0 +1,154 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +@file:JsModule("three/examples/jsm/libs/dat.gui.module.js") +@file:JsNonModule + +package info.laht.threekt.external.libs + +import org.w3c.dom.Element + +/** + * https://github.com/dataarts/dat.gui/blob/master/src/dat/gui/val js + */ +external class dat { + + class GUI( + params: GUIParams = definedExternally + ) { + + companion object { + + val CLASS_AUTO_PLACE: String + val CLASS_AUTO_PLACE_CONTAINER: String + val CLASS_MAIN: String + val CLASS_CONTROLLER_ROW: String + val CLASS_TOO_TALL: String + val CLASS_CLOSED: String + val CLASS_CLOSE_BUTTON: String + val CLASS_CLOSE_TOP: String + val CLASS_CLOSE_BOTTOM: String + val CLASS_DRAG: String + + val DEFAULT_WIDTH: Int + val TEXT_CLOSED: String + val TEXT_OPEN: String + + fun toggleHide() + } + + val domElement: Element + val parent: GUI + val scrollable: Boolean + val autoPlace: Boolean + val closeOnTop: Boolean + var preset: String + var width: Number + var name: String + var closed: Boolean + val load: dynamic + var useLocalStorage: Boolean + + fun add(`object`: dynamic, property: String, vararg args: dynamic): Controller + + fun addColor(`object`: dynamic, property: String): ColorController + + fun destroy() + + fun addFolder(name: String): GUI + + fun open() + + fun close() + + fun onResize() + + fun remember(`object`: dynamic) + + fun getRoot(): GUI + + fun getSaveObject(): dynamic + + fun save() + + fun saveAs(presetName: String) + + fun revert(gui: GUI = definedExternally) + + fun listen(controller: Controller) + + fun updateDisplay(controller: Controller) + + } + +} + +external interface Controller { + + val initialValue: dynamic + val domElement: Element + + val `object`: dynamic + val property: String + + fun onChange(fnc: () -> Unit) + fun onFinishChange(fnc: () -> Unit) + fun setValue(newValue: dynamic): Controller + fun getValue(): dynamic + fun updateDisplay(): Controller + fun isModified(): Boolean + +} + +external interface StringController : Controller + +external interface BooleanController : Controller { + + val __checkbox: Element + val __prev: dynamic + +} + +external interface NumberController : Controller { + + val __min: Number + val __max: Number + val __step: Number + val __impliedStep: Number? + val __precision: Number? + + fun min(minValue: Number): NumberController + fun max(maxValue: Number): NumberController + fun step(step: Number): NumberController + +} + +external interface NumberControllerSlider : NumberController +external interface NumberControllerBox : NumberController + +external interface ColorController : Controller + +external interface OptionController : Controller { + val __select: Element +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/BabylonLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/BabylonLoader.kt new file mode 100644 index 00000000..2eae2988 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/BabylonLoader.kt @@ -0,0 +1,55 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +import info.laht.threekt.core.Object3D +import info.laht.threekt.loaders.LoadingManager +import org.w3c.xhr.XMLHttpRequest + +external class BabylonLoader( + manager: LoadingManager = definedExternally +) { + + /** + * Begin loading from url and call onLoad with the parsed response content. + */ + fun load( + url: String, + onLoad: (Object3D) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + /** + * Parse a JSON structure and return an object or a scene. + * Found objects are converted to Mesh with a BufferGeometry and a default MeshPhongMaterial. + * Lights are parsed accordingly. + */ + fun parse(json: String): Object3D + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/GLTFLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/GLTFLoader.kt new file mode 100644 index 00000000..e353372e --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/GLTFLoader.kt @@ -0,0 +1,61 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +import info.laht.threekt.animation.AnimationClip +import info.laht.threekt.cameras.Camera +import info.laht.threekt.loaders.LoadingManager +import info.laht.threekt.scenes.Scene +import org.khronos.webgl.ArrayBuffer +import org.w3c.xhr.XMLHttpRequest + +external interface GLTFOnLoadCallback { + val animations: Array + val scene: Scene + val scenes: Array + val cameras: Array +} + +/** + * A loader for loading glTF 2.0 resource. + * glTF (GL Transmission Format) is an open format specification for efficient delivery + * and loading of 3D content. Assets may be provided either in JSON (.gltf) or binary (.glb) format. + * External files store textures (.jpg, .png, ...) and additional binary data (.bin). + * A glTF asset may deliver one or more scenes, including meshes, materials, textures, skins, + * skeletons, morph targets, animations, lights, and/or cameras. + */ +external class GLTFLoader( + manager: LoadingManager = definedExternally +) { + + /** + * Begin loading from url and call the callback function with the parsed response content. + */ + fun load( + url: String, + onLoad: (GLTFOnLoadCallback) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + /** + * Set the base path for additional resources. + */ + fun setPath(path: String) + + fun setCrossOrigin(value: String) + + /** + * Parse a glTF-based ArrayBuffer and fire onLoad callback when complete. + * The argument to onLoad will be an object that contains loaded parts: .scene, .scenes, .cameras, and .animations. + */ + fun parse(data: ArrayBuffer, path: String, onLoad: (GLTFOnLoadCallback) -> Unit, onError: (dynamic) -> Unit) + + /** + * Parse a glTF-based JSON String and fire onLoad callback when complete. + * The argument to onLoad will be an object that contains loaded parts: .scene, .scenes, .cameras, and .animations. + */ + fun parse(data: String, path: String, onLoad: (GLTFOnLoadCallback) -> Unit, onError: (dynamic) -> Unit) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/LoaderSupport.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/LoaderSupport.kt new file mode 100644 index 00000000..de1bafcd --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/LoaderSupport.kt @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +external object LoaderSupport { + + object LoaderBase + object Validator + object ConsoleLogger + object Callbacks + object LoadedMeshUserOverride + object ResourceDescriptor + object PrepData + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/MTLLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/MTLLoader.kt new file mode 100644 index 00000000..9af877f5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/MTLLoader.kt @@ -0,0 +1,53 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +import info.laht.threekt.core.Object3D +import info.laht.threekt.loaders.LoadingManager +import org.w3c.xhr.XMLHttpRequest + +external class MTLLoader( + loadingManager: LoadingManager = definedExternally +) { + + fun load( + url: String, + onLoad: (Object3D) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: () -> Unit = definedExternally + ) + + fun setTexturePath(path: String) + fun setBaseUrl(path: String) + fun setCrossOrigin(value: String) + + fun parse(text: String): MaterialCreator + +} + +external class MaterialCreator(baseUrl: String = definedExternally) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader.kt new file mode 100644 index 00000000..ff4f2150 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader.kt @@ -0,0 +1,57 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +import info.laht.threekt.core.Object3D +import info.laht.threekt.loaders.LoadingManager +import info.laht.threekt.objects.Mesh +import org.w3c.xhr.XMLHttpRequest + +/** + * A loader for loading a .obj resource. + * The OBJ file format is a simple data-format that represents 3D geometry in a human redeable format as, + * the position of each vertex,the UV position of each texture coordinate vertex, vertex normals, + * and the faces that make each polygon defined as a list of vertices, and texture vertices. + */ +external class OBJLoader( + manager: LoadingManager = definedExternally +) { + + fun load( + url: String, + onLoad: (Mesh) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + fun setPath(value: String) + + fun parse(text: String): Object3D + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader2.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader2.kt new file mode 100644 index 00000000..009e5e81 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/OBJLoader2.kt @@ -0,0 +1,74 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +import info.laht.threekt.loaders.LoadingManager +import info.laht.threekt.objects.Mesh +import org.w3c.xhr.XMLHttpRequest + +external interface Detail { + var loaderRootNode: Mesh + var modelName: String + var instanceNo: Int +} + +external interface OBJ2OnLoadCallback { + var detail: Detail +} + +external interface LoaderProxy { + fun load( + url: String, + onLoad: (OBJ2OnLoadCallback) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally, + onMeshAlter: () -> Unit = definedExternally, + useAsync: Boolean = definedExternally + ) +} + +external class OBJLoader2( + manager: LoadingManager = definedExternally, + logger: LoaderSupport.ConsoleLogger = definedExternally +) : LoaderProxy { + + companion object { + val OBJLOADER2_VERSION: String + val LoaderBase: LoaderSupport.LoaderBase + val Validator: LoaderSupport.Validator + } + + override fun load( + url: String, + onLoad: (OBJ2OnLoadCallback) -> Unit, + onProgress: (XMLHttpRequest) -> Unit, + onError: (dynamic) -> Unit, + onMeshAlter: () -> Unit, + useAsync: Boolean + ) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/STLLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/STLLoader.kt new file mode 100644 index 00000000..707fdc0c --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/loaders/STLLoader.kt @@ -0,0 +1,46 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.loaders + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Object3D +import org.w3c.xhr.XMLHttpRequest + +external class STLLoader { + + fun load( + url: String, + onLoad: (BufferGeometry) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: () -> Unit = definedExternally + ) + + fun parse(data: String): Object3D + fun parse(data: ByteArray): Object3D + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Sky.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Sky.kt new file mode 100644 index 00000000..47ad39ef --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Sky.kt @@ -0,0 +1,32 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.objects + +import info.laht.threekt.objects.Mesh + +external class Sky : Mesh \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Water.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Water.kt new file mode 100644 index 00000000..9ad3f043 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/Water.kt @@ -0,0 +1,32 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.external.objects + +import info.laht.threekt.objects.Mesh + +external class Water(width: Int, height: Int, options: WaterOptions = definedExternally) : Mesh \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/WaterOptions.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/WaterOptions.kt new file mode 100644 index 00000000..74434846 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/external/objects/WaterOptions.kt @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package info.laht.threekt.external.objects + +import info.laht.threekt.math.Vector3 +import info.laht.threekt.textures.Texture + +data class WaterOptions( + + val textureWidth: Int? = undefined, + val textureHeight: Int? = undefined, + + val clipBias: Number? = undefined, + val alpha: Number? = undefined, + val time: Number? = undefined, + val waterNormals: Texture? = undefined, + val sunDirection: Vector3? = undefined, + val sunColor: Int? = undefined, + val waterColor: Int? = undefined, + val eye: Vector3? = undefined, + val distortionScale: Number? = undefined, + val side: Int? = undefined, + val fog: Boolean? = undefined + +) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/SceneUtils.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/SceneUtils.kt new file mode 100644 index 00000000..fb4338fd --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/SceneUtils.kt @@ -0,0 +1,44 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Object3D +import info.laht.threekt.materials.Material +import info.laht.threekt.objects.Group +import info.laht.threekt.scenes.Scene + +/** + * A class containing useful utility functions for scene manipulation. + */ +external object SceneUtils { + + /** + * Creates a new Group that contains a new mesh for each material defined in materials. Beware that this is not the same as an array of materials which defines multiple materials for 1 mesh. + * This is mostly useful for objects that need both a material and a wireframe implementation. + * @param geometry The geometry for the set of materials. + * @param materials The materials for the object. + */ + fun createMultiMaterialObject(geometry: BufferGeometry, materials: List): Group + + /** + * Detaches the object from the parent and adds it back to the scene without moving in worldspace. B + * eware that to do this the matrixWorld needs to be updated, this can be done by calling the updateMatrixWorld method on the parent object. + * @param child The object to remove from the parent + * @param parent The scene to attach the object on. + * @param scene The parent to detach the object from. + */ + fun detach(child: Object3D, parent: Object3D, scene: Scene) + + /** + * Attaches the object to the parent without the moving the object in the worldspace. + * Beware that to do this the matrixWorld needs to be updated, this can be done by calling the updateMatrixWorld method on the parent object. + * + * @param child The object to remove from the parent + * @param parent The scene to attach the object on. + * @param scene The parent to detach the object from. + */ + fun attach(child: Object3D, parent: Object3D, scene: Scene) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Curve.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Curve.kt new file mode 100644 index 00000000..f5a8ced6 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Curve.kt @@ -0,0 +1,35 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.core + + +external abstract class Curve { + + var arcLengthDivisions: Int + + fun getPoint(t: Double, optionalTarget: E = definedExternally): E + + fun getPointAt(u: Double, optionalTarget: E = definedExternally): E + + fun getPoints(divisions: Int): Array + + fun getSpacedPoints(divisions: Int): Array + + fun getLength(): Double + + fun updateArcLengths() + + fun getUtoTmapping(u: Double, distance: Double): Double + + fun getTangent(t: Double): E + + fun getTangentAt(u: Double): E + + fun computeFrenetFrames(segments: Int, closed: Boolean = definedExternally) + + open fun clone(): Curve + + fun copy(source: Curve): Curve + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/CurvePath.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/CurvePath.kt new file mode 100644 index 00000000..18ae2165 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/CurvePath.kt @@ -0,0 +1,22 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.core + + +open external class CurvePath : Curve { + + var curves: List> + + var autoClose: Boolean + + fun add(curve: Curve) + + fun closePath() + + fun getPoint(t: Double) + + override fun clone(): CurvePath + + fun copy(source: CurvePath): CurvePath +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Path.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Path.kt new file mode 100644 index 00000000..7b944a7c --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Path.kt @@ -0,0 +1,12 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.core + +import info.laht.threekt.math.Vector2 + +open external class Path : CurvePath { + + var currentPoint: Vector2 + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Shape.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Shape.kt new file mode 100644 index 00000000..0b584f1f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/Shape.kt @@ -0,0 +1,8 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.core + +import info.laht.threekt.math.Vector2 + +external class Shape(points: Array) : Path \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/ShapePath.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/ShapePath.kt new file mode 100644 index 00000000..bd6e69b9 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/core/ShapePath.kt @@ -0,0 +1,6 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.core + +external class ShapePath \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/ArcCurve.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/ArcCurve.kt new file mode 100644 index 00000000..a6f2d172 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/ArcCurve.kt @@ -0,0 +1,20 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +external class ArcCurve( + aX: Number = definedExternally, + aY: Number = definedExternally, + xRadius: Number = definedExternally, + yRadius: Number = definedExternally, + aStartAngle: Number = definedExternally, + aEndAngle: Number = definedExternally, + aClockwise: Number = definedExternally +) : EllipseCurve { + + override fun clone(): ArcCurve + fun copy(curve: ArcCurve): ArcCurve + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/CatmullRomCurve3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/CatmullRomCurve3.kt new file mode 100644 index 00000000..93a5d931 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/CatmullRomCurve3.kt @@ -0,0 +1,24 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector3 + + +external class CatmullRomCurve3( + points: Array = definedExternally, + closed: Boolean = definedExternally, + curveType: String = definedExternally, + tension: Double = definedExternally +) : Curve { + + var points: Array + var closed: Boolean + var curveType: String + var tension: Double + + override fun clone(): CatmullRomCurve3 + fun copy(curve: CatmullRomCurve3): CatmullRomCurve3 +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/EllipseCurve.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/EllipseCurve.kt new file mode 100644 index 00000000..d3ead4c5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/EllipseCurve.kt @@ -0,0 +1,37 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector2 + +open external class EllipseCurve( + aX: Number = definedExternally, + aY: Number = definedExternally, + xRadius: Number = definedExternally, + yRadius: Number = definedExternally, + aStartAngle: Number = definedExternally, + aEndAngle: Number = definedExternally, + aClockwise: Boolean = definedExternally, + aRotation: Number = definedExternally + +) : Curve { + + var aX: Double + var aY: Double + + var xRadius: Double + var yRadius: Double + + var aStartAngle: Double + var aEndAngle: Double + + var aClockwise: Boolean + + var aRotation: Double + + override fun clone(): EllipseCurve + fun copy(curve: EllipseCurve): EllipseCurve + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve.kt new file mode 100644 index 00000000..ca9dc41b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve.kt @@ -0,0 +1,17 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector2 + +external class LineCurve( + v1: Vector2 = definedExternally, + v2: Vector2 = definedExternally +) : Curve { + + override fun clone(): LineCurve + fun copy(curve: LineCurve): LineCurve + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve3.kt new file mode 100644 index 00000000..90218d60 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/LineCurve3.kt @@ -0,0 +1,18 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector3 + +external class LineCurve3( + v1: Vector3 = definedExternally, + v2: Vector3 = definedExternally +) : Curve { + + override fun clone(): LineCurve3 + fun copy(curve3: LineCurve3): LineCurve3 + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve.kt new file mode 100644 index 00000000..aa7b2a95 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve.kt @@ -0,0 +1,21 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector2 + +external class QuadricBezierCurve : Curve { + + constructor( + v0: Vector2 = definedExternally, + v1: Vector2 = definedExternally, + v2: Vector2 = definedExternally + ) + + override fun clone(): QuadricBezierCurve + fun copy(curve: QuadricBezierCurve3): QuadricBezierCurve + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve3.kt new file mode 100644 index 00000000..b4b30426 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/QuadricBezierCurve3.kt @@ -0,0 +1,21 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector3 + +external class QuadricBezierCurve3 : Curve { + + constructor( + v0: Vector3 = definedExternally, + v1: Vector3 = definedExternally, + v2: Vector3 = definedExternally + ) + + override fun clone(): QuadricBezierCurve3 + fun copy(curve: QuadricBezierCurve3): QuadricBezierCurve3 + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/SplineCurve.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/SplineCurve.kt new file mode 100644 index 00000000..df3fb8cd --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/extras/curves/SplineCurve.kt @@ -0,0 +1,18 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.extras.curves + +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector2 + +external class SplineCurve( + points: Array = definedExternally +) : Curve { + + var points: Array + + override fun clone(): SplineCurve + fun copy(curve: SplineCurve): SplineCurve + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/BoxGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/BoxGeometry.kt new file mode 100644 index 00000000..6cf5d5a7 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/BoxGeometry.kt @@ -0,0 +1,27 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + + +external class BoxGeometry( + width: Number, + height: Number, + depth: Number, + widthSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + depthSegments: Int = definedExternally +) : Geometry + + +external class BoxBufferGeometry( + width: Number, + height: Number, + depth: Number, + widthSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + depthSegments: Int = definedExternally +) : BufferGeometry diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/ConeGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/ConeGeometry.kt new file mode 100644 index 00000000..ae143fa8 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/ConeGeometry.kt @@ -0,0 +1,27 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +external class ConeGeometry( + radius: Number = definedExternally, + height: Number = definedExternally, + radialSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + openEnded: Boolean = definedExternally, + thetaStart: Boolean = definedExternally, + thetaLength: Boolean = definedExternally +) : Geometry + +external class ConeBufferGeometry( + radius: Number = definedExternally, + height: Number = definedExternally, + radialSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + openEnded: Boolean = definedExternally, + thetaStart: Boolean = definedExternally, + thetaLength: Boolean = definedExternally +) : BufferGeometry \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/CylinderGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/CylinderGeometry.kt new file mode 100644 index 00000000..a4801453 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/CylinderGeometry.kt @@ -0,0 +1,29 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +external class CylinderGeometry( + radiusTop: Number, + radiusBottom: Number, + height: Number, + radialSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + openEnded: Boolean = definedExternally, + thetaStart: Number = definedExternally, + thetaLength: Number = definedExternally +) : Geometry + +external class CylinderBufferGeometry( + radiusTop: Number, + radiusBottom: Number, + height: Number, + radialSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + openEnded: Boolean = definedExternally, + thetaStart: Number = definedExternally, + thetaLength: Number = definedExternally +) : BufferGeometry \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/EdgesGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/EdgesGeometry.kt new file mode 100644 index 00000000..8e6568da --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/EdgesGeometry.kt @@ -0,0 +1,11 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +external class EdgesGeometry(geometry: Geometry, thresholdAngle: Int = definedExternally) : BufferGeometry { + constructor(geometry: BufferGeometry, thresholdAngle: Int = definedExternally) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/PlaneGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/PlaneGeometry.kt new file mode 100644 index 00000000..ad758af4 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/PlaneGeometry.kt @@ -0,0 +1,25 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +external class PlaneGeometry( + + width: Number, + height: Number, + widthSegments: Int = definedExternally, + heightSegments: Int = definedExternally + +) : Geometry + +external class PlaneBufferGeometry( + + width: Number, + height: Number, + widthSegments: Int = definedExternally, + heightSegments: Int = definedExternally + +) : BufferGeometry \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/SphereGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/SphereGeometry.kt new file mode 100644 index 00000000..8117ff4c --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/SphereGeometry.kt @@ -0,0 +1,27 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +external class SphereGeometry( + radius: Number, + widthSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + phiStart: Number = definedExternally, + phiLength: Number = definedExternally, + thetaStart: Number = definedExternally, + thetaLength: Number = definedExternally +) : Geometry + +external class SphereBufferGeometry( + radius: Number, + widthSegments: Int = definedExternally, + heightSegments: Int = definedExternally, + phiStart: Number = definedExternally, + phiLength: Number = definedExternally, + thetaStart: Number = definedExternally, + thetaLength: Number = definedExternally +) : BufferGeometry \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TorusGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TorusGeometry.kt new file mode 100644 index 00000000..7406afb3 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TorusGeometry.kt @@ -0,0 +1,23 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +external class TorusGeometry( + radius: Number = definedExternally, + tube: Number = definedExternally, + radialSegments: Int = definedExternally, + tubularSegments: Int = definedExternally, + arc: Number = definedExternally +) : Geometry + +external class TorusBufferGeometry( + radius: Number = definedExternally, + tube: Number = definedExternally, + radialSegments: Int = definedExternally, + tubularSegments: Int = definedExternally, + arc: Number = definedExternally +) : BufferGeometry \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TubeGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TubeGeometry.kt new file mode 100644 index 00000000..38bc560a --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/TubeGeometry.kt @@ -0,0 +1,46 @@ +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry +import info.laht.threekt.extras.core.Curve +import info.laht.threekt.math.Vector3 + +/** + * Creates a tube that extrudes along a 3d curve. + */ +external class TubeGeometry( + + path: Curve, + tubularSegments: Int = definedExternally, + radius: Number = definedExternally, + radiusSegments: Int = definedExternally, + closed: Boolean = definedExternally + +) : Geometry { + + var tangents: Array + var normals: Array + var binormals: Array + +} + +/** + * Creates a tube that extrudes along a 3d curve. + */ +external class TubeBufferGeometry( + + path: Curve, + tubularSegments: Int = definedExternally, + radius: Number = definedExternally, + radiusSegments: Int = definedExternally, + closed: Boolean = definedExternally + +) : BufferGeometry { + + val parameters: dynamic + + val tangents: Array + val normals: Array + val binormals: Array + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/WireframeGeometry.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/WireframeGeometry.kt new file mode 100644 index 00000000..4c0a72ee --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/geometries/WireframeGeometry.kt @@ -0,0 +1,17 @@ +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.geometries + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Geometry + +/** + * This can be used as a helper object to view a Geometry object as a wireframe. + */ +external class WireframeGeometry : BufferGeometry { + + constructor(geometry: Geometry) + constructor(geometry: BufferGeometry) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/ArrowHelper.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/ArrowHelper.kt new file mode 100644 index 00000000..ea1764dd --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/ArrowHelper.kt @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.helpers + +import info.laht.threekt.core.Object3D +import info.laht.threekt.math.Color +import info.laht.threekt.math.Vector3 +import info.laht.threekt.objects.Line +import info.laht.threekt.objects.Mesh + +external class ArrowHelper( + dir: Vector3, + origin: Vector3, + length: Number, + color: Int = definedExternally, + headLength: Number = definedExternally, + headWidth: Number = definedExternally +) : Object3D { + + var line: Line + + var cone: Mesh + + fun setDirection(dir: Vector3) + fun setLength(length: Number, headLength: Number, headWidth: Number) + + fun setColor(color: Color) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/AxesHelper.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/AxesHelper.kt new file mode 100644 index 00000000..d4b515be --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/AxesHelper.kt @@ -0,0 +1,34 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.helpers + +import info.laht.threekt.objects.LineSegments + +external class AxesHelper( + size: Int = definedExternally +) : LineSegments \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/Box3Helper.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/Box3Helper.kt new file mode 100644 index 00000000..27aef631 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/Box3Helper.kt @@ -0,0 +1,49 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.helpers + +import info.laht.threekt.math.Box3 +import info.laht.threekt.objects.LineSegments + +/** + * Helper object to visualize a Box3. + * + * @param box the Box3 to show. + * @param color (optional) the box's color. Default is 0xffff00. + */ +external class Box3Helper( + box: Box3, + color: Int = definedExternally +) : LineSegments { + + /** + * The Box3 being visualized. + */ + var box: Box3 + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/CameraHelper.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/CameraHelper.kt new file mode 100644 index 00000000..6b199f3f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/CameraHelper.kt @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.helpers + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.objects.LineSegments + +external class CameraHelper( + camera: Camera +) : LineSegments { + + + var camera: Camera + + fun update() + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/GridHelper.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/GridHelper.kt new file mode 100644 index 00000000..0d987ae5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/GridHelper.kt @@ -0,0 +1,38 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.helpers + +import info.laht.threekt.objects.LineSegments + +external class GridHelper( + size: Int = definedExternally, + divisions: Int = definedExternally, + color1: Int = definedExternally, + color2: Int = definedExternally +) : LineSegments + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/HemisphereLightHelper.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/HemisphereLightHelper.kt new file mode 100644 index 00000000..af7333d5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/helpers/HemisphereLightHelper.kt @@ -0,0 +1,51 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.helpers + +import info.laht.threekt.core.Object3D +import info.laht.threekt.lights.HemiSphereLight +import info.laht.threekt.lights.Light + +/** + * Creates a visual aid consisting of a spherical Mesh for a HemisphereLight. + * + * @param light The light being visualized. + * @param size The size of the mesh used to visualize the light. + * @param color (optional) if this is not the set the helper will take the color of the light. + */ +external class HemisphereLightHelper( + light: HemiSphereLight, + size: Number, + color: Int = definedExternally +) : Object3D { + + var light: Light + + fun dispose() + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/ktutils.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/ktutils.kt new file mode 100644 index 00000000..a0ef343e --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/ktutils.kt @@ -0,0 +1,9 @@ +@file:Suppress("FunctionName") + +package info.laht.threekt + +import info.laht.threekt.renderers.WebGLRenderer +import info.laht.threekt.renderers.WebGLRendererParams + +fun WebGLRenderer(builder: WebGLRendererParams.() -> Unit): WebGLRenderer = + WebGLRenderer(WebGLRendererParams().apply(builder)) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/AmbientLight.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/AmbientLight.kt new file mode 100644 index 00000000..0d2cae66 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/AmbientLight.kt @@ -0,0 +1,39 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +/** + * This light globally illuminates all objects in the scene equally. + * + * This light cannot be used to cast shadows as it does not have a direction. + */ + +external class AmbientLight( + color: Int = definedExternally, + intensity: Number = definedExternally +) : Light \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLight.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLight.kt new file mode 100644 index 00000000..f85d3e24 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLight.kt @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +import info.laht.threekt.core.Object3D + +external class DirectionalLight( + color: Int = definedExternally, + intensity: Number = definedExternally +) : Light { + + var target: Object3D + + var shadow: DirectionalLightShadow + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLightShadow.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLightShadow.kt new file mode 100644 index 00000000..e2886e0b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/DirectionalLightShadow.kt @@ -0,0 +1,32 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +external class DirectionalLightShadow : LightShadow { + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/HemiSphereLight.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/HemiSphereLight.kt new file mode 100644 index 00000000..727a36a1 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/HemiSphereLight.kt @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +import info.laht.threekt.math.Color + +/** + * A light source positioned directly above the scene, with color fading from the sky color to the ground color. + * + * This light cannot be used to cast shadows. + */ +external class HemiSphereLight( + skyColor: Int = definedExternally, + groundColor: Int = definedExternally, + intensity: Number = definedExternally +) : Light { + + var groundColor: Color + + fun copy(light: HemiSphereLight): HemiSphereLight + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/Light.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/Light.kt new file mode 100644 index 00000000..6ffd9a2d --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/Light.kt @@ -0,0 +1,59 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +import info.laht.threekt.core.Object3D +import info.laht.threekt.math.Color + +/** + * Abstract base class for lights - all other light types inherit the properties and methods described here. + */ +open external class Light( + color: Int = definedExternally, + intensity: Number = definedExternally +) : Object3D { + + /** + * Color of the light. Defaults to a new Color set to white, if not passed in the constructor. + */ + var color: Color + /** + * The light's intensity, or strength. + * In physically correct mode, the product of color * intensity is interpreted as luminous intensity measured in candela. + * Default - 1.0. + */ + var intensity: Double + + var receiveShadow: Boolean? + + /** + * Copies the value of color and intensity from the source light into this one. + */ + fun copy(source: Light): Light + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/LightShadow.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/LightShadow.kt new file mode 100644 index 00000000..ef62b843 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/LightShadow.kt @@ -0,0 +1,48 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.math.Matrix4 +import info.laht.threekt.math.Vector2 + +open external class LightShadow(camera: Camera) { + + var camera: Camera + + var bias: Double + var radius: Double + + var mapSize: Vector2 + + var matrix: Matrix4 + + fun clone(): LightShadow + fun copy(source: LightShadow): LightShadow + fun toJSON(): String +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/PointLight.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/PointLight.kt new file mode 100644 index 00000000..6a708e58 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/PointLight.kt @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +external class PointLight( + color: Int = definedExternally, + intensity: Number = definedExternally +) : Light { + + var distance: Double + var decay: Double + + var shadow: LightShadow + + fun copy(source: PointLight): PointLight + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLight.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLight.kt new file mode 100644 index 00000000..70c14e6a --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLight.kt @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +import info.laht.threekt.core.Object3D + +external class SpotLight( + color: Int = definedExternally, + intensity: Number = definedExternally, + distance: Number = definedExternally, + angle: Number = definedExternally, + penumbra: Number = definedExternally, + decay: Number = definedExternally +) : Light { + + var target: Object3D + + var power: Double + + var distance: Double + var angle: Double + var penumbra: Double + var decay: Double + + var shadow: SpotLightShadow + + fun copy(source: SpotLight): SpotLight + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLightShadow.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLightShadow.kt new file mode 100644 index 00000000..8d8e052f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/lights/SpotLightShadow.kt @@ -0,0 +1,34 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.lights + +external class SpotLightShadow : LightShadow { + + fun update(light: SpotLight) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Cache.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Cache.kt new file mode 100644 index 00000000..1424d8e7 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Cache.kt @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +external object Cache { + + var enabled: Boolean + + var files: dynamic + + fun add(key: String, file: dynamic) + + fun get(key: String): dynamic + + fun remove(key: String) + + fun clear() + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/CompressedTextureLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/CompressedTextureLoader.kt new file mode 100644 index 00000000..889c5d18 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/CompressedTextureLoader.kt @@ -0,0 +1,73 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +import info.laht.threekt.textures.Texture +import org.w3c.xhr.XMLHttpRequest + +/** + * Abstract base class for block based textures loader (dds, pvr, ...). + * This uses the FileLoader internally for loading files. + * + * @param manager The loadingManager for the loader to use. Default is THREE.DefaultLoadingManager. + */ +external class CompressedTextureLoader( + manager: LoadingManager = definedExternally +) { + + /** + * The loadingManager the loader is using. Default is DefaultLoadingManager. + */ + var manager: LoadingManager + /** + * The base path from which files will be loaded. See .setPath. Default is undefined. + */ + var path: String + + /** + * Begin loading from url and pass the loaded texture to onLoad. + * + * @param url the path or URL to the file. This can also be a Data URI. + * @param onLoad Will be called when load completes. The argument will be the loaded texture. + * @param onProgress Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. + * @param onError Will be called when load errors. + */ + fun load( + url: String, + onLoad: (Texture) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + /** + * Set the base path or URL from which to load files. + * This can be useful if you are loading many textures from the same directory. + */ + fun setPath(path: String) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/ImageLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/ImageLoader.kt new file mode 100644 index 00000000..ade47d72 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/ImageLoader.kt @@ -0,0 +1,80 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +import org.w3c.dom.Element +import org.w3c.xhr.XMLHttpRequest + +/** + * A loader for loading an Image. This uses the FileLoader internally + * for loading files, and is used internally by the CubeTextureLoader, ObjectLoader and TextureLoader. + * + * @param manager The loadingManager for the loader to use. Default is THREE.DefaultLoadingManager. + * + */ +external class ImageLoader( + manager: LoadingManager = definedExternally +) { + + /** + * If set, assigns the crossOrigin attribute of the image to the value of crossOrigin, + * prior to starting the load. Default is undefined. + */ + var crossOrigin: String? + + /** + * The base path from which files will be loaded. See .setPath. Default is undefined. + */ + var path: String + + /** + * Begin loading from url and return the image object that will contain the data.. + * + * @param url the path or URL to the file. This can also be a Data URI. + * @param onLoad Will be called when load completes. The argument will be the loaded image. + * @param onProgress Will be called while load progresses. The argument will be the progress event. + * @param onError Will be called when load errors. + */ + fun load( + url: String, + onLoad: (Element) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + /** + * Set the .crossOrigin attribute. + */ + fun setCrossOrigin(value: String) + + /** + * Set the base path or URL from which to load files. This can be useful if you are loading many models from the same directory. + */ + fun setPath(path: String) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/JSONLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/JSONLoader.kt new file mode 100644 index 00000000..db38edb6 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/JSONLoader.kt @@ -0,0 +1,84 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Object3D +import info.laht.threekt.materials.Material +import org.w3c.xhr.XMLHttpRequest + +/** + * A loader for loading objects in JSON format. This uses the FileLoader internally for loading files. + * + * @param manager The loadingManager for the loader to use. Default is THREE.DefaultLoadingManager. + */ +external class JSONLoader( + manager: LoadingManager = definedExternally +) { + + /** + * The loadingManager the loader is using. Default is DefaultLoadingManager. + */ + var manager: LoadingManager + /** + * Whether the XMLHttpRequest uses credentials. Default is false. + */ + var withCredentials: Boolean + + /** + * Begin loading from url and pass the JSON to onLoad. + * @param url the path or URL to the file. This can also be a Data URI.. + * @param onLoad Will be called when load completes. The argument will be the loaded text response. + * @param onProgress Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. + * @param onError Will be called when load errors. + */ + fun load( + url: String, + onLoad: (Object3D) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + /** + * Set the base path or URL from which to load files. This can be useful if you are loading many files from the same directory. + */ + fun setTexturePath(value: String) + + interface ParsedObject { + val geometry: BufferGeometry + val materials: Array + } + + /** + * Parse a JSON structure and return an object containing the parsed geometry and materials. + * @param json JSON object to parse. + * @param texturePath Base path for textures. + */ + fun parse(json: Any, texturePath: String): ParsedObject + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Loader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Loader.kt new file mode 100644 index 00000000..2d60ee93 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/Loader.kt @@ -0,0 +1,46 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +/** + * Base class for implementing loaders. + */ +external class Loader { + + object Handlers { + fun add(regex: String, loader: Loader) + fun get(file: dynamic): Loader + } + + var onLoadStart: () -> Unit + var onLoadProgress: () -> Unit + var onLoadComplete: () -> Unit + + var crossOrigin: String? + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/LoadingManager.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/LoadingManager.kt new file mode 100644 index 00000000..ebf5d2bc --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/LoadingManager.kt @@ -0,0 +1,49 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +external object DefaultLoadingManager : LoadingManager + +/** + * Handles and keeps track of loaded and pending data. A default global instance of this class is created and + * used by loaders if not supplied manually - see DefaultLoadingManager. + * + * In general that should be sufficient, however there are times when it can be useful to have + * seperate loaders - for example if you want to show seperate loading bars for objects and textures. + */ +open external class LoadingManager( + onLoad: () -> Unit, + onProgress: () -> Unit = definedExternally, + onError: () -> Unit = definedExternally +) { + + var onStart: () -> Unit + var onLoad: () -> Unit + var onProgress: () -> Unit + var onError: () -> Unit +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/MaterialLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/MaterialLoader.kt new file mode 100644 index 00000000..ef30c71f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/MaterialLoader.kt @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +import info.laht.threekt.materials.Material +import info.laht.threekt.textures.Texture +import org.w3c.xhr.XMLHttpRequest + +external class MaterialLoader { + + fun load( + url: String, + onLoad: (Material) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ) + + fun parse(json: String): Material + + fun setTextures(textures: Map) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/TextureLoader.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/TextureLoader.kt new file mode 100644 index 00000000..5d57ab88 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/loaders/TextureLoader.kt @@ -0,0 +1,84 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.loaders + +import info.laht.threekt.textures.Texture +import org.w3c.xhr.XMLHttpRequest + +/** + * Class for loading a texture. This uses the ImageLoader internally for loading files. + */ +external class TextureLoader { + + constructor(manager: LoadingManager = definedExternally) + + /** + * If set, assigns the crossOrigin attribute of the image to the value of crossOrigin, + * prior to starting the load. Default is undefined. + */ + var crossOrigin: String? + + /** + * The loadingManager the loader is using. Default is DefaultLoadingManager. + */ + var manager: LoadingManager + + /** + * The base path from which files will be loaded. See .setPath. Default is undefined. + */ + var path: String? + + /** + * Begin loading from the given URL and pass the fully loaded texture to onLoad. + * The method also returns a new texture object which can directly be used for material creation. + * If you do it this way, the texture may pop up in your scene once the respective loading process is finished. + * + * @param url the path or URL to the file. This can also be a Data URI. + * @param onLoad Will be called when load completes. The argument will be the loaded texture. + * @param onProgress Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. + * @param onError Will be called when load errors. + */ + fun load( + url: String, + onLoad: (Texture) -> Unit, + onProgress: (XMLHttpRequest) -> Unit = definedExternally, + onError: (dynamic) -> Unit = definedExternally + ): Texture + + /** + * Set the .crossOrigin attribute. + */ + fun setCrossOrigin(value: String) + + /** + * Set the base path or URL from which to load files. This can be useful if you are loading many models from the same directory. + */ + fun setPath(path: String) + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineBasicMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineBasicMaterial.kt new file mode 100644 index 00000000..308e5a52 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineBasicMaterial.kt @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color + + +open external class LineBasicMaterial : Material { + + var color: Color + + var linewidth: Double + var linecap: String + var linejoin: String + + override fun clone(): LineBasicMaterial + fun copy(material: LineBasicMaterial): LineBasicMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineDashedMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineDashedMaterial.kt new file mode 100644 index 00000000..79ad5ada --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/LineDashedMaterial.kt @@ -0,0 +1,39 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +external class LineDashedMaterial : LineBasicMaterial { + + var scale: Double + var dashSize: Double + var gapSize: Double + + override fun clone(): LineDashedMaterial + fun copy(lineDashedMaterial: LineDashedMaterial): LineDashedMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/Material.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/Material.kt new file mode 100644 index 00000000..3950c963 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/Material.kt @@ -0,0 +1,130 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +@JsName("Material") +open external class Material { + + /** + * Unique number for this material instance. + */ + val id: Int + + var uuid: String + /** + * Optional name of the object (doesn't need to be unique). Default is an empty string. + */ + var name: String + var type: String + + /** + * Whether the material is affected by fog. Default is true. + */ + var fog: Boolean + var lights: Boolean + + var blending: Int + var side: Int + var flatShading: Boolean + var vertexColors: Int + + /** + * Double in the range of 0.0 - 1.0 indicating how transparent the material is. A value of 0.0 indicates fully transparent, 1.0 is fully opaque. + If the material's # .transparent property is not set to true, the material will remain fully opaque and this value will only affect its color. + Default is 1.0. + */ + var opacity: Double + var transparent: Boolean + + var blendSrc: Int + /** + * Blending destination. Default is OneMinusSrcAlphaFactor. See the destination factors constants for all possible values. + The material's # .blending must be set to CustomBlending for this to have any effect. + */ + var blendDst: Int + /** + * Blending equation to use when applying blending. Default is AddEquation. See the blending equation constants for all possible values. + The material's # .blending must be set to CustomBlending for this to have any effect. + */ + var blendEquation: Int + var blendSrcAlpha: Int + /** + * The tranparency of the .blendDst. Default is null. + */ + var blendDstAlpha: Int? + var blendEquationAlpha: Int + + + var depthFunc: Int + var depthTest: Boolean + var depthWrite: Boolean + + var colorWrite: Boolean + + var precision: String? + + /** + * Sets the polygon offset factor. Default is 0. + */ + var polygonOffset: Boolean + var polygonOffsetFactor: Number + /** + * Sets the polygon offset units. Default is 0. + */ + var polygonOffsetUnits: Number + + var dithering: Boolean + + /** + * Sets the alpha value to be used when running an alpha test. + * The material will not be renderered if the opacity is lower than this value. Default is 0. + */ + var alphaTest: Double + var premultipliedAlpha: Boolean + + var overdraw: Double + + var visible: Boolean + + var userData: Map + + /** + * Specifies that the material needs to be updated at the WebGL level. Set it to true if you made changes that need to be reflected in WebGL. + This property is automatically set to true when instancing a new material. + */ + var needsUpdate: Boolean + + + fun toJSON(meta: String = definedExternally): String + + open fun clone(): Material + fun copy(material: Material): Material + + fun dispose() + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshBasicMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshBasicMaterial.kt new file mode 100644 index 00000000..96eae5e0 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshBasicMaterial.kt @@ -0,0 +1,67 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color +import info.laht.threekt.textures.Texture + + +external class MeshBasicMaterial : Material { + + var color: Color + + var map: Texture? + + var lightMap: Texture? + var lightMapIntensity: Double + + var aoMap: Texture + var aoMapIntensity: Double + + var specularMap: Texture? + + var alphaMap: Texture? + + var envMap: Texture? + var combine: Int + var reflectivity: Double + var refractionRatio: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + var wireframeLinecap: String + var wireframeLinejoin: String + + var skinning: Boolean + var morphTargets: Boolean + + + override fun clone(): MeshBasicMaterial + fun copy(source: MeshBasicMaterial): MeshBasicMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshDepthMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshDepthMaterial.kt new file mode 100644 index 00000000..185dce93 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshDepthMaterial.kt @@ -0,0 +1,55 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.textures.Texture + +external class MeshDepthMaterial : Material { + + var depthPacking: Int + + var skinning: Boolean + var morphTargets: Boolean + + var map: Texture? + + var alphaMap: Texture? + + var displacementMap: Texture? + var displacementScale: Double + var displacementBias: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + + + override fun clone(): MeshDepthMaterial + fun copy(material: MeshDepthMaterial): MeshDepthMaterial + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshLambertMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshLambertMaterial.kt new file mode 100644 index 00000000..dcd0670a --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshLambertMaterial.kt @@ -0,0 +1,70 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color +import info.laht.threekt.textures.Texture + +external class MeshLambertMaterial : Material { + + var color: Color + + var map: Texture? + + var lightMap: Texture? + var lightMapIntensity: Double + + var aoMap: Texture? + var aoMapIntensity: Double + + var emissive: Color + var emissiveIntensity: Double + var emissiveMap: Texture? + + var specularMap: Texture? + + var alphaMap: Texture? + + var envMap: Texture? + var combine: Int + var reflectivity: Double + var refractionRatio: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + var wireframeLinecap: String + var wireframeLinejoin: String + + var skinning: Boolean + var morphTargets: Boolean + var morphNormals: Boolean + + override fun clone(): MeshLambertMaterial + fun copy(material: MeshLambertMaterial): MeshLambertMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshNormalMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshNormalMaterial.kt new file mode 100644 index 00000000..ea7c0960 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshNormalMaterial.kt @@ -0,0 +1,56 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Vector2 +import info.laht.threekt.textures.Texture + +external class MeshNormalMaterial : Material { + + var bumpMap: Texture? + var bumpScale: Texture? + + var normalMap: Texture? + var normalScale: Vector2 + + var displacementMap: Texture? + var displacementScale: Double + var displacementBias: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + + var skinning: Boolean + var morphTargets: Boolean + var morphNormals: Boolean + + override fun clone(): MeshNormalMaterial + fun copy(material: MeshNormalMaterial): MeshNormalMaterial + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhongMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhongMaterial.kt new file mode 100644 index 00000000..693ba8b4 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhongMaterial.kt @@ -0,0 +1,86 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color +import info.laht.threekt.math.Vector2 +import info.laht.threekt.textures.Texture + + +external class MeshPhongMaterial : Material { + + var color: Color + var specular: Color + var shininess: Double + + var map: Texture? + + var lightMap: Texture? + var lightMapIntensity: Double + + var aoMap: Texture? + var aoMapIntensity: Double + + var emissive: Color + var emissiveIntensity: Double + var emissiveMap: Texture? + + var bumpMap: Texture? + var bumpScale: Double + + var normalMap: Texture? + var normalScale: Vector2 + + var displacementMap: Texture? + var displacementScale: Double + var displacementBias: Double + + var specularMap: Texture? + + var alphaMap: Texture? + + var envMap: Texture? + var combine: Int + var reflectivity: Double + var refractionRatio: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + var wireframeLinecap: String + var wireframeLinejoin: String + + var skinning: Boolean + var morphTargets: Boolean + var morphNormals: Boolean + + override fun clone(): MeshPhongMaterial + fun copy(source: MeshPhongMaterial): MeshPhongMaterial + + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhysicalMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhysicalMaterial.kt new file mode 100644 index 00000000..42fef98f --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshPhysicalMaterial.kt @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +external class MeshPhysicalMaterial : MeshStandardMaterial { + + var reflectivity: Double + + var clearCoat: Double + var clearCoatRoughness: Int + + override fun clone(): MeshPhysicalMaterial + fun copy(source: MeshPhysicalMaterial): MeshPhysicalMaterial + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshStandardMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshStandardMaterial.kt new file mode 100644 index 00000000..19b6901e --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/MeshStandardMaterial.kt @@ -0,0 +1,86 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color +import info.laht.threekt.math.Vector2 +import info.laht.threekt.textures.Texture + +open external class MeshStandardMaterial : Material { + + var color: Color + + var roughness: Double + var metalness: Double + + var map: Texture? + + var lightMap: Texture? + var lightMapIntensity: Double + + var aoMap: Texture? + var aoMapIntensity: Double + + var emissive: Color + var emissiveIntensity: Double + var emissiveMap: Texture? + + var bumpMap: Texture? + var bumpScale: Double + + var normalMap: Texture? + var normalScale: Vector2 + + var displacementMap: Texture? + var displacementScale: Double + var displacementBias: Double + + var roughnessMap: Texture? + + var metalnessMap: Texture? + + var alphaMap: Texture? + + var envMap: Texture? + var envMapIntensity: Double + + var refractionRatio: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + var wireframeLinecap: String + var wireframeLinejoin: String + + var skinning: Boolean + var morphTargets: Boolean + var morphNormals: Boolean + + override fun clone(): MeshStandardMaterial + fun copy(meshBasicMaterial: MeshBasicMaterial): MeshBasicMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/PointsMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/PointsMaterial.kt new file mode 100644 index 00000000..bb9c4bd8 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/PointsMaterial.kt @@ -0,0 +1,45 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color +import info.laht.threekt.textures.Texture + +external class PointsMaterial : Material { + + var color: Color + + var map: Texture? + + var size: Number + var sizeAttentuation: Boolean + + override fun clone(): PointsMaterial + fun copy(material: PointsMaterial): PointsMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/RawShaderMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/RawShaderMaterial.kt new file mode 100644 index 00000000..2a096459 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/RawShaderMaterial.kt @@ -0,0 +1,35 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +external class RawShaderMaterial : ShaderMaterial { + + override fun clone(): RawShaderMaterial + fun copy(material: RawShaderMaterial): RawShaderMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/ShaderMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/ShaderMaterial.kt new file mode 100644 index 00000000..016520eb --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/ShaderMaterial.kt @@ -0,0 +1,65 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +open external class ShaderMaterial : Material { + + var defines: dynamic + var uniforms: dynamic + + var vertexShader: String + var fragmentShader: String + var linewidth: Double + + var wireframe: Boolean + var wireframeLinewidth: Double + + var clipping: Boolean + + var skinning: Boolean + var morphTargets: Boolean + var morphNormals: Boolean + + + interface Extensions { + var derivatives: Boolean + var fragDepth: Boolean + var drawBuffers: Boolean + var shaderTextureLOD: Boolean + } + + + var extensions: Extensions + + var index0AttributeName: String + + override fun clone(): ShaderMaterial + fun copy(material: ShaderMaterial): ShaderMaterial + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/SpriteMaterial.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/SpriteMaterial.kt new file mode 100644 index 00000000..32056537 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/materials/SpriteMaterial.kt @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.materials + +import info.laht.threekt.math.Color +import info.laht.threekt.textures.Texture + +external class SpriteMaterial : Material { + + var color: Color + + var map: Texture? + + var rotation: Double + + override fun clone(): SpriteMaterial + fun copy(material: SpriteMaterial): SpriteMaterial + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box2.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box2.kt new file mode 100644 index 00000000..c00da8eb --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box2.kt @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Box2( + min: Vector2 = definedExternally, + max: Vector2 = definedExternally +) { + + var min: Vector2 + var max: Vector2 + + fun set(min: Vector2, max: Vector2): Box2 + + fun clone(): Box2 + fun copy(box: Box2): Box2 + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box3.kt new file mode 100644 index 00000000..a34622fa --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Box3.kt @@ -0,0 +1,162 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +import info.laht.threekt.core.Object3D + +/** + * Represents a box or cube in 3D space. The main purpose of this is to represent the Minimum Bounding Boxes for objects. + * + * @param min (optional) Vector3 representing the lower (x, y, z) boundary of the box. Default is ( + Infinity, + Infinity, + Infinity ). + * @param max (optional) Vector3 representing the lower upper (x, y, z) boundary of the box. Default is ( - Infinity, - Infinity, - Infinity ). + */ +external class Box3( + min: Vector3 = definedExternally, + max: Vector3 = definedExternally +) { + + /** + * Vector3 representing the lower (x, y, z) boundary of the box. + * Default is ( + Infinity, + Infinity, + Infinity ). + */ + var min: Vector3 + /** + * Vector3 representing the lower upper (x, y, z) boundary of the box. + * Default is ( - Infinity, - Infinity, - Infinity ). + */ + var max: Vector3 + + val isBox3: Boolean + + /** + * Sets the lower and upper (x, y, z) boundaries of this box. + */ + fun set(min: Vector3, max: Vector3): Box3 + + /** + * Sets the upper and lower bounds of this box to include all of the data in array. + * @param array An array of position data that the resulting box will envelop. + */ + fun setFromArray(array: DoubleArray): Box3 + + fun setFromPoints(points: List): Box3 + + /** + * Centers this box on center and sets this box's width and height to the values specified in size. + * @param center - Desired center position of the box (Vector3). + * @param size - Desired x, y and z dimensions of the box (Vector3). + */ + fun setFromCenterAndSize(center: Vector3, size: Vector3): Box3 + + /** + * Computes the world-axis-aligned bounding box of an Object3D (including its children), + * accounting for the object's, and children's, world transforms. + * @param `object` Object3D to compute the bounding box of. + */ + fun setFromObject(`object`: Object3D): Box3 + + /** + * Makes this box empty. + */ + fun makeEmpty(): Box3 + + /** + * Returns true if this box includes zero points within its bounds. + Note that a box with equal lower and upper bounds still includes one point, the one both bounds share. + */ + fun isEmpty(): Boolean + + fun getCenter(optionalTarget: Vector3 = definedExternally): Vector3 + + fun getSize(optionalTarget: Vector3 = definedExternally): Vector3 + + fun expandByPoint(point: Vector3): Box3 + + fun expandByVector(vector: Vector3): Box3 + + fun expandByScalar(scalar: Number): Box3 + + fun expandByObject(`object`: Object3D): Box3 + + fun containsPoint(point: Vector3): Boolean + + fun containsBox(box: Box3): Boolean + + fun intersectsBox(box: Box3): Boolean + + fun intersectsSphere(sphere: Sphere): Boolean + + fun intersectsPlane(plane: Plane): Boolean + + fun clampPoint(point: Vector3, optionalTarget: Vector3 = definedExternally): Vector3 + + fun distanceToPoint(point: Vector3): Double + + /** + * Gets a Sphere that bounds the box. + * @param optionalTarget (optional) if specified, the result will be copied into this Sphere, otherwise a new Sphere will be created. + */ + fun getBoundingSphere(optionalTarget: Sphere = definedExternally): Sphere + + fun intersect(box: Box3): Box3 + + /** + * Unions this box with box, setting the upper bound of this box to the greater of the two boxes' + * upper bounds and the lower bound of this box to the lesser of the two boxes' lower bounds. + * @param box Box that will be unioned with this box. + */ + fun union(box: Box3): Box3 + + /** + * Transforms this Box3 with the supplied matrix. + * @param matrix The Matrix4 to apply + */ + fun applyMatrix4(matrix: Matrix4): Box3 + + fun translate(offset: Vector3): Box3 + + /** + * Returns true if this box and box share the same lower and upper bounds. + * @param box Box to compare with this one. + */ + fun equals(box: Box3): Boolean + + /** + * Returns a new Box3 with the same min and max as this one. + */ + fun clone(): Box3 + + /** + * Copies the min and max from box to this box. + * @param box Box3 to copy. + */ + fun copy(box: Box3): Box3 + + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Color.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Color.kt new file mode 100644 index 00000000..26a2a760 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Color.kt @@ -0,0 +1,58 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + + +external class Color { + + constructor() + constructor(string: String) + constructor(hex: Int) + constructor(color: Color) + constructor(r: Number, g: Number, b: Number) + + var r: Double + var g: Double + var b: Double + + fun set(value: Color): Color + fun set(value: Int): Color + fun set(value: String): Color + + fun setScalar(scalar: Double): Color + fun setHex(hex: Int): Color + fun setRGB(r: Number, g: Number, b: Number): Color + fun setHSL(h: Number, s: Number, l: Number): Color + + fun clone(): Color + fun copy(color: Color): Color + + fun getHex(): Int + fun getHexString(): String + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/ColorConstants.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/ColorConstants.kt new file mode 100644 index 00000000..34475bd1 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/ColorConstants.kt @@ -0,0 +1,203 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +package info.laht.threekt.math + +object ColorConstants { + + val aliceblue = 0xF0F8FF + val antiquewhite = 0xFAEBD7 + val aqua = 0x00FFFF + val aquamarine = 0x7FFFD4 + val azure = 0xF0FFFF + + val beige = 0xF5F5DC + val bisque = 0xFFE4C4 + val black = 0x000000 + val blanchedalmond = 0xFFEBCD + val blue = 0x0000FF + val blueviolet = 0x8A2BE2 + + val brown = 0xA52A2A + val burlywood = 0xDEB887 + val cadetblue = 0x5F9EA0 + val chartreuse = 0x7FFF00 + val chocolate = 0xD2691E + val coral = 0xFF7F50 + + val cornflowerblue = 0x6495ED + val cornsilk = 0xFFF8DC + val crimson = 0xDC143C + val cyan = 0x00FFFF + val darkblue = 0x00008B + val darkcyan = 0x008B8B + + val darkgoldenrod = 0xB8860B + val darkgray = 0xA9A9A9 + val darkgreen = 0x006400 + val darkgrey = 0xA9A9A9 + val darkkhaki = 0xBDB76B + val darkmagenta = 0x8B008B + + val darkolivegreen = 0x556B2F + val darkorange = 0xFF8C00 + val darkorchid = 0x9932CC + val darkred = 0x8B0000 + val darksalmon = 0xE9967A + val darkseagreen = 0x8FBC8F + + val darkslateblue = 0x483D8B + val darkslategray = 0x2F4F4F + val darkslategrey = 0x2F4F4F + val darkturquoise = 0x00CED1 + val darkviolet = 0x9400D3 + + val deeppink = 0xFF1493 + val deepskyblue = 0x00BFFF + val dimgray = 0x696969 + val dimgrey = 0x696969 + val dodgerblue = 0x1E90FF + val firebrick = 0xB22222 + + val floralwhite = 0xFFFAF0 + val forestgreen = 0x228B22 + val fuchsia = 0xFF00FF + val gainsboro = 0xDCDCDC + val ghostwhite = 0xF8F8FF + val gold = 0xFFD700 + + val goldenrod = 0xDAA520 + val gray = 0x808080 + val green = 0x008000 + val greenyellow = 0xADFF2F + val grey = 0x808080 + val honeydew = 0xF0FFF0 + val hotpink = 0xFF69B4 + + val indianred = 0xCD5C5C + val indigo = 0x4B0082 + val ivory = 0xFFFFF0 + val khaki = 0xF0E68C + val lavender = 0xE6E6FA + val lavenderblush = 0xFFF0F5 + val lawngreen = 0x7CFC00 + + val lemonchiffon = 0xFFFACD + val lightblue = 0xADD8E6 + val lightcoral = 0xF08080 + val lightcyan = 0xE0FFFF + val lightgoldenrodyellow = 0xFAFAD2 + val lightgray = 0xD3D3D3 + + val lightgreen = 0x90EE90 + val lightgrey = 0xD3D3D3 + val lightpink = 0xFFB6C1 + val lightsalmon = 0xFFA07A + val lightseagreen = 0x20B2AA + val lightskyblue = 0x87CEFA + + val lightslategray = 0x778899 + val lightslategrey = 0x778899 + val lightsteelblue = 0xB0C4DE + val lightyellow = 0xFFFFE0 + val lime = 0x00FF00 + val limegreen = 0x32CD32 + + val linen = 0xFAF0E6 + val magenta = 0xFF00FF + val maroon = 0x800000 + val mediumaquamarine = 0x66CDAA + val mediumblue = 0x0000CD + val mediumorchid = 0xBA55D3 + + val mediumpurple = 0x9370DB + val mediumseagreen = 0x3CB371 + val mediumslateblue = 0x7B68EE + val mediumspringgreen = 0x00FA9A + val mediumturquoise = 0x48D1CC + + val mediumvioletred = 0xC71585 + val midnightblue = 0x191970 + val mintcream = 0xF5FFFA + val mistyrose = 0xFFE4E1 + val moccasin = 0xFFE4B5 + val navajowhite = 0xFFDEAD + + val navy = 0x000080 + val oldlace = 0xFDF5E6 + val olive = 0x808000 + val olivedrab = 0x6B8E23 + val orange = 0xFFA500 + val orangered = 0xFF4500 + val orchid = 0xDA70D6 + + val palegoldenrod = 0xEEE8AA + val palegreen = 0x98FB98 + val paleturquoise = 0xAFEEEE + val palevioletred = 0xDB7093 + val papayawhip = 0xFFEFD5 + val peachpuff = 0xFFDAB9 + val + peru = 0xCD853F + val pink = 0xFFC0CB + val plum = 0xDDA0DD + val powderblue = 0xB0E0E6 + val purple = 0x800080 + val rebeccapurple = 0x663399 + val red = 0xFF0000 + val rosybrown = 0xBC8F8F + + val royalblue = 0x4169E1 + val saddlebrown = 0x8B4513 + val salmon = 0xFA8072 + val sandybrown = 0xF4A460 + val seagreen = 0x2E8B57 + val seashell = 0xFFF5EE + + val sienna = 0xA0522D + val silver = 0xC0C0C0 + val skyblue = 0x87CEEB + val slateblue = 0x6A5ACD + val slategray = 0x708090 + val slategrey = 0x708090 + val snow = 0xFFFAFA + + val springgreen = 0x00FF7F + val steelblue = 0x4682B4 + val tan = 0xD2B48C + val teal = 0x008080 + val thistle = 0xD8BFD8 + val tomato = 0xFF6347 + val turquoise = 0x40E0D0 + + val violet = 0xEE82EE + val wheat = 0xF5DEB3 + val white = 0xFFFFFF + val whitesmoke = 0xF5F5F5 + val yellow = 0xFFFF00 + val yellowgreen = 0x9ACD32 + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Cylindrical.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Cylindrical.kt new file mode 100644 index 00000000..9e0cd8ba --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Cylindrical.kt @@ -0,0 +1,46 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Cylindrical( + radius: Number, + theta: Number, + y: Number +) { + + var radius: Double + var theta: Double + var y: Double + + fun set(radius: Number, theta: Number, y: Number): Cylindrical + fun clone(): Cylindrical + fun copy(cylindrical: Cylindrical): Cylindrical + fun setFromVector3(vector3: Vector3): Cylindrical + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Euler.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Euler.kt new file mode 100644 index 00000000..5b8dc1ce --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Euler.kt @@ -0,0 +1,74 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + + +external class Euler( + x: Number = definedExternally, + y: Number = definedExternally, + z: Number = definedExternally, + order: String = definedExternally +) { + + companion object { + val RotationOrders: Array + var DefaultOrder: String + } + + var x: Double + var y: Double + var z: Double + + var order: String + + fun set(x: Number, y: Number, z: Number, order: String = definedExternally): Euler + + fun clone(): Euler + fun copy(euler: Euler): Euler + + fun setFromRotationMatrix(m: Matrix4, order: String = definedExternally, update: Boolean = definedExternally): Euler + + fun setFromQuaternion(q: Quaternion, order: String = definedExternally, update: Boolean = definedExternally) + + fun setFromVector3(v: Vector3, order: String = definedExternally): Euler + + fun reorder(order: String): Euler + + fun equals(euler: Euler): Boolean + + fun fromArray(array: DoubleArray): Euler + + fun toArray(array: DoubleArray = definedExternally, offset: Int = definedExternally): DoubleArray + + fun toVector3(optionalResult: Vector3 = definedExternally): Vector3 + + fun onChange(callback: () -> Unit) + + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Frustrum.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Frustrum.kt new file mode 100644 index 00000000..cce6a0bc --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Frustrum.kt @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Frustrum( + p0: Plane = definedExternally, + p1: Plane = definedExternally, + p2: Plane = definedExternally, + p3: Plane = definedExternally, + p4: Plane = definedExternally +) { + + fun set(p0: Plane, p1: Plane, p2: Plane, p3: Plane, p4: Plane): Frustrum + + fun clone(): Frustrum + fun copy(frustrum: Frustrum): Frustrum + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Line3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Line3.kt new file mode 100644 index 00000000..6bb1b4e2 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Line3.kt @@ -0,0 +1,60 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Line3( + start: Vector3 = definedExternally, + end: Vector3 = definedExternally +) { + + var start: Vector3 + var end: Vector3 + + fun set(start: Vector3, end: Vector3): Line3 + + fun clone(): Line3 + fun copy(line: Line3): Line3 + + fun getCenter(optionalTarget: Vector3 = definedExternally): Vector3 + + fun delta(optionalTarget: Vector3): Vector3 + + fun distanceSq(): Double + + fun distance(): Double + + fun at(t: Number, optionalTarget: Vector3): Vector3 + + fun closestPointToPointParameter(point: Vector3, clampToLine: Boolean = definedExternally): Double + + fun closestPointToPoint(point: Vector3, clampToLine: Boolean, optionalTarget: Vector3 = definedExternally): Vector3 + + fun applyMatrix4(matrix: Matrix4): Matrix4 + + fun equals(line: Line3): Boolean +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Math.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Math.kt new file mode 100644 index 00000000..9bae9dba --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Math.kt @@ -0,0 +1,52 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + + +external class Math { + + companion object { + + val DEG2RAD: Double + val RAD2DEG: Double + + fun generateUUID(): String + + fun clamp(value: Int, min: Int, max: Int): Int + fun clamp(value: Double, min: Double, max: Double): Double + + fun mapLinear(x: Double, a1: Double, a2: Double, b1: Double, b2: Double): Double + + fun lerp(x: Double, y: Double, t: Double): Double + + fun degToRad(deegrees: Double): Double + fun radToDeg(radians: Double): Double + + } + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix3.kt new file mode 100644 index 00000000..6f31380b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix3.kt @@ -0,0 +1,82 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +import info.laht.threekt.core.BufferAttribute + +external class Matrix3 { + + var elements: DoubleArray + + fun set( + n11: Number, n12: Number, n13: Number, + n21: Number, n22: Number, n23: Number, + n31: Number, n32: Number, n33: Number + ): Matrix3 + + fun identity(): Matrix3 + + fun clone(): Matrix3 + fun copy(m: Matrix3): Matrix3 + + fun setFromMatrix4(m: Matrix4): Matrix3 + + fun applyToBufferAttribute(attribute: BufferAttribute) + + fun multiply(m: Matrix3): Matrix3 + + fun premultiply(m: Matrix3): Matrix3 + + fun multiplyMatrices(a: Matrix3, b: Matrix3): Matrix3 + + fun multiplyScalar(s: Number): Matrix3 + + fun determinant(): Double + + fun getInverse(matrix: Matrix3, throwOnDegenerate: Boolean = definedExternally): Matrix3 + + fun transpose(): Matrix3 + + fun getNormalMatrix(matrix4: Matrix4): Matrix3 + + fun transposeIntoArray(r: DoubleArray): Matrix3 + + fun setUvTransform(tx: Number, ty: Number, sx: Number, sy: Number, rotation: Number, cx: Number, cy: Number) + + fun scale(sx: Number, sy: Number): Matrix3 + + fun rotate(theta: Number): Matrix3 + fun translate(tx: Number, ty: Number): Matrix3 + + fun equals(matrix: Matrix3): Boolean + + fun fromArray(array: DoubleArray, offset: Int = definedExternally): Matrix3 + + fun toArray(array: DoubleArray = definedExternally, offset: Int = definedExternally): DoubleArray + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix4.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix4.kt new file mode 100644 index 00000000..49ed3bfe --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Matrix4.kt @@ -0,0 +1,178 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +import info.laht.threekt.core.BufferGeometry + +/** + * A class representing a 4x4 matrix. + * + * The most common use of a 4x4 matrix in 3D computer graphics is as a Transformation Matrix. For an introduction to transformation matrices as used in WebGL, check out this tutorial. + * + * This allows a Vector3 representing a point in 3D space to undergo transformations such as translation, rotation, shear, scale, reflection, orthogonal or perspective projection and so on, by being multiplied by the matrix. This is known as applying the matrix to the vector. + * + * Every Object3D has three associated Matrix4s: + * Object3D.matrix: This stores the local transform of the object. + * Object3D.matrixWorld: The global or world transform of the object. This is the object's transformation relative to its parent. If the object has no parent, then this is identical to the local transform. + * Object3D.modelViewMatrix: This represents the object's transformation relative to the camera's coordinate system. An object's modelViewMatrix is the object's matrixWorld pre-multiplied by the camera's matrixWorldInverse. + * Cameras have two additional Matrix4s: + * Camera.matrixWorldInverse: The view matrix - the inverse of the Camera's matrixWorld. + * Camera.projectionMatrix: Represents the information how to project the scene to clip space. + * Note: Object3D.normalMatrix is not a Matrix4, but a Matrix3. + */ +external class Matrix4 { + + /** + * A column-major list of matrix values. + */ + val elements: DoubleArray + + /** + * Creates and initializes the Matrix4 to the 4x4 identity matrix. + */ + constructor() + + fun set( + n11: Number, n12: Number, n13: Number, n14: Number, + n21: Number, n22: Number, n23: Number, n24: Number, + n31: Number, n32: Number, n33: Number, n34: Number, + n41: Number, n42: Number, n43: Number, n44: Number + ) + + /** + * Resets this matrix to the identity matrix. + */ + fun identity(): Matrix4 + + /** + * Creates a new Matrix4 with identical elements to this one. + */ + fun clone(): Matrix4 + + /** + * Copies the elements of matrix m into this matrix. + */ + fun copy(m: Matrix4): Matrix4 + + /** + * Copies the translation component of the supplied matrix m into this matrix's translation component. + */ + fun copyPosition(m: Matrix4): Matrix4 + + fun extractBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4 + + /** + * Set this to the basis matrix consisting of the three provided basis vectors + */ + fun makeBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4 + + fun extractRotation(m: Matrix4): Matrix4 + + fun makeRotationFromEuler(euler: Euler): Matrix4 + + fun makeRotationFromQuaternion(q: Quaternion): Quaternion + + fun lookAt(eye: Vector3, target: Vector3, up: Vector3): Matrix4 + + /** + * Post-multiplies this matrix by m. + */ + fun multiply(m: Matrix4): Matrix4 + + /** + * Pre-multiplies this matrix by m. + */ + fun premultiply(m: Matrix4): Matrix4 + + /** + * Sets this matrix to a x b. + */ + fun multiplyMatrices(a: Matrix4, b: Matrix4): Matrix4 + + /** + * Multiplies every component of the matrix by a scalar value s. + */ + fun multiplyScalar(s: Double): Matrix4 + + fun applyToBufferAttribute(attribute: BufferGeometry) + + fun determinant(): Double + + fun transpose(): Matrix4 + + fun setPosition(v: Vector3): Matrix4 + + /** + * Set this matrix to the inverse of the passed matrix m, using the method outlined here. + * If throwOnDegenerate is not set and the matrix is not invertible, set this to the 4x4 identity matrix. + * + * @m the matrix to take the inverse of. + * @param throwOnDegenerate (optional) If true, throw an error if the matrix is degenerate (not invertible). + */ + fun getInverse(m: Matrix4, throwOnDegenerate: Boolean = definedExternally) + + /** + * Multiplies the columns of this matrix by vector v. + */ + fun scale(v: Vector3): Matrix4 + + /** + * Gets the maximum scale value of the 3 axes. + */ + fun getMaxScaleOnAxis(): Double + + fun makeTranslation(x: Double, y: Double, z: Double): Matrix4 + + fun makeRotationX(theta: Double): Matrix4 + + fun makeRotationY(theta: Double): Matrix4 + + fun makeRotationZ(theta: Double): Matrix4 + + fun makeRotationAxis(axis: Vector3, angle: Double): Matrix4 + + fun makeScale(x: Double, y: Double, z: Double): Matrix4 + + fun makeShear(x: Double, y: Double, z: Double): Matrix4 + + fun compose(position: Vector3, quaternion: Vector3, scale: Vector3): Matrix4 + + fun decompose(position: Vector3, quaternion: Vector3, scale: Vector3): Matrix4 + + fun makePerspective(left: Int, right: Int, top: Int, bottom: Int, near: Double, far: Double): Matrix4 + + fun makeOrthographic(left: Int, right: Int, top: Int, bottom: Int, near: Double, far: Double): Matrix4 + + fun equals(matrix: Matrix4): Boolean + + fun fromArray(array: DoubleArray, offset: Int = definedExternally): Matrix4 + + fun toArray(array: DoubleArray, offset: Int = definedExternally): DoubleArray + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Plane.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Plane.kt new file mode 100644 index 00000000..f91c0fef --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Plane.kt @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Plane { + + constructor() + constructor(normal: Vector3, constant: Double) + + var normal: Vector3 + var constant: Double + + fun set(normal: Vector3, constant: Number) + + fun clone(): Plane + fun copy(plane: Plane): Plane + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Quaternion.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Quaternion.kt new file mode 100644 index 00000000..a3a0af8b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Quaternion.kt @@ -0,0 +1,86 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + + +external class Quaternion( + x: Number = definedExternally, + y: Number = definedExternally, + z: Number = definedExternally, + w: Number = definedExternally +) { + + companion object { + fun slerp(qa: Quaternion, qb: Quaternion, qm: Quaternion, t: Number): Quaternion + fun slerpFlat( + dst: DoubleArray, + dstOffset: Int, + src0: DoubleArray, + srcOffset0: Int, + src1: DoubleArray, + srcOffset1: Int, + t: Number + ) + } + + var x: Double + var y: Double + var z: Double + var w: Double + + fun set(x: Number, y: Number, z: Number, w: Number) + fun clone(): Quaternion + fun copy(quaternion: Quaternion): Quaternion + + fun setFromEuler(euler: Euler, update: Boolean = definedExternally) + fun setFromAxisAngle(axis: Vector3, angle: Number): Quaternion + fun setFromRotationMatrix(m: Matrix4): Quaternion + fun setFromUnitVectors(vFrom: Vector3, vTo: Vector3): Vector3 + + fun inverse(): Quaternion + fun conjugate(): Quaternion + + fun dot(q: Quaternion): Double + fun lengthSq(): Double + fun length(): Double + fun normalize(): Quaternion + + fun multiply(q: Quaternion): Quaternion + fun preMultiply(q: Quaternion): Quaternion + fun multiplyQuaternions(a: Quaternion, b: Quaternion): Quaternion + + fun slerp(qb: Quaternion, t: Number): Quaternion + + fun equals(quaternion: Quaternion): Boolean + + fun fromArray(array: DoubleArray, offset: Int = definedExternally): Quaternion + fun toArray(array: DoubleArray = definedExternally, offset: Int = definedExternally): DoubleArray + + fun onChange(callback: () -> Unit) + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Ray.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Ray.kt new file mode 100644 index 00000000..731a3d2b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Ray.kt @@ -0,0 +1,49 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Ray { + + constructor() + constructor(origin: Vector3, direction: Vector3) + + var origin: Vector3 + var direction: Vector3 + + fun set(origin: Vector3, direction: Vector3): Ray + fun clone(): Ray + fun copy(ray: Ray): Ray + fun at(t: Double, optionalTarget: Vector3 = definedExternally) + fun lookAt(v: Vector3): Ray + fun recast(t: Double): Ray + fun closestPointToPoint(point: Vector3, optionalTarget: Vector3 = definedExternally): Vector3 + fun distanceToPoint(point: Vector3): Double + fun distanceSqToPoint(point: Vector3): Double + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Sphere.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Sphere.kt new file mode 100644 index 00000000..cbbc24c4 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Sphere.kt @@ -0,0 +1,61 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Sphere { + + constructor() + constructor(center: Vector3, radius: Number) + + fun setFromPoints(points: Array, optionalCenter: Vector3 = definedExternally): Sphere + + fun clone(): Sphere + fun copy(sphere: Sphere): Sphere + + fun empty(): Boolean + + fun containsPoint(point: Vector3): Boolean + + fun distanceToPoint(point: Vector3): Double + + fun intersectsSphere(sphere: Sphere): Boolean + + fun intersectsBox(box: Box3): Boolean + + fun clampPoint(point: Vector3, optionalTarget: Vector3 = definedExternally): Vector3 + + fun getBoundingBox(optionalTarget: Box3): Box3 + + fun applyMatrix4(matrix: Matrix4): Sphere + + fun translate(offset: Vector3): Sphere + + fun equals(sphere: Sphere): Boolean + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Spherical.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Spherical.kt new file mode 100644 index 00000000..187dcd94 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Spherical.kt @@ -0,0 +1,45 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Spherical { + + constructor() + constructor(radius: Number, phi: Number, theta: Number) + + var radius: Double + var phi: Double + var theta: Double + + fun set(radius: Double, phi: Double, theta: Double) + fun clone(): Spherical + fun copy(other: Spherical): Spherical + fun makeSafe(): Spherical + fun setFromVector3(vec3: Vector3): Spherical + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Triangle.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Triangle.kt new file mode 100644 index 00000000..9dd99c52 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Triangle.kt @@ -0,0 +1,67 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Triangle( + a: Vector3 = definedExternally, + b: Vector3 = definedExternally, + c: Vector3 = definedExternally +) { + + var a: Vector3 + var b: Vector3 + var c: Vector3 + + companion object { + fun normal(a: Vector3, b: Vector3, c: Vector3, optionalTarget: Vector3 = definedExternally) + fun barycoordFromPoint( + point: Vector3, + a: Vector3, + b: Vector3, + c: Vector3, + optionalTarget: Vector3 = definedExternally + ) + + fun containsPoint(point: Vector3, a: Vector3, b: Vector3, c: Vector3) + } + + fun set(a: Vector3, b: Vector3, c: Vector3): Triangle + fun setFromPointsAndIndices(points: Array, i0: Int, i1: Int, i2: Int): Triangle + fun clone(): Triangle + fun copy(source: Triangle): Triangle + fun area(): Double + fun midpoint(optionalTarget: Vector3 = definedExternally): Vector3 + fun normal(optionalTarget: Vector3 = definedExternally): Vector3 + fun plane(optionalTarget: Plane = definedExternally): Plane + fun barycoordFromPoint(point: Vector3, optionalTarget: Vector3 = definedExternally): Vector3 + fun containsPoint(point: Vector3): Boolean + fun closestPointToPoint(point: Vector3, optionalTarget: Vector3 = definedExternally): Vector3 + + fun equals(triangle: Triangle): Boolean + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector2.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector2.kt new file mode 100644 index 00000000..86049df0 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector2.kt @@ -0,0 +1,130 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Vector2( + x: Number = definedExternally, + y: Number = definedExternally +) { + + var x: Double + var y: Double + + fun width(): Double + fun height(): Double + + fun set(x: Number, y: Number): Vector2 + + fun setScalar(scalar: Number): Vector2 + + fun setX(x: Number): Vector2 + + fun setY(y: Number): Vector2 + + fun setComponent(index: Int, value: Number): Vector2 + + fun getComponent(index: Int): Double + + fun clone(): Vector2 + + fun copy(v: Vector2): Vector2 + + fun add(v: Vector2): Vector2 + + fun addScalar(s: Number): Vector2 + fun addVectors(a: Vector2, b: Vector2): Vector2 + + fun addScaledVector(v: Vector2, s: Number): Vector2 + fun sub(v: Vector2): Vector2 + + fun subScalar(s: Number): Vector2 + + fun subVectors(a: Vector2, b: Vector2): Vector2 + + fun multiply(v: Vector2): Vector2 + + fun multiplyScalar(scalar: Number): Vector2 + fun divide(v: Vector2): Vector2 + + fun divideScalar(scalar: Number): Vector2 + + fun applyMatrix3(m: Matrix3): Vector2 + + fun min(v: Vector2): Vector2 + + fun max(v: Vector2): Vector2 + + fun clamp(min: Vector2, max: Vector2): Vector2 + + fun clampScalar(minVal: Number, maxVal: Number): Vector2 + + fun clampLength(min: Vector2, max: Vector2): Vector2 + fun floor(): Vector2 + + fun ceil(): Vector2 + + fun round(): Vector2 + fun roundToZero(): Vector2 + + fun negate(): Vector2 + + fun dot(v: Vector2): Double + + fun lengthSq(): Double + + fun length(): Double + + fun manhattanLength(): Double + + fun normalize(): Vector2 + + fun angle(): Double + + fun distanceTo(v: Vector2): Double + + fun distanceToSquared(v: Vector2): Double + + fun manhattanDistanceTo(v: Vector2): Double + + fun setLength(length: Number): Vector2 + + fun lerp(v: Vector2, alpha: Number): Vector2 + + fun lerpVectors(v1: Vector2, v2: Vector2, alpha: Number): Vector2 + + fun equals(v: Vector2): Boolean + + fun fromArray(array: DoubleArray, offset: Int): Vector2 + + fun toArray(array: DoubleArray = definedExternally, offset: Int): DoubleArray + + fun fromBufferAttribute(attribute: dynamic, index: Int) + + fun rotateAround(center: Vector2, angle: Number): Vector2 + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector3.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector3.kt new file mode 100644 index 00000000..85f1c74b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector3.kt @@ -0,0 +1,388 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +import info.laht.threekt.cameras.Camera + +/** + * Class representing a 3D vector. A 3D vector is an ordered triplet of numbers (labeled x, y, and z), which can be used to represent a number of things, such as: + * A point in 3D space. + * A direction and length in 3D space. In three.js the length will always be the Euclidean distance (straight-line distance) from (0, 0, 0) to (x, y, z) and the direction is also measured from (0, 0, 0) towards (x, y, z). + * Any arbitrary ordered triplet of numbers. + * There are other things a 3D vector can be used to represent, such as momentum vectors and so on, however these are the most common uses in three.js. + * + * @param x the x value of the vector. Default is 0. + * @param y the y value of the vector. Default is 0. + * @param z the z value of the vector. Default is 0. + */ + +external open class Vector3( + x: Number = definedExternally, + y: Number = definedExternally, + z: Number = definedExternally +) { + + var x: Double + var y: Double + var z: Double + + val isVector3: Boolean + + /** + * Sets the x, y and z components of this vector. + */ + fun set(x: Number, y: Number, z: Number) + + /** + * Set the x, y and z values of this vector both equal to scalar. + */ + fun setScalar(scalar: Number): Vector3 + + /** + * Replace this vector's x value with x. + */ + fun setX(x: Number): Vector3 + + /** + * Replace this vector's y value with y. + */ + fun setY(y: Number): Vector3 + + /** + * Replace this vector's z value with z. + */ + fun setZ(z: Number): Vector3 + + /** + * If index equals 0 set x to value. + * If index equals 1 set y to value. + * If index equals 2 set z to value + * @param index 0, 1 or 2. + * @param value number + */ + fun setComponent(index: Int, value: Number): Vector3 + + fun getComponent(index: Int): Double + + /** + * Adds v to this vector. + */ + fun add(v: Vector3): Vector3 + + /** + * Adds the scalar value s to this vector's x, y and z values. + */ + fun addScalar(s: Number): Vector3 + + /** + * Sets this vector to a + b. + */ + fun addVectors(a: Vector3, b: Vector3): Vector3 + + /** + * Adds the multiple of v and s to this vector. + */ + fun addScaledVector(v: Vector3, s: Number): Vector3 + + /** + * Subtracts v from this vector. + */ + fun sub(v: Vector3): Vector3 + + /** + * Subtracts s from this vector's x, y and z compnents. + */ + fun subScalar(s: Number): Vector3 + + /** + * Sets this vector to a - b. + */ + fun subVectors(a: Vector3, b: Vector3): Vector3 + + /** + * Multiplies this vector by v. + */ + fun multiply(v: Vector3): Vector3 + + /** + * Multiplies this vector by scalar s. + */ + fun multiplyScalar(scalar: Number): Vector3 + + /** + * Sets this vector equal to a x b. + */ + fun multiplyVectors(a: Vector3, b: Vector3): Vector3 + + /** + * Applies euler transform to this vector by converting the Euler object to a Quaternion and applying. + */ + fun applyEuler(euler: Euler): Vector3 + + /** + * Applies a rotation specified by an axis and an angle to this vector. + * @param axis A normalized Vector3. + * @param angle An angle in radians. + */ + fun applyAxisAngle(axis: Vector3, angle: Number): Vector3 + + /** + * Multiplies this vector by m + */ + fun applyMatrix3(m: Matrix3): Vector3 + + /** + * Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective. + */ + fun applyMatrix4(m: Matrix4): Vector3 + + /** + * Applies a Quaternion transform to this vector. + */ + fun applyQuaternion(q: Quaternion): Vector3 + + /** + * Projects the vector with the camera. + * @param camera — camera to use in the projection. + */ + fun project(camera: Camera): Vector3 + + /** + * Unprojects the vector with the camera's projection matrix. + * @param camera camera to use in the projection. + */ + fun unproject(camera: Camera): Vector3 + + /** + * Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) + * and then normalizes the result. + */ + fun transformDirection(m: Matrix4): Vector3 + + fun divide(v: Vector3): Vector3 + fun divideScalar(scalar: Double): Vector3 + /** + * If this vector's x, y or z value is greater than v's x, y or z value, replace that value with the corresponding min value. + */ + fun min(v: Vector3): Vector3 + + /** + * If this vector's x, y or z value is less than v's x, y or z value, replace that value with the corresponding max value. + */ + fun max(v: Vector3): Vector3 + + /** + * If this vector's x, y or z value is greater than the max vector's x, y or z value, it is replaced by the corresponding value. + * + * If this vector's x, y or z value is less than the min vector's x, y or z value, it is replaced by the corresponding value. + */ + fun clamp(min: Vector3, max: Vector3): Vector3 + + fun clampScalar(minVal: Number, maxVal: Number): Vector3 + fun clampLength(min: Number, max: Number): Vector3 + /** + * The components of the vector are rounded down to the nearest integer value. + */ + fun floor(): Vector3 + + /** + * The x, y and z components of the vector are rounded up to the nearest integer value. + */ + fun ceil(): Vector3 + + /** + * The components of the vector are rounded to the nearest integer value. + */ + fun round(): Vector3 + + /** + * The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value. + */ + fun roundToZero(): Vector3 + + /** + * Inverts this vector - i.e. sets x = -x, y = -y and z = -z. + */ + fun negate(): Vector3 + + /** + * Calculate the dot product of this vector and v. + */ + fun dot(v: Vector3): Double + + /** + * Computes the square of the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z). + * If you are comparing the lengths of vectors, you should compare the length squared instead as it + * is slightly more efficient to calculate. + */ + fun lengthSq(): Double + + /** + * Computes the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z). + */ + fun length(): Double + + /** + * Computes the Manhattan length of this vector. + */ + fun manhattanLength(): Double + + /** + * Convert this vector to a unit vector - that is, sets it equal to the vector with + * the same direction as this one, but length 1. + */ + fun normalize(): Vector3 + + /** + * Set this vector to the vector with the same direction as this one, but length l. + */ + fun setLength(length: Number): Vector3 + + /** + * Linearly interpolate between this vector and v, where alpha is the distance along + * the line - alpha = 0 will be this vector, and alpha = 1 will be v. + * @param v Vector3 to interpolate towards. + * @param alpha interpolation factor in the closed interval [0, 1]. + */ + fun lerp(v: Vector3, alpha: Number): Vector3 + + /** + * Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the distance along the line + * connecting the two vectors - alpha = 0 will be v1, and alpha = 1 will be v2. + * @param v1 the starting Vector3. + * @param v2 Vector3 to interpolate towards. + * @param alpha interpolation factor in the closed interval [0, 1]. + */ + fun lerpVectors(v1: Vector3, v2: Vector3, alpha: Number): Vector3 + + /** + * Sets this vector to cross product of itself and v. + */ + fun cross(v: Vector3): Vector3 + + /** + * Sets this vector to cross product of a and b. + */ + fun crossVectors(a: Vector3, b: Vector3): Vector3 + + /** + * Projects this vector onto another vector. + */ + fun projectOnVector(vector: Vector3): Vector3 + + /** + * Projects this vector onto a plane by subtracting this vector projected onto the plane's normal from this vector. + * @param planeNormal A vector representing a plane normal. + */ + fun projectOnPlane(planeNormal: Vector3): Vector3 + + /** + * Reflect the vector off of plane orthogonal to normal. Normal is assumed to have unit length. + * @param normal the normal to the reflecting plane + */ + fun reflect(normal: Vector3): Vector3 + + /** + * Returns the angle between this vector and vector v in radians. + */ + fun angleTo(v: Vector3): Double + + /** + * Computes the distance from this vector to v. + */ + fun distanceTo(v: Vector3): Double + + /** + * Computes the squared distance from this vector to v. If you are just comparing the distance with another distance, + * you should compare the distance squared instead as it is slightly more efficient to calculate. + */ + fun distanceToSquared(v: Vector3): Double + + /** + * Computes the Manhattan distance from this vector to v. + */ + fun manhattanDistanceTo(v: Vector3): Double + + /** + * Sets this vector from the spherical coordinates s. + */ + fun setFromSpherical(s: Spherical): Vector3 + + /** + * Sets this vector from the cylindrical coordinates c. + */ + fun setFromCylindrical(c: Cylindrical): Vector3 + + /** + * Sets this vector to the position elements of the transformation matrix m. + */ + fun setFromMatrixPosition(m: Matrix4): Vector3 + + /** + * Sets this vector to the scale elements of the transformation matrix m. + */ + fun setFromMatrixScale(m: Matrix4): Vector3 + + /** + * Sets this vector's x, y and z equal to the column of the matrix specified by the index. + */ + fun setFromMatrixColumn(m: Matrix4, index: Int): Vector3 + + /** + * Sets this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] + * and z value to be array[ offset + 2 ]. + * + * @param array the source array. + * @param offset ( optional) offset into the array. Default is 0. + * + */ + fun fromArray(array: DoubleArray, offset: Int = definedExternally): Vector3 + + fun toArray(array: DoubleArray = definedExternally, offset: Int = definedExternally): DoubleArray + + /** + * Sets this vector's x, y and z values from the attribute. + */ + fun fromBufferAttribute(attribute: dynamic, index: Int, offset: Int = definedExternally): Vector3 + + /** + * Checks for strict equality of this vector and v. + */ + fun equals(v: Vector3): Boolean + + /** + * Returns a new vector3 with the same x, y and z values as this one. + */ + fun clone(): Vector3 + + /** + * Copies the values of the passed vector3's x, y and z properties to this vector3. + */ + fun copy(v: Vector3): Vector3 + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector4.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector4.kt new file mode 100644 index 00000000..f017f4d4 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/Vector4.kt @@ -0,0 +1,146 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.math + +external class Vector4( + x: Number = definedExternally, + y: Number = definedExternally, + z: Number = definedExternally, + w: Number = definedExternally +) { + + var x: Double + var y: Double + var z: Double + var w: Double + + fun set(x: Number, y: Number, z: Number, w: Number): Vector4 + + /** + * If index equals 0 returns the x value. + * If index equals 1 returns the y value. + * If index equals 2 returns the z value. + * If index equals 3 returns the w value. + * @index 0, 1, 2 or 3. + */ + fun getComponent(index: Int): Double + + /** + * Adds v to this vector + */ + fun add(v: Vector4): Vector4 + + /** + * ets this vector to a + b. + */ + fun addVectors(a: Vector4, b: Vector4): Vector4 + + /** + * Adds the scalar value s to this vector's x, y, z and w values. + */ + fun addScalar(s: Number): Vector4 + + /** + * Subtracts v from this vector. + */ + fun sub(v: Vector4): Vector4 + + /** + * Sets this vector to a - b. + */ + fun subVectors(a: Vector4, b: Vector4): Vector4 + + + /** + * Subtracts s from this vector's x, y, z and w compnents. + */ + fun subScalar(s: Number): Vector4 + + /** + * Inverts this vector - i.e. sets x = -x, y = -y, z = -z and w = -w. + */ + fun negate(): Vector4 + + /** + * Converts this vector to a unit vector - that is, sets it equal to the vector with the same direction as this one, but length 1. + */ + fun normalize(): Vector4 + + /** + * Computes the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w). + */ + fun length(): Double + + /** + * Computes the Manhattan length of this vector. + */ + fun manhattanLength(): Double + + /** + * Computes the square of the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w). + * If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate. + */ + fun lengthSq(): Double + + /** + * Multiplies this vector by 4 x 4 m. + */ + fun applyMatrix4(m: Matrix4): Vector4 + + /** + * The x, y, z and w components of the vector are rounded up to the nearest integer value. + */ + fun ceil(): Vector4 + + /** + * The components of the vector are rounded down to the nearest integer value. + */ + fun floor(): Vector4 + + /** + * Calculates the dot product of this vector and v. + */ + fun dot(v: Vector4): Vector4 + + /** + * Returns a new Vector4 with the same x, y, z and w values as this one. + */ + fun clone(): Vector4 + + + /** + * Copies the values of the passed Vector4's x, y, z and w properties to this Vector4. + */ + fun copy(source: Vector4): Vector4 + + /** + * Checks for strict equality of this vector and v. + */ + fun equals(v: Vector4): Boolean + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/operators.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/operators.kt new file mode 100644 index 00000000..b30baf00 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/math/operators.kt @@ -0,0 +1,46 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package info.laht.threekt.math + +operator fun Vector3.unaryMinus() = this.clone().negate() +operator fun Vector3.plusAssign(v: Vector3) = this.let { add(v); Unit } +operator fun Vector3.plus(v: Vector3) = this.clone().add(v) +operator fun Vector3.minusAssign(v: Vector3) = this.let { sub(v); Unit } +operator fun Vector3.minus(v: Vector3) = this.clone().sub(v) +operator fun Vector3.times(v: Vector3) = this.clone().multiply(v) +operator fun Vector3.timesAssign(v: Vector3) = this.let { times(v); Unit } + +operator fun Vector4.unaryMinus() = this.clone().negate() +operator fun Vector4.plusAssign(v: Vector4) = this.let { add(v); Unit } +operator fun Vector4.plus(v: Vector4) = this.clone().add(v) +operator fun Vector4.minusAssign(v: Vector4) = this.let { sub(v); Unit } +operator fun Vector4.minus(v: Vector4) = this.clone().sub(v) + +operator fun Quaternion.times(q: Quaternion) = this.clone().multiply(q) +operator fun Quaternion.timesAssign(q: Quaternion) = this.let { multiply(q); Unit } + +operator fun Matrix4.times(v: Vector3) = v.applyMatrix4(this).let { this.setPosition(it) } +operator fun Matrix4.times(m: Matrix4) = this.clone().multiply(m) +operator fun Matrix4.timesAssign(m: Matrix4) = this.let { multiply(m); Unit } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Group.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Group.kt new file mode 100644 index 00000000..e5420f29 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Group.kt @@ -0,0 +1,33 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.Object3D + +external class Group : Object3D + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LOD.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LOD.kt new file mode 100644 index 00000000..89e405ac --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LOD.kt @@ -0,0 +1,48 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.core.Intersect +import info.laht.threekt.core.Object3D +import info.laht.threekt.core.Raycaster + + +external class LOD : Object3D { + + fun copy(source: LOD): LOD + + fun addLevel(`object`: Object3D, distance: Double) + + fun getObjectForDistance(distance: Double): Object3D + + fun raycast(raycaster: Raycaster, intercects: List) + + fun update(camera: Camera) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Line.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Line.kt new file mode 100644 index 00000000..e0a217bc --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Line.kt @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Intersect +import info.laht.threekt.core.Object3D +import info.laht.threekt.core.Raycaster +import info.laht.threekt.materials.Material + + +open external class Line(geometry: BufferGeometry, material: Material) : Object3D { + + var geometry: BufferGeometry + var material: Material + + fun raycast(raycaster: Raycaster, intercects: List) + + fun clone(): Line + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineLoop.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineLoop.kt new file mode 100644 index 00000000..50aa390e --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineLoop.kt @@ -0,0 +1,33 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.materials.Material + +external class LineLoop(geometry: BufferGeometry, material: Material) : Line \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineSegments.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineSegments.kt new file mode 100644 index 00000000..e682cdc7 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/LineSegments.kt @@ -0,0 +1,34 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.BufferGeometry +import info.laht.threekt.core.Object3D +import info.laht.threekt.materials.Material + +open external class LineSegments(geometry: BufferGeometry, material: Material) : Object3D \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Mesh.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Mesh.kt new file mode 100644 index 00000000..6c5b4555 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Mesh.kt @@ -0,0 +1,49 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.* +import info.laht.threekt.materials.Material + + +open external class Mesh : Object3D { + + constructor(geometry: Geometry, material: Material) + constructor(geometry: BufferGeometry, material: Material) + + var geometry: dynamic + var material: Material + + var drawMode: Int + + fun copy(source: Mesh): Mesh + fun updateMorphTargets() + fun raycast(raycaster: Raycaster, intersects: List) + fun clone(): Mesh + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Points.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Points.kt new file mode 100644 index 00000000..f296937a --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Points.kt @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.Intersect +import info.laht.threekt.core.Object3D +import info.laht.threekt.core.Raycaster +import info.laht.threekt.materials.Material + +external class Points : Object3D { + + var geometry: dynamic + var material: Material + + fun raycast(raycaster: Raycaster, intercects: List) + + fun clone(): Points + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Sprite.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Sprite.kt new file mode 100644 index 00000000..60e2d0de --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/objects/Sprite.kt @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.objects + +import info.laht.threekt.core.Intersect +import info.laht.threekt.core.Object3D +import info.laht.threekt.core.Raycaster +import info.laht.threekt.materials.Material + +external class Sprite(material: Material = definedExternally) : Object3D { + + var material: Material + + fun raycast(raycaster: Raycaster, intersects: List) + + fun clone(): Sprite + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2Renderer.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2Renderer.kt new file mode 100644 index 00000000..1c5208ad --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2Renderer.kt @@ -0,0 +1,49 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.renderers + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.scenes.Scene + +external class WebGL2Renderer { + + constructor(params: WebGL2RendererParams = definedExternally) + + fun clear( + color: Boolean = definedExternally, + depth: Boolean = definedExternally, + stencil: Boolean = definedExternally + ) + + fun setPixelRatio(value: Number) + fun setSize(width: Int, height: Int, updateStyle: Boolean = definedExternally) + fun setViewPort(x: Int, y: Int, width: Int, height: Int) + fun render(scene: Scene, camera: Camera) + fun onContextLost(event: dynamic) + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2RendererParams.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2RendererParams.kt new file mode 100644 index 00000000..a2ef9eaf --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGL2RendererParams.kt @@ -0,0 +1,37 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package info.laht.threekt.renderers + +import org.w3c.dom.Node + +data class WebGL2RendererParams( + val canvas: Node? = undefined, + val alpha: Boolean? = undefined, + val depth: Boolean? = undefined, + val stencil: Boolean? = undefined, + val antialias: Boolean? = undefined, + val premultipliedAlpha: Boolean? = undefined, + val preserveDrawingBuffer: Boolean? = undefined +) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTarget.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTarget.kt new file mode 100644 index 00000000..08c44a36 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTarget.kt @@ -0,0 +1,60 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.renderers + +import info.laht.threekt.math.Vector4 +import info.laht.threekt.textures.Texture + +external class WebGLRenderTarget { + + constructor(width: Int, height: Int, options: WebGLRenderTargetOptions = definedExternally) + + var uuid: String + + var widht: Int + var height: Int + + var scissor: Vector4 + var scissorTest: Boolean + + var viewPort: Vector4 + + var texture: Texture + + var depthBuffer: Boolean + var stencilBuffer: Boolean + + fun setSize(width: Int, height: Int) + + fun clone(): WebGLRenderTarget + fun copy(source: WebGLRenderTarget): WebGLRenderTarget + + fun dispose() + + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTargetOptions.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTargetOptions.kt new file mode 100644 index 00000000..4ba8b941 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderTargetOptions.kt @@ -0,0 +1,38 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package info.laht.threekt.renderers + +data class WebGLRenderTargetOptions( + val wrapS: Int? = undefined, + val wrapT: Int? = undefined, + val magFilter: Int? = undefined, + val minFilter: Int? = undefined, + val format: Int? = undefined, + val type: Int? = undefined, + val anisotropy: Int? = undefined, + val encoding: Int? = undefined, + val depthBuffer: Boolean? = undefined, + val stencilBuffer: Boolean? = undefined +) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderer.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderer.kt new file mode 100644 index 00000000..c46e941e --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRenderer.kt @@ -0,0 +1,101 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.renderers + +import info.laht.threekt.cameras.Camera +import info.laht.threekt.scenes.Scene +import org.w3c.dom.Node + + +external class WebGLRenderer(params: WebGLRendererParams = definedExternally) { + var domElement: Node + + var autoClear: Boolean + var autoClearColor: Boolean + var autoClearDepth: Boolean + var autoClearStencil: Boolean + + var sortObjects: Boolean + + var gammaFactor: Double + var gammaInput: Boolean + var gammaOutput: Boolean + + var physicallyCorrectLights: Boolean + + + var toneMapping: Int + var toneMappingExposure: Double; + var toneMappingWhitePoint: Double + + var maxMorphTargets: Int + var maxMorphNormals: Int + + interface Size { + val x: Int + val y: Int + } + + fun clear( + color: Boolean = definedExternally, + depth: Boolean = definedExternally, + stencil: Boolean = definedExternally + ) + + fun clearColor() + fun clearDepth() + fun clearStencil() + + fun getSize(): Size + fun setSize(width: Int, height: Int, updateStyle: Boolean = definedExternally) + + /** + * Sets the clear alpha. Valid input is a float between 0.0 and 1.0. + */ + fun setClearAlpha(alpha: Number) + + /** + * Sets the clear color and opacity. + */ + fun setClearColor(color: Int, alpha: Number) + + /** + * Render a scene using a camera. + * The render is done to the renderTarget (if specified) or to the canvas as usual. + * If forceClear is true, the depth, stencil and color buffers will be cleared before rendering even if the renderer's autoClear property is false. + * Even with forceClear set to true you can prevent certain buffers being cleared by setting either the autoClearColor, autoClearStencil or autoClearDepth properties to false. + */ + fun render( + scene: Scene, + camera: Camera, + renderTarget: dynamic = definedExternally, + forceClear: Boolean = definedExternally + ) + + fun setPixelRatio(value: Number) +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRendererParams.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRendererParams.kt new file mode 100644 index 00000000..e6800673 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/WebGLRendererParams.kt @@ -0,0 +1,37 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package info.laht.threekt.renderers + +import org.w3c.dom.Node + +data class WebGLRendererParams( + var canvas: Node? = undefined, + var alpha: Boolean? = undefined, + var depth: Boolean? = undefined, + var stencil: Boolean? = undefined, + var antialias: Boolean? = undefined, + var premultipliedAlpha: Boolean? = undefined, + var preserveDrawingBuffer: Boolean? = undefined +) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderChunk.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderChunk.kt new file mode 100644 index 00000000..f70c7137 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderChunk.kt @@ -0,0 +1,141 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.renderers.shaders + +external object ShaderChunk { + val alphamap_fragment: String + val alphamap_pars_fragment: String + val alphatest_fragment: String + val aomap_fragment: String + val aomap_pars_fragment: String + val begin_vertex: String + val beginnormal_vertex: String + val bsdfs: String + val bumpmap_pars_fragment: String + val clipping_planes_fragment: String + val clipping_planes_pars_fragment: String + val clipping_planes_pars_vertex: String + val clipping_planes_vertex: String + val color_fragment: String + val color_pars_fragment: String + val color_pars_vertex: String + val color_vertex: String + val common: String + val cube_uv_reflection_fragment: String + val defaultnormal_vertex: String + val displacementmap_pars_vertex: String + val displacementmap_vertex: String + val emissivemap_fragment: String + val emissivemap_pars_fragment: String + val encodings_fragment: String + val encodings_pars_fragment: String + val envmap_fragment: String + val envmap_pars_fragment: String + val envmap_pars_vertex: String + val envmap_vertex: String + val fog_vertex: String + val fog_pars_vertex: String + val fog_fragment: String + val fog_pars_fragment: String + val gradientmap_pars_fragment: String + val lightmap_fragment: String + val lightmap_pars_fragment: String + val lights_lambert_vertex: String + val lights_pars: String + val lights_phong_fragment: String + val lights_phong_pars_fragment: String + val lights_physical_fragment: String + val lights_physical_pars_fragment: String + val lights_template: String + val logdepthbuf_fragment: String + val logdepthbuf_pars_fragment: String + val logdepthbuf_pars_vertex: String + val logdepthbuf_vertex: String + val map_fragment: String + val map_pars_fragment: String + val map_particle_fragment: String + val map_particle_pars_fragment: String + val metalnessmap_fragment: String + val metalnessmap_pars_fragment: String + val morphnormal_vertex: String + val morphtarget_pars_vertex: String + val morphtarget_vertex: String + val normal_fragment: String + val normalmap_pars_fragment: String + val packing: String + val premultiplied_alpha_fragment: String + val project_vertex: String + val dithering_fragment: String + val dithering_pars_fragment: String + val roughnessmap_fragment: String + val roughnessmap_pars_fragment: String + val shadowmap_pars_fragment: String + val shadowmap_pars_vertex: String + val shadowmap_vertex: String + val shadowmask_pars_fragment: String + val skinbase_vertex: String + val skinning_pars_vertex: String + val skinning_vertex: String + val skinnormal_vertex: String + val specularmap_fragment: String + val specularmap_pars_fragment: String + val tonemapping_fragment: String + val tonemapping_pars_fragment: String + val uv_pars_fragment: String + val uv_pars_vertex: String + val uv_vertex: String + val uv2_pars_fragment: String + val uv2_pars_vertex: String + val uv2_vertex: String + val worldpos_vertex: String + + val cube_frag: String + val cube_vert: String + val depth_frag: String + val depth_vert: String + val distanceRGBA_frag: String + val distanceRGBA_vert: String + val equirect_frag: String + val equirect_vert: String + val linedashed_frag: String + val linedashed_vert: String + val meshbasic_frag: String + val meshbasic_vert: String + val meshlambert_frag: String + val meshlambert_vert: String + val meshphong_frag: String + val meshphong_vert: String + val meshphysical_frag: String + val meshphysical_vert: String + val normal_frag: String + val normal_vert: String + val points_frag: String + val points_vert: String + val shadow_frag: String + val shadow_vert: String +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderLib.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderLib.kt new file mode 100644 index 00000000..f168f740 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/ShaderLib.kt @@ -0,0 +1,32 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.renderers.shaders + +external object ShaderLib { + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/UniformsUtil.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/UniformsUtil.kt new file mode 100644 index 00000000..fb68d712 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/renderers/shaders/UniformsUtil.kt @@ -0,0 +1,37 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.renderers.shaders + +import info.laht.threekt.core.Uniform + +external object UniformsUtil { + + fun merge(uniforms: Array): dynamic + fun clone(uniforms_src: Uniform): dynamic + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Fog.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Fog.kt new file mode 100644 index 00000000..c5682f36 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Fog.kt @@ -0,0 +1,45 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.scenes + +import info.laht.threekt.math.Color + +external class Fog { + + var name: String + var color: Color + + var near: Int + var far: Int + + fun clone(): Fog + + fun toJSON(): dynamic + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/FogExp2.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/FogExp2.kt new file mode 100644 index 00000000..017fd34b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/FogExp2.kt @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.scenes + +import info.laht.threekt.math.Color + +external class FogExp2 { + + constructor(color: Color) + constructor(color: Color, density: Number) + + var color: Color + var density: Double + + fun clone(): FogExp2 + fun toJSON(): dynamic + +} + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Scene.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Scene.kt new file mode 100644 index 00000000..16e5e3cd --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/scenes/Scene.kt @@ -0,0 +1,62 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.scenes + +import info.laht.threekt.core.Object3D +import info.laht.threekt.materials.Material + +/** + * Scenes allow you to set up what and where is to be rendered by three.js. + * This is where you place objects, lights and cameras. + */ +external class Scene : Object3D { + + /** + * A fog instance defining the type of fog that affects everything rendered in the scene. Default is null. + */ + var fog: dynamic + + /** + * If not null, it will force everything in the scene to be rendered with that material. Default is null. + */ + var overideMaterial: Material + + /** + * Default is true. If set, then the renderer checks every frame if the scene and its objects needs matrix updates. + * When it isn't, then you have to maintain all matrices in the scene yourself. + */ + var autoUpdate: Boolean + /** + * If not null, sets the background used when rendering the scene, and is always rendered first. + * Can be set to a Color which sets the clear color, a Texture covering the canvas, or a CubeTexture. Default is null. + */ + var background: dynamic + + fun copy(source: Scene, recursive: Boolean = definedExternally): Scene + +} diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CompressedTexture.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CompressedTexture.kt new file mode 100644 index 00000000..1d25e61d --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CompressedTexture.kt @@ -0,0 +1,59 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.textures + +/** + * Creates a texture based on data in compressed form, for example from a DDS file. + * + * For use with the CompressedTextureLoader. + */ +external class CompressedTexture( + mipmaps: Array, + width: Int, + height: Int, + format: Int = definedExternally, + type: Int, + mapping: Int = definedExternally, + wrapS: Int = definedExternally, + wrapT: Int = definedExternally, + magFilter: Int = definedExternally, + minFilter: Int = definedExternally, + anisotropy: Int = definedExternally +) : Texture { + + /** + * False by default. Flipping textures does not work for compressed textures. + */ + override var flipY: Boolean + + /** + * False by default. Mipmaps can't be generated for compressed textures + */ + override var generateMipmaps: Boolean + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CubeTexture.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CubeTexture.kt new file mode 100644 index 00000000..b5eb6e89 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/CubeTexture.kt @@ -0,0 +1,47 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.textures + +import org.w3c.dom.Element + +external class CubeTexture( + image: Element = definedExternally, + mapping: Int = definedExternally, + wrapS: Int = definedExternally, + wrapT: Int = definedExternally, + magFilter: Int = definedExternally, + minFilter: Int = definedExternally, + format: Int = definedExternally, + type: Int = definedExternally, + anisotropy: Int = definedExternally, + encoding: Int = definedExternally +) : Texture { + + var images: Array + +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/DepthTexture.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/DepthTexture.kt new file mode 100644 index 00000000..0ce9a308 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/DepthTexture.kt @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.textures + +external class DepthTexture( + width: Int, + height: Int, + type: Int, + mapping: Int = definedExternally, + wrapS: Int = definedExternally, + wrapT: Int = definedExternally, + magFilter: Int = definedExternally, + minFilter: Int = definedExternally, + anisotropy: Int = definedExternally, + format: Int = definedExternally +) : Texture \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/Texture.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/Texture.kt new file mode 100644 index 00000000..b936c2f5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/textures/Texture.kt @@ -0,0 +1,238 @@ +/* + * The MIT License + * + * Copyright 2017-2018 Lars Ivar Hatledal + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +@file:JsModule("three") +@file:JsNonModule + +package info.laht.threekt.textures + +import info.laht.threekt.math.Matrix3 +import info.laht.threekt.math.Vector2 +import org.w3c.dom.Element + +/** + * Create a texture to apply to a surface or as a reflection or refraction map. + */ +open external class Texture( + image: Element = definedExternally, + mapping: Int = definedExternally, + wrapS: Int = definedExternally, + wrapT: Int = definedExternally, + magFilter: Int = definedExternally, + minFilter: Int = definedExternally, + format: Int = definedExternally, + type: Int = definedExternally, + anisotropy: Int = definedExternally, + encoding: Int = definedExternally +) { + + companion object { + var DEFAULT_IMAGE: Element? + var DEFAULT_MAPPING: Int + } + + + /** + * This starts at 0 and counts how many times # .needsUpdate is set to true. + */ + var version: Int + + /** + * Readonly - unique number for this texture instance. + */ + val id: Int + + /** + * UUID of this object instance. This gets automatically assigned, so this shouldn't be edited. + */ + val uuid: String + + /** + * Optional name of the object (doesn't need to be unique). Default is an empty string. + */ + var name: String + /** + * An image object, typically created using the TextureLoader.load method. This can be any image (e.g., PNG, JPG, GIF, DDS) + * or video (e.g., MP4, OGG/OGV) type supported by three.js. + * + * To use video as a texture you need to have a playing HTML5 video element as a source for your texture image and + * continuously update this texture as long as video is playing - the VideoTexture class handles this automatically. + */ + var image: Element + + /** + * Array of user-specified mipmaps (optional). + */ + var mipmaps: Array + + /** + * How the image is applied to the object. An object type of THREE.UVMapping is the default, where the U,V coordinates are used to apply the map. + See the texture constants page for other mapping types. + */ + var mapping: Int + + /** + * This defines how the texture is wrapped horizontally and corresponds to U in UV mapping. + * The default is THREE.ClampToEdgeWrapping, where the edge is clamped to the outer edge texels. + * The other two choices are THREE.RepeatWrapping and THREE.MirroredRepeatWrapping. + * See the texture constants page for details. + */ + var wrapS: Int + /** + * This defines how the texture is wrapped vertically and corresponds to V in UV mapping. + * The same choices are available as for # .wrapS . + + * NOTE: tiling of images in textures only functions if image dimensions are powers + * of two (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, ...) in terms of pixels. + * Individual dimensions need not be equal, but each must be a power of two. This is a limitation of WebGL, not three.js. + */ + var wrapT: Int + + /** + * How the texture is sampled when a texel covers more than one pixel. + * The default is THREE.LinearFilter, which takes the four closest texels and bilinearly interpolates among them. + * The other option is THREE.NearestFilter, which uses the value of the closest texel. + * See the texture constants page for details. + */ + var magFilter: Int + /** + * How the texture is sampled when a texel covers less than one pixel. + * The default is THREE.LinearMipMapLinearFilter, which uses mipmapping and a trilinear filter. + * + * See the texture constants page for all possible choices. + */ + var minFilter: Int + + /** + * The number of samples taken along the axis through the pixel that has the highest density of texels. + * By default, this value is 1. A higher value gives a less blurry result than a basic mipmap, at the cost of more texture samples being used. + * Use renderer.getMaxAnisotropy() to find the maximum valid anisotropy value for the GPU; this value is usually a power of 2. + */ + var anisotropy: Int + + /** + * The default is THREE.RGBAFormat, although the TextureLoader will automatically set this to THREE.RGBFormat for JPG images. + * + * See the texture constants page for details of other formats. + */ + var format: Int + /** + * This must correspond to the .format. The default is THREE.UnsignedByteType, which will be used for most texture formats. + * + * See the texture constants page for details of other formats. + */ + var type: Int + + /** + * How much a single repetition of the texture is offset from the beginning, in each direction U and V. + * Typical range is 0.0 to 1.0. _Note:_ The offset property is a convenience modifier and only affects the Texture's application + * to the first set of UVs on a model. If the Texture is used as a map requiring additional UV sets + * (e.g. the aoMap or lightMap of most stock materials), those UVs must be manually assigned to achieve the desired offset. + */ + var offset: Vector2 + /** + * How many times the texture is repeated across the surface, in each direction U and V. + * If repeat is set greater than 1 in either direction, the corresponding Wrap parameter should + * also be set to THREE.RepeatWrapping or THREE.MirroredRepeatWrapping to achieve the desired tiling effect. + * _Note:_ The repeat property is a convenience modifier and only affects the Texture's application to the + * first set of UVs on a model. If the Texture is used as a map requiring additional UV sets + * (e.g. the aoMap or lightMap of most stock materials), those UVs must be manually assigned to + * achieve the desired repetiton. + */ + var repeat: Vector2 + /** + * Indicates where the center of rotation is. + * To rotate around the center point set this value to (0.5, 0.5). Default value is (0.0, 0.0). + */ + var center: Vector2 + /** + * How much the texture is rotated around the center point, in radians. Postive values are counter-clockwise. Default is 0. + */ + var rotation: Double + + /** + * Whether to update the texture's uv-transform # .matrix based on the .offset , .repeat , and .rotation settings. + * True by default. Set this to false if you are specifying the uv-transform matrix directly. + */ + var matrixAutoUpdate: Boolean + /** + * The uv-transform matrix for the texture. Updated by the renderer from the texture properties .offset, .repeat, and .rotation + * when the texture's .matrixAutoUpdate property is true. + * When .matrixAutoUpdate property is false, this matrix may be set manually. Default is the indentity matrix. + */ + var matrix: Matrix3 + + /** + * Whether to generate mipmaps (if possible) for a texture. True by default. + * Set this to false if you are creating mipmaps manually. + */ + open var generateMipmaps: Boolean + /** + * False by default, which is the norm for PNG images. + * Set to true if the RGB values have been stored premultiplied by alpha. + */ + var premultiplyAlpha: Boolean + /** + * True by default. Flips the image's Y axis to match the WebGL texture coordinate space + */ + open var flipY: Boolean + /** + * 4 by default. Specifies the alignment requirements for the start of each pixel row in memory. + * The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), + * 4 (word-alignment), and 8 (rows start on double-word boundaries). + * + * See glPixelStorei for more information. + */ + var unpackAlignment: Int + + + /** + * THREE.LinearEncoding is the default. See the texture constants page for details of other formats. + * + * Note that ff this value is changed on a texture after the material has been used, it is necessary to + * trigger a Material.needsUpdate for this value to be realized in the shader. + */ + var encoding: Int + + /** + * Set this to true to trigger an update next time the texture is used. Particularly important for setting the wrap mode. + */ + var needsUpdate: Boolean + + /** + * Call EventDispatcher.dispatchEvent with a 'dispose' event type. + */ + fun dispose() + + /** + * Transform the uv based on the value of this texture's .repeat, .offset, .wrapS, .wrapT and .flipY properties. + */ + fun transformUv(uv: Vector2) + + fun clone(): Texture + fun copy(texture: Texture): Texture + + fun toJSON(meta: String): dynamic + +} \ No newline at end of file From 8f1dcac6cdb997ddc90423a4c163e5ab7ed66415 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Aug 2019 13:39:10 +0300 Subject: [PATCH 02/55] Fixed after migration to new Group structure --- .../vis/common/AbstractVisualGroup.kt | 33 +++++-- .../vis/common/AbstractVisualObject.kt | 3 +- .../hep/dataforge/vis/common/VisualGroup.kt | 2 +- .../dataforge/vis/spatial/gdml/visualGDML.kt | 9 +- .../kotlin/hep/dataforge/vis/spatial/Box.kt | 2 +- .../dataforge/vis/spatial/Visual3DPlugin.kt | 10 ++ .../dataforge/vis/spatial/VisualGroup3D.kt | 92 +++++++++++++++++++ .../dataforge/vis/spatial/VisualObject3D.kt | 70 +------------- .../hep/dataforge/vis/spatial/serilization.kt | 18 +++- .../dataforge/vis/spatial/three/Materials.kt | 2 +- .../vis/spatial/three/ThreeFactory.kt | 2 +- .../vis/spatial/three/ThreePlugin.kt | 13 ++- 12 files changed, 167 insertions(+), 89 deletions(-) create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt index 939a2ec6..23b889f6 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -54,10 +54,24 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { // // } + /** + * Remove a child with given name token + */ protected abstract fun removeChild(token: NameToken) + /** + * Add, remove or replace child with given name + */ protected abstract fun setChild(token: NameToken, child: VisualObject?) + /** + * Add a static child. Statics could not be found by name, removed or replaced + */ + protected abstract fun addStatic(child: VisualObject) + + /** + * Recursively create a child group + */ protected abstract fun createGroup(name: Name): VisualGroup /** @@ -66,17 +80,16 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { */ override fun set(name: Name, child: VisualObject?) { when { - name.isEmpty() -> error("") + name.isEmpty() -> { + if (child != null) { + addStatic(child) + } + } name.length == 1 -> { val token = name.first()!! if (child == null) { removeChild(token) } else { - if (child.parent == null) { - child.parent = this - } else { - error("Can't reassign existing parent for $child") - } setChild(token, child) } } @@ -89,7 +102,13 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { listeners.forEach { it.callback(name, child) } } - operator fun set(key: String, child: VisualObject?) = set(key.asName(), child) + operator fun set(key: String, child: VisualObject?) = if (key.isBlank()) { + child?.let { addStatic(child) } + } else { + set(key.asName(), child) + } + + operator fun set(key: String?, child: VisualObject?) = set(key ?: "", child) protected fun MetaBuilder.updateChildren() { //adding named children diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index 61ae9b7c..7b3b7a89 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -34,8 +34,7 @@ abstract class AbstractVisualObject : VisualObject { abstract var properties: Config? override val config: Config get() = properties ?: Config().also { config -> - properties = config - config.onChange(this, ::propertyChanged) + properties = config.apply { onChange(this, ::propertyChanged) } } override fun setProperty(name: Name, value: Any?) { diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt index 749938bd..2be37102 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt @@ -50,4 +50,4 @@ interface VisualGroup : VisualObject, Provider, Iterable { operator fun set(name: Name, child: VisualObject?) } -operator fun VisualGroup.get(str: String) = get(str.toName()) \ No newline at end of file +operator fun VisualGroup.get(str: String?) = get(str?.toName() ?: EmptyName) \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index db513ba7..f71b4948 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -1,8 +1,10 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.Meta +import hep.dataforge.names.EmptyName import hep.dataforge.names.plus import hep.dataforge.vis.common.asName +import hep.dataforge.vis.common.get import hep.dataforge.vis.spatial.* import scientifik.gdml.* import kotlin.math.cos @@ -42,7 +44,7 @@ private inline operator fun Number.times(f: Float) = toFloat() * f private fun VisualGroup3D.addSolid( context: GDMLTransformer, solid: GDMLSolid, - name: String? = null, + name: String = "", block: VisualObject3D.() -> Unit = {} ): VisualObject3D { context.solidAdded(solid) @@ -185,7 +187,8 @@ private fun VisualGroup3D.addDivisionVolume( ?: error("Volume with ref ${divisionVolume.volumeref.ref} could not be resolved") //TODO add divisions - add( + set( + EmptyName, volume( context, volume @@ -217,7 +220,7 @@ private fun volume( } } GDMLTransformer.Action.CACHE -> { - if (context.templates[solid.name] == null) { + if (context.templates.get(solid.name) == null) { context.templates.addSolid(context, solid, solid.name) { this.material = context.resolveColor(group, material, solid) } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt index 40ee092d..4d0f05be 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt @@ -12,7 +12,7 @@ import kotlinx.serialization.UseSerializers import kotlin.reflect.KClass @Serializable -data class Box( +class Box( val xSize: Float, val ySize: Float, val zSize: Float diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt index 2c9a0595..6057f628 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt @@ -3,12 +3,16 @@ package hep.dataforge.vis.spatial import hep.dataforge.context.AbstractPlugin import hep.dataforge.context.PluginFactory import hep.dataforge.context.PluginTag +import hep.dataforge.io.ConfigSerializer +import hep.dataforge.io.MetaSerializer +import hep.dataforge.io.NameSerializer import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.vis.common.VisualPlugin import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.contextual import kotlin.reflect.KClass class Visual3DPlugin(meta: Meta) : AbstractPlugin(meta) { @@ -28,6 +32,12 @@ class Visual3DPlugin(meta: Meta) : AbstractPlugin(meta) { override fun invoke(meta: Meta): Visual3DPlugin = Visual3DPlugin(meta) val serialModule = SerializersModule { + contextual(Point3DSerializer) + contextual(Point2DSerializer) + contextual(NameSerializer) + contextual(NameTokenSerializer) + contextual(MetaSerializer) + contextual(ConfigSerializer) polymorphic(VisualObject3D::class) { VisualGroup3D::class with VisualGroup3D.serializer() Proxy::class with Proxy.serializer() diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt new file mode 100644 index 00000000..ea0837b3 --- /dev/null +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -0,0 +1,92 @@ +@file:UseSerializers(Point3DSerializer::class, ConfigSerializer::class, NameTokenSerializer::class) +package hep.dataforge.vis.spatial + +import hep.dataforge.io.ConfigSerializer +import hep.dataforge.meta.Config +import hep.dataforge.meta.Configurable +import hep.dataforge.meta.MetaBuilder +import hep.dataforge.meta.set +import hep.dataforge.names.Name +import hep.dataforge.names.NameToken +import hep.dataforge.names.asName +import hep.dataforge.names.isEmpty +import hep.dataforge.vis.common.AbstractVisualGroup +import hep.dataforge.vis.common.VisualObject +import kotlinx.serialization.Serializable +import kotlinx.serialization.UseSerializers + +@Serializable +class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, Configurable { + /** + * A container for templates visible inside this group + */ + var templates: VisualGroup3D? = null + set(value) { + value?.parent = this + field = value + } + + @Serializable(ConfigSerializer::class) + override var properties: Config? = null + + override var position: Point3D? = null + override var rotation: Point3D? = null + override var scale: Point3D? = null + + private val _children = HashMap() + override val children: Map get() = _children + + override fun removeChild(token: NameToken) { + _children.remove(token) + } + + override fun setChild(token: NameToken, child: VisualObject?) { + if (child == null) { + _children.remove(token) + } else { + if (child.parent == null) { + child.parent = this + } else { + error("Can't reassign existing parent for $child") + } + _children[token] = child + } + } + + /** + * TODO add special static group to hold statics without propagation + */ + override fun addStatic(child: VisualObject) = setChild(NameToken(child.hashCode().toString()), child) + + override fun createGroup(name: Name): VisualGroup3D { + return when { + name.isEmpty() -> error("Should be unreachable") + name.length == 1 -> { + val token = name.first()!! + when (val current = children[token]) { + null -> VisualGroup3D().also { setChild(token, it) } + is VisualGroup3D -> current + else -> error("Can't create group with name $name because it exists and not a group") + } + } + else -> createGroup(name.first()!!.asName()).createGroup(name.cutFirst()) + } + } + + fun getTemplate(name: Name): VisualObject3D? = + templates?.get(name) as? VisualObject3D + ?: (parent as? VisualGroup3D)?.getTemplate(name) + + override fun MetaBuilder.updateMeta() { + set(TEMPLATES_KEY, templates?.toMeta()) + updatePosition() + updateChildren() + } + + companion object { + const val TEMPLATES_KEY = "templates" + } +} + +fun VisualGroup3D.group(key: String = "", action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = + VisualGroup3D().apply(action).also { set(key, it) } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index 564349bc..b873eed2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -2,18 +2,15 @@ package hep.dataforge.vis.spatial -import hep.dataforge.io.ConfigSerializer import hep.dataforge.io.NameSerializer import hep.dataforge.meta.* -import hep.dataforge.names.* +import hep.dataforge.names.plus import hep.dataforge.output.Output -import hep.dataforge.vis.common.AbstractVisualGroup import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY -import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers interface VisualObject3D : VisualObject { @@ -64,71 +61,6 @@ interface VisualObject3D : VisualObject { } } -@Serializable -class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, Configurable { - /** - * A container for templates visible inside this group - */ - var templates: VisualGroup3D? = null - set(value) { - value?.parent = this - field = value - } - - @Serializable(ConfigSerializer::class) - override var properties: Config? = null - - override var position: Point3D? = null - override var rotation: Point3D? = null - override var scale: Point3D? = null - - private val _children = HashMap() - override val children: Map get() = _children - - override fun removeChild(token: NameToken) { - _children.remove(token) - } - - override fun setChild(token: NameToken, child: VisualObject?) { - if (child == null) { - _children.remove(token) - } else { - _children[token] = child - } - } - - override fun createGroup(name: Name): VisualGroup3D { - return when{ - name.isEmpty() -> error("Should be unreachable") - name.length == 1 -> { - val token = name.first()!! - when (val current = children[token]) { - null -> VisualGroup3D().also { setChild(token, it) } - is VisualGroup3D -> current - else -> error("Can't create group with name $name because it exists and not a group") - } - } - else -> createGroup(name.first()!!.asName()).createGroup(name.cutFirst()) - } - } - - fun getTemplate(name: Name): VisualObject3D? = - templates?.get(name) as? VisualGroup3D ?: (parent as? VisualGroup3D)?.getTemplate(name) - - override fun MetaBuilder.updateMeta() { - set(TEMPLATES_KEY, templates?.toMeta()) - updatePosition() - updateChildren() - } - - companion object { - const val TEMPLATES_KEY = "templates" - } -} - -fun VisualGroup3D.group(key: String = "", action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = - VisualGroup3D().apply(action).also { set(key, it) } - fun Output.render(meta: Meta = EmptyMeta, action: VisualGroup3D.() -> Unit) = render(VisualGroup3D().apply(action), meta) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt index ffa92ae6..c7b3cbfa 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/serilization.kt @@ -1,7 +1,9 @@ package hep.dataforge.vis.spatial import hep.dataforge.names.NameToken +import hep.dataforge.names.toName import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor @Serializable private data class Point2DSerial(val x: Double, val y: Double) @@ -10,7 +12,7 @@ private data class Point2DSerial(val x: Double, val y: Double) private data class Point3DSerial(val x: Double, val y: Double, val z: Double) @Serializer(Point3D::class) -object Point3DSerializer : KSerializer{ +object Point3DSerializer : KSerializer { private val serializer = Point3DSerial.serializer() override val descriptor: SerialDescriptor get() = serializer.descriptor @@ -26,7 +28,7 @@ object Point3DSerializer : KSerializer{ } @Serializer(Point2D::class) -object Point2DSerializer : KSerializer{ +object Point2DSerializer : KSerializer { private val serializer = Point2DSerial.serializer() override val descriptor: SerialDescriptor get() = serializer.descriptor @@ -42,4 +44,14 @@ object Point2DSerializer : KSerializer{ } @Serializer(NameToken::class) -object NameTokenSerializer : KSerializer \ No newline at end of file +object NameTokenSerializer : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName("NameToken") + + override fun deserialize(decoder: Decoder): NameToken { + return decoder.decodeString().toName().first()!! + } + + override fun serialize(encoder: Encoder, obj: NameToken) { + encoder.encodeString(obj.toString()) + } +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt index 3d7f382b..523fd1ec 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt @@ -56,7 +56,7 @@ fun Meta?.jsMaterial(): Material { opacity = get("opacity")?.double ?: 1.0 transparent = get("transparent").boolean ?: (opacity < 1.0) //node["specularColor"]?.let { specular = it.color() } - side = 2 + //side = 2 } } } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index 1b93b1bc..8d39a08f 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -90,7 +90,7 @@ abstract class MeshThreeFactory(override val type: KClass(obj) { buildGeometry(it) } + return buildMesh(obj) { buildGeometry(it) } } companion object { diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt index da642588..9bd40342 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt @@ -5,6 +5,9 @@ import hep.dataforge.context.PluginFactory import hep.dataforge.context.PluginTag import hep.dataforge.context.content import hep.dataforge.meta.* +import hep.dataforge.names.Name +import hep.dataforge.names.asName +import hep.dataforge.names.isEmpty import hep.dataforge.vis.spatial.* import info.laht.threekt.cameras.Camera import info.laht.threekt.cameras.PerspectiveCamera @@ -46,7 +49,7 @@ class ThreePlugin : AbstractPlugin() { object3D.name = name.toString() group.add(object3D) } catch (ex: Throwable) { - console.error(ex) +// console.error(ex) logger.error(ex) { "Failed to render $name" } } } @@ -97,4 +100,12 @@ class ThreePlugin : AbstractPlugin() { override val type = ThreePlugin::class override fun invoke(meta: Meta) = ThreePlugin() } +} + +fun Object3D.findChild(name: Name): Object3D? { + return when { + name.isEmpty() -> this + name.length == 1 -> this.children.find { it.name == name.first()!!.toString() } + else -> findChild(name.first()!!.asName())?.findChild(name.cutFirst()) + } } \ No newline at end of file From 39b70a6064cdd4ad8f4feaddc4cb184198161537 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 20 Aug 2019 15:46:46 +0300 Subject: [PATCH 03/55] Transparency rules for gdml --- .../vis/spatial/gdml/GDMLTransformer.kt | 29 +++++++++++-------- .../dataforge/vis/spatial/gdml/visualGDML.kt | 15 ++++------ .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 4 ++- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index 12fc2aee..b4b4e3a4 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -4,17 +4,16 @@ import hep.dataforge.meta.Meta import hep.dataforge.meta.buildMeta import hep.dataforge.meta.builder import hep.dataforge.vis.spatial.VisualGroup3D -import scientifik.gdml.GDML -import scientifik.gdml.GDMLGroup -import scientifik.gdml.GDMLMaterial -import scientifik.gdml.GDMLSolid +import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.material +import scientifik.gdml.* import kotlin.random.Random class GDMLTransformer(val root: GDML) { private val materialCache = HashMap() private val random = Random(111) - enum class Action{ + enum class Action { ACCEPT, REJECT, CACHE @@ -26,23 +25,29 @@ class GDMLTransformer(val root: GDML) { val templates by lazy { VisualGroup3D() } var lUnit: LUnit = LUnit.MM - var resolveColor: ColorResolver = { material, _ -> + + var solidAction: (GDMLSolid) -> Action = { Action.CACHE } + var volumeAction: (GDMLGroup) -> Action = { Action.ACCEPT } + + + var transparent: GDMLVolume.(GDMLSolid?) -> Boolean = { !physVolumes.isEmpty() } + + internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid?) { + val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref) + val materialColor = materialCache.getOrPut(material) { buildMeta { "color" to random.nextInt(0, Int.MAX_VALUE) } } - if (this?.physVolumes?.isEmpty() != false) { - materialColor - } else { + obj.material = if (parent.transparent(solid)) { materialColor.builder().apply { "opacity" to 0.5 } + } else { + materialColor } } - var solidAction: (GDMLSolid) -> Action = { Action.CACHE } - var volumeAction: (GDMLGroup) -> Action = { Action.ACCEPT } - fun printStatistics() { println("Solids:") solidCounter.entries.sortedByDescending { it.value }.forEach { diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index f71b4948..a59b1a58 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -1,6 +1,5 @@ package hep.dataforge.vis.spatial.gdml -import hep.dataforge.meta.Meta import hep.dataforge.names.EmptyName import hep.dataforge.names.plus import hep.dataforge.vis.common.asName @@ -26,7 +25,7 @@ private fun VisualObject3D.withPosition( this@withPosition.rotationX = rotation.x() this@withPosition.rotationY = rotation.y() this@withPosition.rotationZ = rotation.z() - this@withPosition.rotationOrder=RotationOrder.ZXY + this@withPosition.rotationOrder = RotationOrder.ZXY } scale?.let { this@withPosition.scaleX = scale.x.toFloat() @@ -38,6 +37,7 @@ private fun VisualObject3D.withPosition( @Suppress("NOTHING_TO_INLINE") private inline operator fun Number.times(d: Double) = toDouble() * d + @Suppress("NOTHING_TO_INLINE") private inline operator fun Number.times(f: Float) = toFloat() * f @@ -211,18 +211,18 @@ private fun volume( if (group is GDMLVolume) { val solid = group.solidref.resolve(context.root) ?: error("Solid with tag ${group.solidref.ref} for volume ${group.name} not defined") - val material = group.materialref.resolve(context.root) ?: GDMLElement(group.materialref.ref) + //val material = group.materialref.resolve(context.root) ?: GDMLElement(group.materialref.ref) when (context.solidAction(solid)) { GDMLTransformer.Action.ACCEPT -> { addSolid(context, solid, solid.name) { - this.material = context.resolveColor(group, material, solid) + context.configureSolid(this, group, solid) } } GDMLTransformer.Action.CACHE -> { - if (context.templates.get(solid.name) == null) { + if (context.templates[solid.name] == null) { context.templates.addSolid(context, solid, solid.name) { - this.material = context.resolveColor(group, material, solid) + context.configureSolid(this, group, solid) } } ref(solid.name.asName(), solid.name) @@ -244,9 +244,6 @@ private fun volume( } } -typealias ColorResolver = GDMLGroup?.(GDMLMaterial, GDMLSolid?) -> Meta - - fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D { val context = GDMLTransformer(this).apply(block) diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 7de8ea84..444961fc 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -100,9 +100,11 @@ private class GDMLDemoApp : ApplicationBase() { } } + transparent = { !physVolumes.isEmpty() || (it?.name?.startsWith("Coil") ?: false) } + } launch { message("Rendering") } - val output = three.output(canvas){ + val output = three.output(canvas) { "axis" to { "size" to 100 } From dffc1e039b78e399d4620e8aa1fc67499f943cf8 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 9 Sep 2019 22:09:08 +0300 Subject: [PATCH 04/55] Properties for cached objects inside proxies (not tested) --- .../vis/common/AbstractVisualGroup.kt | 24 +++--- .../vis/common/AbstractVisualObject.kt | 21 +++++- .../hep/dataforge/vis/common/VisualObject.kt | 5 ++ .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 75 +++++++++++++++---- .../dataforge/vis/spatial/VisualGroup3D.kt | 31 ++++---- .../dataforge/vis/spatial/VisualObject3D.kt | 6 +- .../vis/spatial/three/ThreePlugin.kt | 3 +- .../vis/spatial/three/ThreeProxyFactory.kt | 19 ++++- 8 files changed, 134 insertions(+), 50 deletions(-) diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt index 23b889f6..aed504e9 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -28,31 +28,31 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { } } - private data class Listener(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) + private data class StructureChangeListeners(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) @Transient - private val listeners = HashSet() + private val structureChangeListeners = HashSet() /** * Add listener for children change */ override fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) { - listeners.add(Listener(owner, action)) + structureChangeListeners.add(StructureChangeListeners(owner, action)) } /** * Remove children change listener */ override fun removeChildrenChangeListener(owner: Any?) { - listeners.removeAll { it.owner === owner } + structureChangeListeners.removeAll { it.owner === owner } } -// /** -// * Propagate children change event upwards -// */ -// protected fun childrenChanged(name: Name, child: VisualObject?) { -// -// } + /** + * Propagate children change event upwards + */ + protected fun childrenChanged(name: Name, child: VisualObject?) { + structureChangeListeners.forEach { it.callback(name, child) } + } /** * Remove a child with given name token @@ -62,7 +62,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { /** * Add, remove or replace child with given name */ - protected abstract fun setChild(token: NameToken, child: VisualObject?) + protected abstract fun setChild(token: NameToken, child: VisualObject) /** * Add a static child. Statics could not be found by name, removed or replaced @@ -99,7 +99,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { parent[name.last()!!.asName()] = child } } - listeners.forEach { it.callback(name, child) } + structureChangeListeners.forEach { it.callback(name, child) } } operator fun set(key: String, child: VisualObject?) = if (key.isBlank()) { diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index 7b3b7a89..5d4622e2 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -2,6 +2,7 @@ package hep.dataforge.vis.common import hep.dataforge.meta.* import hep.dataforge.names.Name +import hep.dataforge.names.asName import kotlinx.serialization.Transient internal data class PropertyListener( @@ -14,6 +15,19 @@ abstract class AbstractVisualObject : VisualObject { @Transient override var parent: VisualObject? = null + override var style: Meta? = null + set(value) { + //notify about style removed + style?.items?.forEach {(name, value) -> + propertyChanged(name.asName(), value, null) + } + field = value + //notify about style adition + value?.items?.forEach { (name, value) -> + propertyChanged(name.asName(), null, value) + } + } + @Transient private val listeners = HashSet() @@ -31,7 +45,8 @@ abstract class AbstractVisualObject : VisualObject { listeners.removeAll { it.owner == owner } } - abstract var properties: Config? + protected abstract var properties: Config? + override val config: Config get() = properties ?: Config().also { config -> properties = config.apply { onChange(this, ::propertyChanged) } @@ -43,9 +58,9 @@ abstract class AbstractVisualObject : VisualObject { override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { - properties?.get(name) ?: parent?.getProperty(name, inherit) + style?.get(name) ?: properties?.get(name) ?: parent?.getProperty(name, inherit) } else { - properties?.get(name) + style?.get(name) ?: properties?.get(name) } } diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt index 1c15a0a5..9aebedbd 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt @@ -21,6 +21,11 @@ interface VisualObject : MetaRepr, Configurable { @Transient var parent: VisualObject? + /** + * A style which is set externally and could not be modified from inside + */ + var style: Meta? + /** * Set property for this object */ diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index f91ec56a..e1e0d559 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -1,4 +1,4 @@ -@file:UseSerializers(Point3DSerializer::class, NameSerializer::class) +@file:UseSerializers(Point3DSerializer::class, NameSerializer::class, ConfigSerializer::class) package hep.dataforge.vis.spatial @@ -8,15 +8,20 @@ import hep.dataforge.meta.Config import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaItem import hep.dataforge.names.Name +import hep.dataforge.names.NameToken +import hep.dataforge.names.asName import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.VisualGroup +import hep.dataforge.vis.common.VisualObject import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient import kotlinx.serialization.UseSerializers /** * A proxy [VisualObject3D] to reuse a template object */ @Serializable -class Proxy(val templateName: Name) : AbstractVisualObject(), VisualObject3D { +class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, VisualObject3D { override var position: Point3D? = null override var rotation: Point3D? = null @@ -28,10 +33,10 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualObject3D { /** * Recursively search for defined template in the parent */ - val template: VisualObject3D - get() = (parent as? VisualGroup3D)?.getTemplate(templateName) + val template: VisualObject3D by lazy { + (parent as? VisualGroup3D)?.getTemplate(templateName) ?: error("Template with name $templateName not found in $parent") - + } override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { @@ -45,16 +50,58 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualObject3D { //TODO add reference to child updatePosition() } -} -//fun VisualGroup3D.proxy( -// templateName: Name, -// //name: String? = null, -// builder: VisualGroup3D.() -> Unit -//): Proxy { -// val template = getTemplate(templateName) ?: templates.builder() -// return Proxy(this, templateName).also { set(name, it) } -//} + override val children: Map + get() = (template as? VisualGroup)?.children?.mapValues { + ProxyChild(it.key.asName()) + } ?: emptyMap() + + private data class ProxyChangeListeners(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) + + @Transient + private val listeners = HashSet() + + override fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) { + listeners.add(ProxyChangeListeners(owner, action)) + } + + override fun removeChildrenChangeListener(owner: Any?) { + listeners.removeAll { it.owner == owner } + } + + override fun set(name: Name, child: VisualObject?) { + error("Content change not supported for proxy") + } + + private val propertyCache: HashMap = HashMap() + + private fun Config.attachListener(obj: VisualObject) { + onChange(this@Proxy) { name, before, after -> + listeners.forEach { listener -> + listener.callback(name, obj) + } + } + } + + inner class ProxyChild(val name: Name) : AbstractVisualObject() { + override var properties: Config? + get() = propertyCache.getOrPut(name) { + Config().apply { + attachListener(this@ProxyChild) + } + } + set(value) { + if (value == null) { + propertyCache.remove(name)?.removeListener(this@Proxy) + } else { + propertyCache[name] = value.apply { + attachListener(this@ProxyChild) + } + } + } + + } +} inline fun VisualGroup3D.ref( templateName: Name, diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index ea0837b3..20024ad9 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -1,9 +1,9 @@ @file:UseSerializers(Point3DSerializer::class, ConfigSerializer::class, NameTokenSerializer::class) + package hep.dataforge.vis.spatial import hep.dataforge.io.ConfigSerializer import hep.dataforge.meta.Config -import hep.dataforge.meta.Configurable import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.set import hep.dataforge.names.Name @@ -16,7 +16,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers @Serializable -class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, Configurable { +class VisualGroup3D() : AbstractVisualGroup(), VisualObject3D { /** * A container for templates visible inside this group */ @@ -36,21 +36,26 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D, Configurable { private val _children = HashMap() override val children: Map get() = _children - override fun removeChild(token: NameToken) { - _children.remove(token) + init { + //Do after deserialization + _children.values.forEach { + it.parent = this + } } - override fun setChild(token: NameToken, child: VisualObject?) { - if (child == null) { - _children.remove(token) + override fun removeChild(token: NameToken) { + _children.remove(token) + childrenChanged(token.asName(), null) + } + + override fun setChild(token: NameToken, child: VisualObject) { + if (child.parent == null) { + child.parent = this } else { - if (child.parent == null) { - child.parent = this - } else { - error("Can't reassign existing parent for $child") - } - _children[token] = child + error("Can't reassign existing parent for $child") } + _children[token] = child + childrenChanged(token.asName(), child) } /** diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index b873eed2..f36a33d0 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -90,15 +90,15 @@ var VisualObject3D.detail: Int? get() = getProperty(DETAIL_KEY, false).int set(value) = setProperty(DETAIL_KEY, value) -var VisualObject3D.material: Meta? +var VisualObject.material: Meta? get() = getProperty(MATERIAL_KEY).node set(value) = setProperty(MATERIAL_KEY, value) -var VisualObject3D.visible: Boolean? +var VisualObject.visible: Boolean? get() = getProperty(VISIBLE_KEY).boolean set(value) = setProperty(VISIBLE_KEY, value) -fun VisualObject3D.color(rgb: Int) { +fun VisualObject.color(rgb: Int) { material = buildMeta { "color" to rgb } } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt index 9bd40342..8621091c 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreePlugin.kt @@ -40,6 +40,7 @@ class ThreePlugin : AbstractPlugin() { fun buildObject3D(obj: VisualObject3D): Object3D { return when (obj) { + is Proxy -> proxyFactory(obj) is VisualGroup3D -> { val group = info.laht.threekt.objects.Group() obj.children.forEach { (name, child) -> @@ -49,7 +50,6 @@ class ThreePlugin : AbstractPlugin() { object3D.name = name.toString() group.add(object3D) } catch (ex: Throwable) { -// console.error(ex) logger.error(ex) { "Failed to render $name" } } } @@ -61,7 +61,6 @@ class ThreePlugin : AbstractPlugin() { } } is Composite -> compositeFactory(obj) - is Proxy -> proxyFactory(obj) else -> { //find specialized factory for this type if it is present val factory = findObjectFactory(obj::class) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt index bb037270..f198e470 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt @@ -1,14 +1,23 @@ package hep.dataforge.vis.spatial.three +import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.spatial.Proxy import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.material +import hep.dataforge.vis.spatial.visible import info.laht.threekt.core.Object3D +import info.laht.threekt.objects.Mesh class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { private val cache = HashMap() override val type = Proxy::class + private fun Mesh.updateProperties(obj: VisualObject?) { + material = obj?.material.jsMaterial() + visible = obj?.visible ?: true + } + override fun invoke(obj: Proxy): Object3D { val template = obj.template val cachedObject = cache.getOrPut(template) { @@ -16,9 +25,13 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { } //val mesh = Mesh(templateMesh.geometry as BufferGeometry, templateMesh.material) - val mesh = cachedObject.clone() + val object3D = cachedObject.clone() + object3D.updatePosition(obj) - mesh.updatePosition(obj) - return mesh + obj.onChildrenChange(object3D) { name, propertyHolder -> + (object3D.findChild(name) as? Mesh)?.updateProperties(propertyHolder) + } + + return object3D } } \ No newline at end of file From e5a27ab56f2f9283018d05bd29f00ad3a261e0c8 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 15 Sep 2019 11:30:25 +0300 Subject: [PATCH 05/55] Updated plugin and GDML conversion optimization --- build.gradle.kts | 15 ++--- dataforge-vis-common/build.gradle.kts | 2 +- .../vis/common/AbstractVisualGroup.kt | 2 +- dataforge-vis-spatial-gdml/build.gradle.kts | 6 +- .../vis/spatial/gdml/GDMLTransformer.kt | 13 ++++- .../vis/spatial/gdml/optimizations.kt | 58 +++++++++++++++++++ .../dataforge/vis/spatial/gdml/visualGDML.kt | 52 +++++++++++------ .../dataforge/vis/spatial/gdml/testMain.kt | 24 ++++++-- dataforge-vis-spatial/build.gradle.kts | 2 +- .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 6 +- .../dataforge/vis/spatial/Visual3DPlugin.kt | 5 +- .../dataforge/vis/spatial/VisualGroup3D.kt | 5 +- .../hep/dataforge/vis/spatial/geometry.kt | 18 ++++++ .../hep/dataforge/vis/spatial/GroupTest.kt | 15 ++--- .../vis/spatial/SerializationTest.kt | 2 +- 15 files changed, 172 insertions(+), 53 deletions(-) create mode 100644 dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt diff --git a/build.gradle.kts b/build.gradle.kts index ada9bd4c..4a01e294 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,17 +1,15 @@ val dataforgeVersion by extra("0.1.3") plugins{ - val kotlinVersion = "1.3.50-eap-5" + val kotlinVersion = "1.3.50" kotlin("jvm") version kotlinVersion apply false - id("kotlin2js") version kotlinVersion apply false id("kotlin-dce-js") version kotlinVersion apply false - id("org.jetbrains.kotlin.frontend") version "0.0.45" apply false - id("scientifik.mpp") version "0.1.4" apply false - id("scientifik.jvm") version "0.1.4" apply false - id("scientifik.js") version "0.1.4" apply false - id("scientifik.publish") version "0.1.4" apply false - id("org.openjfx.javafxplugin") version "0.0.7" apply false + id("scientifik.mpp") version "0.1.7" apply false + id("scientifik.jvm") version "0.1.7" apply false + id("scientifik.js") version "0.1.7" apply false + id("scientifik.publish") version "0.1.7" apply false + id("org.openjfx.javafxplugin") version "0.0.8" apply false } allprojects { @@ -19,7 +17,6 @@ allprojects { mavenLocal() jcenter() maven("https://kotlin.bintray.com/kotlinx") - maven("http://npm.mipt.ru:8081/artifactory/gradle-dev-local") maven("https://kotlin.bintray.com/js-externals") maven("https://dl.bintray.com/pdvrieze/maven") maven("https://dl.bintray.com/kotlin/kotlin-eap") diff --git a/dataforge-vis-common/build.gradle.kts b/dataforge-vis-common/build.gradle.kts index e57c78bb..2898a778 100644 --- a/dataforge-vis-common/build.gradle.kts +++ b/dataforge-vis-common/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } scientifik{ - serialization = true + withSerialization() } val dataforgeVersion: String by rootProject.extra diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt index aed504e9..73b5bbf2 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -108,7 +108,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { set(key.asName(), child) } - operator fun set(key: String?, child: VisualObject?) = set(key ?: "", child) +// operator fun set(key: String?, child: VisualObject?) = set(key ?: "", child) protected fun MetaBuilder.updateChildren() { //adding named children diff --git a/dataforge-vis-spatial-gdml/build.gradle.kts b/dataforge-vis-spatial-gdml/build.gradle.kts index e2c711c6..1a76a7a7 100644 --- a/dataforge-vis-spatial-gdml/build.gradle.kts +++ b/dataforge-vis-spatial-gdml/build.gradle.kts @@ -2,12 +2,16 @@ plugins { id("scientifik.mpp") } +scientifik{ + withSerialization() +} + kotlin { sourceSets { val commonMain by getting { dependencies { api(project(":dataforge-vis-spatial")) - api("scientifik:gdml:0.1.4-dev-1") + api("scientifik:gdml:0.1.4-dev-3") } } val jsMain by getting { diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index b4b4e3a4..200ab034 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -64,9 +64,18 @@ class GDMLTransformer(val root: GDML) { var onFinish: GDMLTransformer.() -> Unit = {} - internal fun finished(final: VisualGroup3D) { + var optimizeSingleChild = false + + //var optimizations: List = emptyList() + + internal fun finalize(final: VisualGroup3D): VisualGroup3D { +// var res = final +// optimizations.forEach { +// res = it(res) +// } final.templates = templates onFinish(this@GDMLTransformer) + return final } -} \ No newline at end of file +} diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt new file mode 100644 index 00000000..ef842aa7 --- /dev/null +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt @@ -0,0 +1,58 @@ +package hep.dataforge.vis.spatial.gdml + +import hep.dataforge.meta.update +import hep.dataforge.names.asName +import hep.dataforge.vis.common.VisualGroup +import hep.dataforge.vis.spatial.Point3D +import hep.dataforge.vis.spatial.VisualGroup3D +import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.plus +import kotlin.collections.component1 +import kotlin.collections.component2 + +typealias GDMLOptimization = GDMLTransformer.(VisualGroup3D) -> VisualGroup3D + +/** + * Collapse nodes with single child + */ +val optimizeSingleChild: GDMLOptimization = { tree -> + fun VisualGroup.replaceChildren() { + children.forEach { (key, child) -> + if (child is VisualGroup3D && child.children.size == 1) { + val newChild = child.children.values.first().apply { + config.update(child.config) + } + + if (newChild is VisualObject3D) { + newChild.apply { + position += child.position + rotation += child.rotation + scale = when { + scale == null && child.scale == null -> null + scale == null -> child.scale + child.scale == null -> scale + else -> Point3D( + scale!!.x * child.scale!!.x, + scale!!.y * child.scale!!.y, + scale!!.z * child.scale!!.z + ) + } + } + } + + if (newChild is VisualGroup) { + newChild.replaceChildren() + } + + //actual replacement + set(key.asName(), newChild) + } else if (child is VisualGroup) { + child.replaceChildren() + } + } + } + + tree.replaceChildren() + + tree +} \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index a59b1a58..030b173b 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -149,13 +149,32 @@ private fun VisualGroup3D.addPhysicalVolume( when (context.volumeAction(volume)) { GDMLTransformer.Action.ACCEPT -> { - this[physVolume.name] = volume(context, volume).apply { - withPosition( - context.lUnit, - physVolume.resolvePosition(context.root), - physVolume.resolveRotation(context.root), - physVolume.resolveScale(context.root) - ) + val group = volume(context, volume) + //optimizing single child case + if (context.optimizeSingleChild && group.children.size == 1) { + this[physVolume.name ?: "@unnamed"] = group.children.values.first().apply { + //Must ser this to avoid parent reset error + parent = null + //setting offset from physical volume + withPosition( + context.lUnit, + physVolume.resolvePosition(context.root), + physVolume.resolveRotation(context.root), + physVolume.resolveScale(context.root) + ) + // in case when both phys volume and underlying volume have offset + position += group.position + rotation += group.rotation + } + } else { + this[physVolume.name ?: "@unnamed"] = group.apply { + withPosition( + context.lUnit, + physVolume.resolvePosition(context.root), + physVolume.resolveRotation(context.root), + physVolume.resolveScale(context.root) + ) + } } } GDMLTransformer.Action.CACHE -> { @@ -164,7 +183,7 @@ private fun VisualGroup3D.addPhysicalVolume( context.templates[name] = volume(context, volume) } - this[physVolume.name] = Proxy(name).apply { + this[physVolume.name ?: ""] = Proxy(name).apply { withPosition( context.lUnit, physVolume.resolvePosition(context.root), @@ -196,12 +215,12 @@ private fun VisualGroup3D.addDivisionVolume( ) } -private fun VisualGroup3D.addVolume( - context: GDMLTransformer, - group: GDMLGroup -) { - this[group.name] = volume(context, group) -} +//private fun VisualGroup3D.addVolume( +// context: GDMLTransformer, +// group: GDMLGroup +//) { +// this[group.name] = volume(context, group) +//} private fun volume( context: GDMLTransformer, @@ -211,7 +230,6 @@ private fun volume( if (group is GDMLVolume) { val solid = group.solidref.resolve(context.root) ?: error("Solid with tag ${group.solidref.ref} for volume ${group.name} not defined") - //val material = group.materialref.resolve(context.root) ?: GDMLElement(group.materialref.ref) when (context.solidAction(solid)) { GDMLTransformer.Action.ACCEPT -> { @@ -248,7 +266,5 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D { val context = GDMLTransformer(this).apply(block) - return volume(context, world).also { - context.finished(it) - } + return context.finalize(volume(context, world)) } \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt index 943b4afc..36584814 100644 --- a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt +++ b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt @@ -1,6 +1,6 @@ package hep.dataforge.vis.spatial.gdml -import hep.dataforge.names.toName +import hep.dataforge.vis.spatial.Visual3DPlugin import hep.dataforge.vis.spatial.VisualGroup3D import nl.adaptivity.xmlutil.StAXReader import scientifik.gdml.GDML @@ -19,17 +19,29 @@ fun main() { volume.name.startsWith("ecal") -> GDMLTransformer.Action.CACHE volume.name.startsWith("U") -> GDMLTransformer.Action.CACHE volume.name.startsWith("V") -> GDMLTransformer.Action.CACHE + volume.name.startsWith("tof") -> GDMLTransformer.Action.CACHE else -> GDMLTransformer.Action.ACCEPT } } + optimizeSingleChild = true + //optimizations = listOf(optimizeSingleChild) onFinish = { printStatistics() } } - val template = visual.getTemplate("volumes.ecal01mod".toName()) - println(template) - visual.flatMap { (it as? VisualGroup3D) ?: listOf(it) }.forEach { - if(it.parent==null) error("") - } + val string = Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual) + + val tmpFile = File.createTempFile("dataforge-visual", ".json") + + tmpFile.writeText(string) + + println(tmpFile.canonicalPath) + + +// val template = visual.getTemplate("volumes.ecal01mod".toName()) +// println(template) +// visual.flatMap { (it as? VisualGroup3D) ?: listOf(it) }.forEach { +// if(it.parent==null) error("") +// } //readLine() //val meta = visual.toMeta() // val tmpFile = File.createTempFile("dataforge-visual", "json") diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index d2eb5d37..25a1dc19 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } scientifik{ - serialization = true + withSerialization() } kotlin { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index e1e0d559..3c9ca492 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -33,10 +33,10 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua /** * Recursively search for defined template in the parent */ - val template: VisualObject3D by lazy { - (parent as? VisualGroup3D)?.getTemplate(templateName) + val template: VisualObject3D + get() = (parent as? VisualGroup3D)?.getTemplate(templateName) ?: error("Template with name $templateName not found in $parent") - } + override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt index 6057f628..2d5089e8 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt @@ -8,6 +8,7 @@ import hep.dataforge.io.MetaSerializer import hep.dataforge.io.NameSerializer import hep.dataforge.meta.* import hep.dataforge.names.Name +import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.VisualPlugin import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration @@ -38,13 +39,15 @@ class Visual3DPlugin(meta: Meta) : AbstractPlugin(meta) { contextual(NameTokenSerializer) contextual(MetaSerializer) contextual(ConfigSerializer) - polymorphic(VisualObject3D::class) { + + polymorphic(VisualObject::class,VisualObject3D::class) { VisualGroup3D::class with VisualGroup3D.serializer() Proxy::class with Proxy.serializer() Composite::class with Composite.serializer() Tube::class with Tube.serializer() Box::class with Box.serializer() Convex::class with Convex.serializer() + addSubclass(Extruded.serializer()) } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 20024ad9..5cf750a0 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -12,6 +12,7 @@ import hep.dataforge.names.asName import hep.dataforge.names.isEmpty import hep.dataforge.vis.common.AbstractVisualGroup import hep.dataforge.vis.common.VisualObject +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers @@ -26,13 +27,13 @@ class VisualGroup3D() : AbstractVisualGroup(), VisualObject3D { field = value } - @Serializable(ConfigSerializer::class) - override var properties: Config? = null + public override var properties: Config? = null override var position: Point3D? = null override var rotation: Point3D? = null override var scale: Point3D? = null + @SerialName("children") private val _children = HashMap() override val children: Map get() = _children diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt index 20b537b2..4ef1510c 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt @@ -26,6 +26,24 @@ expect class Point3D(x: Number, y: Number, z: Number) { var z: Double } +operator fun Point3D?.plus(other: Point3D?): Point3D? { + return when { + this == null && other == null -> null + this == null -> other + other == null -> this + else -> Point3D(x + other.x, y + other.y, z + other.z) + } +} + +operator fun Point3D?.minus(other: Point3D?): Point3D? { + return when { + this == null && other == null -> null + this == null -> Point3D(-other!!.x, -other.y, -other.z) + other == null -> this + else -> Point3D(x - other.x, y - other.y, z - other.z) + } +} + operator fun Point3D.component1() = x operator fun Point3D.component2() = y operator fun Point3D.component3() = z diff --git a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/GroupTest.kt b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/GroupTest.kt index e7ef1eeb..c1e81721 100644 --- a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/GroupTest.kt +++ b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/GroupTest.kt @@ -1,15 +1,16 @@ package hep.dataforge.vis.spatial import hep.dataforge.vis.common.Colors +import hep.dataforge.vis.common.get import kotlin.math.PI import kotlin.test.Test import kotlin.test.assertEquals class GroupTest { @Test - fun testGroupWithComposite(){ - val group = VisualGroup3D().apply{ - union { + fun testGroupWithComposite() { + val group = VisualGroup3D().apply { + union("union") { box(100, 100, 100) { z = 100 rotationX = PI / 4 @@ -21,7 +22,7 @@ class GroupTest { "opacity" to 0.3 } } - intersect{ + intersect("intersect") { box(100, 100, 100) { z = 100 rotationX = PI / 4 @@ -31,7 +32,7 @@ class GroupTest { y = 300 color(Colors.red) } - subtract{ + subtract("subtract") { box(100, 100, 100) { z = 100 rotationX = PI / 4 @@ -44,7 +45,7 @@ class GroupTest { } assertEquals(3, group.count()) - assertEquals(300.0,group.toList()[1].y.toDouble()) - assertEquals(-300.0,group.toList()[2].y.toDouble()) + assertEquals(300.0, (group["intersect"] as VisualObject3D).y.toDouble()) + assertEquals(-300.0, (group["subtract"] as VisualObject3D).y.toDouble()) } } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/SerializationTest.kt b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/SerializationTest.kt index 87668852..805fee43 100644 --- a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/SerializationTest.kt +++ b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/SerializationTest.kt @@ -15,6 +15,6 @@ class SerializationTest { val meta = cube.toMeta() println(meta) val newCube = Box(Global,null, meta) - assertEquals(cube,newCube) + assertEquals(cube.toMeta(),newCube.toMeta()) } } \ No newline at end of file From e9d73b28fe207751ce4a9883c2f6c76ba3bc47a5 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 15 Sep 2019 19:09:08 +0300 Subject: [PATCH 06/55] BMN rendering optimization --- .../vis/spatial/gdml/GDMLTransformer.kt | 12 +++---- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 32 +++++++++++++++---- .../dataforge/vis/spatial/VisualGroup3D.kt | 2 +- .../dataforge/vis/spatial/VisualObject3D.kt | 10 +++++- .../vis/spatial/three/ThreeFactory.kt | 12 +++++-- .../vis/spatial/three/ThreeOutput.kt | 2 +- .../kotlin/info/laht/threekt/core/Layers.kt | 2 +- 7 files changed, 52 insertions(+), 20 deletions(-) diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index 200ab034..953474ca 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.Meta import hep.dataforge.meta.buildMeta -import hep.dataforge.meta.builder import hep.dataforge.vis.spatial.VisualGroup3D import hep.dataforge.vis.spatial.VisualObject3D import hep.dataforge.vis.spatial.material @@ -30,9 +29,9 @@ class GDMLTransformer(val root: GDML) { var volumeAction: (GDMLGroup) -> Action = { Action.ACCEPT } - var transparent: GDMLVolume.(GDMLSolid?) -> Boolean = { !physVolumes.isEmpty() } + var configure: VisualObject3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { _, _ -> } - internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid?) { + internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid) { val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref) val materialColor = materialCache.getOrPut(material) { @@ -41,11 +40,8 @@ class GDMLTransformer(val root: GDML) { } } - obj.material = if (parent.transparent(solid)) { - materialColor.builder().apply { "opacity" to 0.5 } - } else { - materialColor - } + obj.material = materialColor + obj.configure(parent, solid) } fun printStatistics() { diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 444961fc..bad2b014 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -6,6 +6,7 @@ import hep.dataforge.vis.hmr.startApplication import hep.dataforge.vis.spatial.gdml.GDMLTransformer import hep.dataforge.vis.spatial.gdml.LUnit import hep.dataforge.vis.spatial.gdml.toVisual +import hep.dataforge.vis.spatial.opacity import hep.dataforge.vis.spatial.three.ThreePlugin import hep.dataforge.vis.spatial.three.output import kotlinx.coroutines.CoroutineScope @@ -93,22 +94,41 @@ private class GDMLDemoApp : ApplicationBase() { lUnit = LUnit.CM volumeAction = { volume -> when { - volume.name.startsWith("ecal") -> GDMLTransformer.Action.REJECT + volume.name.startsWith("ecal01lay") -> GDMLTransformer.Action.REJECT + volume.name.startsWith("ecal") -> GDMLTransformer.Action.CACHE + volume.name.startsWith("UPBL") -> GDMLTransformer.Action.REJECT + volume.name.startsWith("USCL") -> GDMLTransformer.Action.REJECT volume.name.startsWith("U") -> GDMLTransformer.Action.CACHE + volume.name.startsWith("VPBL") -> GDMLTransformer.Action.REJECT + volume.name.startsWith("VSCL") -> GDMLTransformer.Action.REJECT volume.name.startsWith("V") -> GDMLTransformer.Action.CACHE else -> GDMLTransformer.Action.ACCEPT } } - transparent = { !physVolumes.isEmpty() || (it?.name?.startsWith("Coil") ?: false) } - + configure = { parent, solid -> + if (!parent.physVolumes.isEmpty()) { + opacity = 0.3 + } + if (solid.name.startsWith("Coil") + || solid.name.startsWith("Yoke") + || solid.name.startsWith("Magnet") + || solid.name.startsWith("Pole") + ) { + opacity = 0.3 + } + } } launch { message("Rendering") } val output = three.output(canvas) { - "axis" to { - "size" to 100 - } +// "axis" to { +// "size" to 100 +// } } + //make top layer visible + //output.camera.layers.disable(0) + output.camera.layers.enable(1) + output.render(visual) launch { message(null) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 5cf750a0..98995f59 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers @Serializable -class VisualGroup3D() : AbstractVisualGroup(), VisualObject3D { +class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { /** * A container for templates visible inside this group */ diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index f36a33d0..c61a9df2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -94,12 +94,20 @@ var VisualObject.material: Meta? get() = getProperty(MATERIAL_KEY).node set(value) = setProperty(MATERIAL_KEY, value) +var VisualObject.opacity: Double + get() = material?.get("opacity").double ?: 1.0 + set(value) { + material = (material?.builder() ?: MetaBuilder()).apply { + "opacity" to value + } + } + var VisualObject.visible: Boolean? get() = getProperty(VISIBLE_KEY).boolean set(value) = setProperty(VISIBLE_KEY, value) fun VisualObject.color(rgb: Int) { - material = buildMeta { "color" to rgb } + material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb } } fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) { diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index 8d39a08f..bb5dc5b2 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -43,6 +43,13 @@ internal fun Object3D.updatePosition(obj: VisualObject3D) { updateMatrix() } +/** + * Count number of layers to the top object. Return 1 if this is top layer + */ +val VisualObject3D.layer: Int + get() = getProperty(MeshThreeFactory.LAYER_KEY).int ?: ((parent as? VisualObject3D)?.layer ?: 0 + 1) + + internal fun Mesh.updateFrom(obj: T) { matrixAutoUpdate = false @@ -61,8 +68,9 @@ internal fun Mesh.updateFrom(obj: T) { //set position for mesh updatePosition(obj) - obj.getProperty(MeshThreeFactory.LAYER_KEY).int?.let { - layers.set(it) + layers.enable(obj.layer) + children.forEach { + it.layers.enable(obj.layer) } } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt index 81de1a89..fb191900 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt @@ -27,7 +27,7 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output Int = { element.clientWidth }) { val width by meta.number(computeWidth(element)).int diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt index b33a302b..503878d1 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/info/laht/threekt/core/Layers.kt @@ -71,5 +71,5 @@ external class Layers { * Returns true if this and the passed layers object are members of the same set of layers. * @param layers a Layers object */ - fun test(layers: Int) + fun test(layers: Layers): Boolean } \ No newline at end of file From 41a987bcc4496b94b5d4a087f9a5f68506d73d49 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 15 Sep 2019 19:50:18 +0300 Subject: [PATCH 07/55] Sidebar and layering support --- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 36 +++++++++++++++++-- .../src/jsMain/web/index.html | 9 +++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index bad2b014..fa56fd8b 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -7,11 +7,17 @@ import hep.dataforge.vis.spatial.gdml.GDMLTransformer import hep.dataforge.vis.spatial.gdml.LUnit import hep.dataforge.vis.spatial.gdml.toVisual import hep.dataforge.vis.spatial.opacity +import hep.dataforge.vis.spatial.three.ThreeOutput import hep.dataforge.vis.spatial.three.ThreePlugin import hep.dataforge.vis.spatial.three.output import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import kotlinx.html.InputType +import kotlinx.html.dom.append +import kotlinx.html.js.div +import kotlinx.html.js.input +import org.w3c.dom.Element import org.w3c.dom.HTMLDivElement import org.w3c.dom.events.Event import org.w3c.files.FileList @@ -74,6 +80,29 @@ private class GDMLDemoApp : ApplicationBase() { } } + fun setupSidebar(element: Element, output: ThreeOutput) { + element.clear() + (0..9).forEach{layer-> + element.append { + div("row") { + +"layer $layer" + input(type = InputType.checkBox).apply { + if (layer == 0 || layer == 1) { + checked = true + } + onchange = { + if (checked) { + output.camera.layers.enable(layer) + } else { + output.camera.layers.disable(layer) + } + } + } + } + } + } + } + override fun start(state: Map) { @@ -81,7 +110,8 @@ private class GDMLDemoApp : ApplicationBase() { val three = context.plugins.load(ThreePlugin) //val url = URL("https://drive.google.com/open?id=1w5e7fILMN83JGgB8WANJUYm8OW2s0WVO") - val canvas = document.getElementById("canvas") ?: error("Element with id canvas not found on page") + val canvas = document.getElementById("canvas") ?: error("Element with id 'canvas' not found on page") + val sidebar = document.getElementById("sidebar") ?: error("Element with id 'sidebar' not found on page") canvas.clear() val action: suspend CoroutineScope.(String) -> Unit = { it -> @@ -121,7 +151,7 @@ private class GDMLDemoApp : ApplicationBase() { } launch { message("Rendering") } val output = three.output(canvas) { -// "axis" to { + // "axis" to { // "size" to 100 // } } @@ -129,6 +159,8 @@ private class GDMLDemoApp : ApplicationBase() { //output.camera.layers.disable(0) output.camera.layers.enable(1) + setupSidebar(sidebar, output) + output.render(visual) launch { message(null) diff --git a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html index 83164142..483a1de8 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html +++ b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html @@ -2,7 +2,7 @@ - + Three js demo for particle physics @@ -21,7 +21,12 @@ -
+
+
+
+ +
+
diff --git a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt index 36584814..37e45cda 100644 --- a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt +++ b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt @@ -2,6 +2,7 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.vis.spatial.Visual3DPlugin import hep.dataforge.vis.spatial.VisualGroup3D +import hep.dataforge.vis.spatial.opacity import nl.adaptivity.xmlutil.StAXReader import scientifik.gdml.GDML import java.io.File @@ -16,14 +17,32 @@ fun main() { lUnit = LUnit.CM volumeAction = { volume -> when { + volume.name.startsWith("ecal01lay") -> GDMLTransformer.Action.REJECT volume.name.startsWith("ecal") -> GDMLTransformer.Action.CACHE + volume.name.startsWith("UPBL") -> GDMLTransformer.Action.REJECT + volume.name.startsWith("USCL") -> GDMLTransformer.Action.REJECT volume.name.startsWith("U") -> GDMLTransformer.Action.CACHE + volume.name.startsWith("VPBL") -> GDMLTransformer.Action.REJECT + volume.name.startsWith("VSCL") -> GDMLTransformer.Action.REJECT volume.name.startsWith("V") -> GDMLTransformer.Action.CACHE - volume.name.startsWith("tof") -> GDMLTransformer.Action.CACHE else -> GDMLTransformer.Action.ACCEPT } } - optimizeSingleChild = true + + solidConfiguration = { parent, solid -> + if (parent.physVolumes.isNotEmpty()) { + opacity = 0.3 + } + if (solid.name.startsWith("Coil") + || solid.name.startsWith("Yoke") + || solid.name.startsWith("Magnet") + || solid.name.startsWith("Pole") + ) { + opacity = 0.3 + } + } + +// optimizeSingleChild = true //optimizations = listOf(optimizeSingleChild) onFinish = { printStatistics() } } @@ -36,7 +55,6 @@ fun main() { println(tmpFile.canonicalPath) - // val template = visual.getTemplate("volumes.ecal01mod".toName()) // println(template) // visual.flatMap { (it as? VisualGroup3D) ?: listOf(it) }.forEach { diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index 25a1dc19..0916534d 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -31,6 +31,8 @@ kotlin { implementation(npm("@hi-level/three-csg", "1.0.6")) implementation(npm("style-loader")) implementation(npm("element-resize-event")) + api("kotlin.js.externals:kotlin-js-jquery:3.2.0-0") + implementation(npm("jquery.fancytree","2.32.0")) } } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 98995f59..8c75a314 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -11,6 +11,7 @@ import hep.dataforge.names.NameToken import hep.dataforge.names.asName import hep.dataforge.names.isEmpty import hep.dataforge.vis.common.AbstractVisualGroup +import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.common.VisualObject import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -37,13 +38,6 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { private val _children = HashMap() override val children: Map get() = _children - init { - //Do after deserialization - _children.values.forEach { - it.parent = this - } - } - override fun removeChild(token: NameToken) { _children.remove(token) childrenChanged(token.asName(), null) @@ -94,5 +88,21 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { } } +/** + * A fix for serialization bug that writes all proper parents inside the tree after deserialization + */ +fun VisualGroup.attachChildren() { + this.children.values.forEach { + it.parent = this + (it as? VisualGroup)?.attachChildren() + } + if(this is VisualGroup3D){ + templates?.apply { + parent = this@attachChildren + attachChildren() + } + } +} + fun VisualGroup3D.group(key: String = "", action: VisualGroup3D.() -> Unit = {}): VisualGroup3D = VisualGroup3D().apply(action).also { set(key, it) } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index c61a9df2..c57e6841 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -9,6 +9,7 @@ import hep.dataforge.output.Output import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY +import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY import kotlinx.serialization.UseSerializers @@ -34,6 +35,7 @@ interface VisualObject3D : VisualObject { val MATERIAL_KEY = "material".asName() val VISIBLE_KEY = "visible".asName() val DETAIL_KEY = "detail".asName() + val LAYER_KEY = "layer".asName() val x = "x".asName() val y = "y".asName() @@ -61,6 +63,15 @@ interface VisualObject3D : VisualObject { } } +/** + * Count number of layers to the top object. Return 1 if this is top layer + */ +var VisualObject3D.layer: Int + get() = getProperty(LAYER_KEY).int ?: 0 + set(value) { + setProperty(LAYER_KEY, value) + } + fun Output.render(meta: Meta = EmptyMeta, action: VisualGroup3D.() -> Unit) = render(VisualGroup3D().apply(action), meta) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/Fancytree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/Fancytree.kt new file mode 100644 index 00000000..c19a8a8b --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/Fancytree.kt @@ -0,0 +1,427 @@ +@file:JsModule("jquery.fancytree") +@file:JsNonModule +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION" +) + +package ru.mipt.npm.fancytreekt + +import js.externals.jquery.JQuery +import js.externals.jquery.JQueryEventObject +import js.externals.jquery.JQueryPromise +import org.w3c.dom.Element +import org.w3c.dom.HTMLElement +import org.w3c.dom.HTMLTableRowElement +import org.w3c.dom.events.Event + +external fun createTree(id: String, options: FancytreeOptions = definedExternally /* null */): Fancytree + +external interface Fancytree { + var `$div`: JQuery<*> + var widget: Any + var rootNode: FancytreeNode + var `$container`: JQuery<*> + var focusNode: FancytreeNode + var options: FancytreeOptions + fun activateKey(key: String): FancytreeNode + fun activateKey(key: Boolean): FancytreeNode + fun applyPatch(patchList: Array): JQueryPromise + fun changeRefKey(oldRefKey: String, newRefKey: String) + fun clearCookies() + fun clearFilter() + fun count(): Number + fun debug(msg: Any) + fun filterBranches(filter: String): Number + fun filterBranches(filter: (node: FancytreeNode) -> Boolean): Number + fun filterNodes(filter: String, leavesOnly: Boolean? = definedExternally /* null */): Number + fun filterNodes( + filter: (node: FancytreeNode) -> Boolean, + leavesOnly: Boolean? = definedExternally /* null */ + ): Number + + fun findNextNode(match: String, startNode: FancytreeNode? = definedExternally /* null */): FancytreeNode + fun findNextNode( + match: (node: FancytreeNode) -> Boolean, + startNode: FancytreeNode? = definedExternally /* null */ + ): FancytreeNode + + fun findAll(match: String): Array + fun findAll(match: (node: FancytreeNode) -> Boolean?): Array + fun generateFormElements( + selected: Boolean? = definedExternally /* null */, + active: Boolean? = definedExternally /* null */ + ) + + fun getActiveNode(): FancytreeNode + fun getFirstChild(): FancytreeNode + fun getFocusNode(ifTreeHasFocus: Boolean? = definedExternally /* null */): FancytreeNode + fun getNodeByKey(key: String, searchRoot: FancytreeNode? = definedExternally /* null */): FancytreeNode + fun getNodesByRef(refKey: String, rootNode: FancytreeNode? = definedExternally /* null */): Array + fun getPersistData() + fun getRootNode(): FancytreeNode + fun getSelectedNodes(stopOnParents: Boolean? = definedExternally /* null */): Array + fun hasFocus(): Boolean + fun info(msg: Any) + fun isEditing(): FancytreeNode + fun loadKeyPath( + keyPathList: Array, + callback: (node: FancytreeNode, status: String) -> Unit + ): JQueryPromise + + fun loadKeyPath(keyPath: String, callback: (node: FancytreeNode, status: String) -> Unit): JQueryPromise + fun reactivate() + fun reload(source: Any? = definedExternally /* null */): JQueryPromise + fun render(force: Boolean? = definedExternally /* null */, deep: Boolean? = definedExternally /* null */) + fun setFocus(flag: Boolean? = definedExternally /* null */) + fun toDict( + includeRoot: Boolean? = definedExternally /* null */, + callback: ((node: FancytreeNode) -> Unit)? = definedExternally /* null */ + ): Any + + fun visit(fn: (node: FancytreeNode) -> Any): Boolean + fun warn(msg: Any) + fun enableUpdate(enabled: Boolean) +} + +external interface FancytreeNode { + var tree: Fancytree + var parent: FancytreeNode + var key: String + var title: String + var data: Any + var children: Array + var expanded: Boolean + var extraClasses: String + var folder: Boolean + var statusNodeType: String + var lazy: Boolean + var tooltip: String + var span: HTMLElement + var tr: HTMLTableRowElement + fun addChildren( + children: Array, + insertBefore: FancytreeNode? = definedExternally /* null */ + ): FancytreeNode + + fun addChildren(children: Array, insertBefore: String? = definedExternally /* null */): FancytreeNode + fun addChildren(children: Array, insertBefore: Number? = definedExternally /* null */): FancytreeNode + fun addChildren(child: NodeData, insertBefore: FancytreeNode? = definedExternally /* null */): FancytreeNode + fun addChildren(child: NodeData, insertBefore: String? = definedExternally /* null */): FancytreeNode + fun addChildren(child: NodeData, insertBefore: Number? = definedExternally /* null */): FancytreeNode + fun addClass(className: String) + fun addNode(node: NodeData, mode: String? = definedExternally /* null */): FancytreeNode + fun applyPatch(patch: NodePatch): JQueryPromise + fun collapseSiblings(): JQueryPromise + fun copyTo( + node: FancytreeNode, + mode: String? = definedExternally /* null */, + map: ((node: NodeData) -> Unit)? = definedExternally /* null */ + ): FancytreeNode + + fun countChildren(deep: Boolean? = definedExternally /* null */): Number + fun debug(msg: Any) + fun editCreateNode(mode: String? = definedExternally /* null */, init: Any? = definedExternally /* null */) + fun editEnd(applyChanges: Boolean) + fun editStart() + fun findAll(match: String): Array + fun findAll(match: (node: FancytreeNode) -> Boolean): Array + fun findFirst(match: String): FancytreeNode + fun findFirst(match: (node: FancytreeNode) -> Boolean): FancytreeNode + fun fixSelection3AfterClick() + fun fixSelection3FromEndNodes() + fun fromDict(dict: NodeData) + fun getChildren(): Array + fun getCloneList(includeSelf: Boolean? = definedExternally /* null */): Array + fun getFirstChild(): FancytreeNode + fun getIndex(): Number + fun getIndexHier(): String + fun getKeyPath(excludeSelf: Boolean): String + fun getLastChild(): FancytreeNode + fun getLevel(): Number + fun getNextSibling(): FancytreeNode + fun getParent(): FancytreeNode + fun getParentList(includeRoot: Boolean, includeSelf: Boolean): Array + fun getPrevSibling(): FancytreeNode + fun hasChildren(): Boolean + fun hasFocus(): Boolean + fun info(msg: String) + fun isActive(): Boolean + fun isChildOf(otherNode: FancytreeNode): Boolean + fun isClone(): Boolean + fun isDescendantOf(otherNode: FancytreeNode): Boolean + fun isEditing(): Boolean + fun isExpanded(): Boolean + fun isFirstSibling(): Boolean + fun isFolder(): Boolean + fun isLastSibling(): Boolean + fun isLazy(): Boolean + fun isLoaded(): Boolean + fun isLoading(): Boolean + fun isRootNode(): Boolean + fun isSelected(): Boolean + fun isStatusNode(): Boolean + fun isTopLevel(): Boolean + fun isUndefined(): Boolean + fun isVisible(): Boolean + fun load(forceReload: Boolean? = definedExternally /* null */): JQueryPromise + fun makeVisible(opts: Any? = definedExternally /* null */): JQueryPromise + fun moveTo( + targetNode: FancytreeNode, + mode: String, + map: ((node: FancytreeNode) -> Unit)? = definedExternally /* null */ + ) + + fun navigate(where: Number, activate: Boolean? = definedExternally /* null */): JQueryPromise + fun remove() + fun removeChild(childNode: FancytreeNode) + fun removeChildren() + fun removeClass(className: String) + fun render(force: Boolean? = definedExternally /* null */, deep: Boolean? = definedExternally /* null */) + fun renderStatus() + fun renderTitle() + fun reRegister(key: String, refKey: String): Boolean + fun resetLazy() + fun scheduleAction(mode: String, ms: Number) + fun scrollIntoView( + effects: Boolean? = definedExternally /* null */, + options: Any? = definedExternally /* null */ + ): JQueryPromise + + fun scrollIntoView( + effects: Any? = definedExternally /* null */, + options: Any? = definedExternally /* null */ + ): JQueryPromise + + fun setActive( + flag: Boolean? = definedExternally /* null */, + opts: Any? = definedExternally /* null */ + ): JQueryPromise + + fun setExpanded( + flag: Boolean? = definedExternally /* null */, + opts: Any? = definedExternally /* null */ + ): JQueryPromise + + fun setFocus(flag: Boolean? = definedExternally /* null */) + fun setSelected(flag: Boolean? = definedExternally /* null */) + fun setStatus( + status: String, + message: String? = definedExternally /* null */, + details: String? = definedExternally /* null */ + ) + + fun setTitle(title: String) + fun sortChildren( + cmp: ((a: FancytreeNode, b: FancytreeNode) -> Number)? = definedExternally /* null */, + deep: Boolean? = definedExternally /* null */ + ) + + fun toDict( + recursive: Boolean? = definedExternally /* null */, + callback: ((dict: NodeData) -> Unit)? = definedExternally /* null */ + ): NodeData + + fun toggleClass(className: String, flag: Boolean? = definedExternally /* null */): Boolean + fun toggleExpanded() + fun toggleSelected() + fun visit(fn: (node: FancytreeNode) -> Any, includeSelf: Boolean? = definedExternally /* null */): Boolean + fun visitAndLoad( + fn: (node: FancytreeNode) -> Any, + includeSelf: Boolean? = definedExternally /* null */ + ): JQueryPromise + + fun visitParents(fn: (node: FancytreeNode) -> Any, includeSelf: Boolean? = definedExternally /* null */): Boolean + fun warn(msg: Any) + fun addChildren(children: Array): FancytreeNode + fun addChildren(child: NodeData): FancytreeNode + fun scrollIntoView(): JQueryPromise +} + +external enum class FancytreeClickFolderMode { + activate /* = 1 */, + expand /* = 2 */, + activate_and_expand /* = 3 */, + activate_dblclick_expands /* = 4 */ +} + +external enum class FancytreeSelectMode { + single /* = 1 */, + multi /* = 2 */, + mutlti_hier /* = 3 */ +} + +external interface EventData { + var tree: Fancytree + var widget: Any + var options: FancytreeOptions + var originalEvent: JQueryEventObject + var node: FancytreeNode + var result: Any + var targetType: String + var response: Any +} + +external interface FancytreeEvents { + val activate: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val beforeActivate: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val beforeExpand: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val beforeSelect: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val blur: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val blurTree: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val click: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val collapse: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val create: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val createNode: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val dblclick: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val deactivate: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val expand: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val focus: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val focusTree: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val init: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val keydown: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val keypress: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val lazyLoad: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val loadChildren: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val loadError: ((event: JQueryEventObject, data: EventData) -> Boolean)? get() = definedExternally + val postProcess: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val removeNode: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val renderColumns: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val renderNode: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val renderTitle: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val restore: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + val select: ((event: JQueryEventObject, data: EventData) -> Unit)? get() = definedExternally + var rtl: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface `T$0` { + var type: String + var cache: Boolean + var dataType: String +} + +external interface `T$1` { + var top: Number + var bottom: Number +} + +external interface FancytreeOptions : FancytreeEvents { + var activeVisible: Boolean? get() = definedExternally; set(value) = definedExternally + var ajax: `T$0`? get() = definedExternally; set(value) = definedExternally + var aria: Boolean? get() = definedExternally; set(value) = definedExternally + var autoActivate: Boolean? get() = definedExternally; set(value) = definedExternally + var autoCollapse: Boolean? get() = definedExternally; set(value) = definedExternally + var autoScroll: Boolean? get() = definedExternally; set(value) = definedExternally + var checkbox: dynamic /* Boolean | String | (event: JQueryEventObject, data: EventData) -> Boolean */ + var clickFolderMode: FancytreeClickFolderMode? get() = definedExternally; set(value) = definedExternally + var debugLevel: dynamic /* 0 | 1 | 2 | 3 | 4 */ + var defaultKey: ((node: FancytreeNode) -> String)? get() = definedExternally; set(value) = definedExternally + var enableAspx: Boolean? get() = definedExternally; set(value) = definedExternally + var enableTitles: Boolean? get() = definedExternally; set(value) = definedExternally + var extensions: Array? get() = definedExternally; set(value) = definedExternally + var focusOnSelect: Boolean? get() = definedExternally; set(value) = definedExternally + var generateIds: Boolean? get() = definedExternally; set(value) = definedExternally + var icon: dynamic /* Boolean | String */ + var idPrefix: String? get() = definedExternally; set(value) = definedExternally + var imagePath: String? get() = definedExternally; set(value) = definedExternally + var keyboard: Boolean? get() = definedExternally; set(value) = definedExternally + var keyPathSeparator: String? get() = definedExternally; set(value) = definedExternally + var minExpandLevel: Number? get() = definedExternally; set(value) = definedExternally + var quicksearch: Boolean? get() = definedExternally; set(value) = definedExternally + var scrollOfs: `T$1`? get() = definedExternally; set(value) = definedExternally + var scrollParent: JQuery<*>? get() = definedExternally; set(value) = definedExternally + var selectMode: FancytreeSelectMode? get() = definedExternally; set(value) = definedExternally + var source: dynamic /* Array | Any */ + var strings: TranslationTable? get() = definedExternally; set(value) = definedExternally + var tabbable: Boolean? get() = definedExternally; set(value) = definedExternally + var titlesTabbable: Boolean? get() = definedExternally; set(value) = definedExternally + //var toggleEffect: EffectOptions? get() = definedExternally; set(value) = definedExternally + var tooltip: Boolean? get() = definedExternally; set(value) = definedExternally + var unselectable: dynamic /* Boolean | (event: JQueryEventObject, data: Fancytree.EventData) -> Boolean? */ + var unselectableIgnore: dynamic /* Boolean | (event: JQueryEventObject, data: Fancytree.EventData) -> Boolean? */ + var unselectableStatus: dynamic /* Boolean | (event: JQueryEventObject, data: Fancytree.EventData) -> Boolean? */ + var dnd5: DragAndDrop5 + var filter: Filter + var table: Table + @nativeGetter + operator fun get(extension: String): Any? + + @nativeSetter + operator fun set(extension: String, value: Any) +} + +external interface TranslationTable { + var loading: String + var loadError: String + var moreData: String + var noData: String +} + +external interface NodeData { + var title: String + var icon: dynamic /* Boolean | String */ + var key: String? get() = definedExternally; set(value) = definedExternally + var refKey: String? get() = definedExternally; set(value) = definedExternally + var expanded: Boolean? get() = definedExternally; set(value) = definedExternally + var active: Boolean? get() = definedExternally; set(value) = definedExternally + var focus: Boolean? get() = definedExternally; set(value) = definedExternally + var folder: Boolean? get() = definedExternally; set(value) = definedExternally + var hideCheckbox: Boolean? get() = definedExternally; set(value) = definedExternally + var lazy: Boolean? get() = definedExternally; set(value) = definedExternally + var selected: Boolean? get() = definedExternally; set(value) = definedExternally + var unselectable: Boolean? get() = definedExternally; set(value) = definedExternally + var children: Array? get() = definedExternally; set(value) = definedExternally + var tooltip: String? get() = definedExternally; set(value) = definedExternally + var extraClasses: String? get() = definedExternally; set(value) = definedExternally + var data: Any? get() = definedExternally; set(value) = definedExternally + var iconTooltip: String? get() = definedExternally; set(value) = definedExternally + var statusNodeType: String? get() = definedExternally; set(value) = definedExternally + var type: String? get() = definedExternally; set(value) = definedExternally + var unselectableIgnore: Boolean? get() = definedExternally; set(value) = definedExternally + var unselectableStatus: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface NodePatch { + var appendChildren: NodeData? get() = definedExternally; set(value) = definedExternally + var replaceChildren: NodeData? get() = definedExternally; set(value) = definedExternally + var insertChildren: NodeData? get() = definedExternally; set(value) = definedExternally +} + +external interface TreePatch { + @nativeGetter + operator fun get(key: String): NodePatch? + + @nativeSetter + operator fun set(key: String, value: NodePatch) +} + +external object FancytreeStatic { + var buildType: String + var debugLevel: Number + var version: String + fun assert(cond: Boolean, msg: String) + fun Unit> debounce( + timeout: Number, + fn: T, + invokeAsap: Boolean? = definedExternally /* null */, + ctx: Any? = definedExternally /* null */ + ): T + + fun debug(msg: String) + fun error(msg: String) + fun escapeHtml(s: String): String + fun getEventTarget(event: Event): Any + fun getEventTargetType(event: Event): String + fun getNode(el: JQuery<*>): FancytreeNode + fun getNode(el: Event): FancytreeNode + fun getNode(el: Element): FancytreeNode + fun info(msg: String) + fun keyEventToString(event: Event): String + fun parseHtml(`$ul`: JQuery<*>): Array + fun registerExtension(definition: Any) + fun unescapeHtml(s: String): String + fun warn(msg: String) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/extensions.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/extensions.kt new file mode 100644 index 00000000..cbe01cae --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/extensions.kt @@ -0,0 +1,78 @@ +@file:JsModule("jquery.fancytree") +@file:JsNonModule +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION" +) +package ru.mipt.npm.fancytreekt + +external interface List { + var dnd5: DragAndDrop5? get() = definedExternally; set(value) = definedExternally + var filter: Filter? get() = definedExternally; set(value) = definedExternally + var table: Table? get() = definedExternally; set(value) = definedExternally + @nativeGetter + operator fun get(extension: String): Any? + + @nativeSetter + operator fun set(extension: String, value: Any) +} + +external interface DragAndDrop5 { + var autoExpandMS: Number? get() = definedExternally; set(value) = definedExternally + var dropMarkerOffsetX: Number? get() = definedExternally; set(value) = definedExternally + var dropMarkerInsertOffsetX: Number? get() = definedExternally; set(value) = definedExternally + var multiSource: Boolean? get() = definedExternally; set(value) = definedExternally + var preventForeignNodes: Boolean? get() = definedExternally; set(value) = definedExternally + var preventNonNodes: Boolean? get() = definedExternally; set(value) = definedExternally + var preventRecursiveMoves: Boolean? get() = definedExternally; set(value) = definedExternally + var preventVoidMoves: Boolean? get() = definedExternally; set(value) = definedExternally + var scroll: Boolean? get() = definedExternally; set(value) = definedExternally + var scrollSensitivity: Number? get() = definedExternally; set(value) = definedExternally + var scrollSpeed: Number? get() = definedExternally; set(value) = definedExternally + var setTextTypeJson: Boolean? get() = definedExternally; set(value) = definedExternally + var dragStart: ((sourceNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragDrag: ((sourceNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragEnd: ((sourceNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragEnter: ((targetNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragOver: ((targetNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragExpand: ((targetNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragDrop: ((node: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var dragLeave: ((targetNode: FancytreeNode, data: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + @nativeGetter + operator fun get(key: String): Any? + + @nativeSetter + operator fun set(key: String, value: Any) +} + +external interface Filter { + var autoApply: Boolean + var autoExpand: Boolean + var counter: Boolean + var fuzzy: Boolean + var hideExpandedCounter: Boolean + var hideExpanders: Boolean + var highlight: Boolean + var leavesOnly: Boolean + var nodata: Boolean + var mode: dynamic /* 'dimm' | 'string' */ + @nativeGetter + operator fun get(key: String): Any? + + @nativeSetter + operator fun set(key: String, value: Any) +} + +external interface Table { + var checkboxColumnIdx: Any + var indentation: Number + var nodeColumnIdx: Number + @nativeGetter + operator fun get(key: String): Any? + + @nativeSetter + operator fun set(key: String, value: Any) +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/kotlinized.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/kotlinized.kt new file mode 100644 index 00000000..762dd6b5 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/kotlinized.kt @@ -0,0 +1,6 @@ +package ru.mipt.npm.fancytreekt + +import kotlin.js.json + +@Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE", "FunctionName") +fun NodeData(block: NodeData.() -> Unit): NodeData = (json() as NodeData).apply(block) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index bb5dc5b2..96289702 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -1,7 +1,6 @@ package hep.dataforge.vis.spatial.three import hep.dataforge.meta.boolean -import hep.dataforge.meta.int import hep.dataforge.meta.node import hep.dataforge.names.plus import hep.dataforge.names.startsWith @@ -43,13 +42,6 @@ internal fun Object3D.updatePosition(obj: VisualObject3D) { updateMatrix() } -/** - * Count number of layers to the top object. Return 1 if this is top layer - */ -val VisualObject3D.layer: Int - get() = getProperty(MeshThreeFactory.LAYER_KEY).int ?: ((parent as? VisualObject3D)?.layer ?: 0 + 1) - - internal fun Mesh.updateFrom(obj: T) { matrixAutoUpdate = false @@ -109,7 +101,6 @@ abstract class MeshThreeFactory(override val type: KClass buildMesh(obj: T, geometryBuilder: (T) -> BufferGeometry): Mesh { //TODO add caching for geometries using templates diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt index fb191900..fbd98c7f 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt @@ -19,12 +19,14 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output Unit = {}) = ThreeOutput(this, buildMeta(meta, override)).apply { - if(element!=null){ + if (element != null) { attach(element) } } \ No newline at end of file From 66caebb090c9a47e983ad43b52055965b4895883 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 19 Sep 2019 11:17:20 +0300 Subject: [PATCH 09/55] Correct tree controls for groups and proxy --- .../dataforge/vis/spatial/gdml/visualGDML.kt | 6 +- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 38 +- .../vis/spatial/gdml/demo/treeTools.kt | 13 + .../src/jsMain/web/index.html | 9 +- .../src/jsMain/web/main.css | 2 +- dataforge-vis-spatial/build.gradle.kts | 4 +- .../dataforge/vis/spatial/VisualGroup3D.kt | 2 +- .../dataforge/vis/spatial/tree/VisualTree.kt | 8 + .../hep/dataforge/vis/fancytree/Fancytree.kt | 427 ------------------ .../hep/dataforge/vis/fancytree/extensions.kt | 78 ---- .../hep/dataforge/vis/fancytree/kotlinized.kt | 6 - .../vis/spatial/three/ThreePlugin.kt | 17 +- .../vis/spatial/three/ThreeProxyFactory.kt | 17 + .../vis/spatial/tree/JSVisualTree.kt | 74 +++ 14 files changed, 160 insertions(+), 541 deletions(-) create mode 100644 dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/tree/VisualTree.kt delete mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/Fancytree.kt delete mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/extensions.kt delete mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/fancytree/kotlinized.kt create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/JSVisualTree.kt diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index f2e31d30..580f487e 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -80,7 +80,7 @@ private fun VisualGroup3D.addSolid( val innerSolid = solid.solidref.resolve(context.root) ?: error("Solid with tag ${solid.solidref.ref} for scaled solid ${solid.name} not defined") - addSolid(context, innerSolid) { + addSolid(context, innerSolid, name) { block() scaleX *= solid.scale.x.toFloat() scaleY *= solid.scale.y.toFloat() @@ -152,7 +152,7 @@ private fun VisualGroup3D.addPhysicalVolume( val group = volume(context, volume) //optimizing single child case if (context.optimizeSingleChild && group.children.size == 1) { - this[physVolume.name ?: "@unnamed"] = group.children.values.first().apply { + this[physVolume.name ?: ""] = group.children.values.first().apply { //Must ser this to avoid parent reset error parent = null //setting offset from physical volume @@ -167,7 +167,7 @@ private fun VisualGroup3D.addPhysicalVolume( rotation += group.rotation } } else { - this[physVolume.name ?: "@unnamed"] = group.apply { + this[physVolume.name ?: ""] = group.apply { withPosition( context.lUnit, physVolume.resolvePosition(context.root), diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 7e74041a..77aa1977 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -15,8 +15,9 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.html.InputType import kotlinx.html.dom.append -import kotlinx.html.js.div import kotlinx.html.js.input +import kotlinx.html.js.li +import kotlinx.html.js.ul import org.w3c.dom.Element import org.w3c.dom.HTMLDivElement import org.w3c.dom.events.Event @@ -79,27 +80,30 @@ private class GDMLDemoApp : ApplicationBase() { } } - fun setupSidebar(element: Element, output: ThreeOutput) { + fun setupSidebar(element: Element, output: ThreeOutput, root: VisualObject3D) { element.clear() - (0..9).forEach { layer -> - element.append { - div("row") { - +"layer $layer" - input(type = InputType.checkBox).apply { - if (layer == 0) { - checked = true - } - onchange = { - if (checked) { - output.camera.layers.enable(layer) - } else { - output.camera.layers.disable(layer) + element.append { + ul("list-group") { + (0..9).forEach { layer -> + li("list-group-item") { + +"layer $layer" + input(type = InputType.checkBox).apply { + if (layer == 0) { + checked = true + } + onchange = { + if (checked) { + output.camera.layers.enable(layer) + } else { + output.camera.layers.disable(layer) + } } } } } } } + element.appendFancyTree(root) } private val gdmlConfiguration: GDMLTransformer.() -> Unit = { @@ -118,8 +122,6 @@ private class GDMLDemoApp : ApplicationBase() { } } -// optimizeSingleChild = true - solidConfiguration = { parent, solid -> if (!parent.physVolumes.isEmpty()) { opacity = 0.3 @@ -169,7 +171,7 @@ private class GDMLDemoApp : ApplicationBase() { //output.camera.layers.enable(1) output.camera.layers.set(0) - setupSidebar(sidebar, output) + setupSidebar(sidebar, output, visual) output.render(visual) launch { diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt new file mode 100644 index 00000000..c8cc5636 --- /dev/null +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/treeTools.kt @@ -0,0 +1,13 @@ +package hep.dataforge.vis.spatial.gdml.demo + +import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.tree.JSVisualTree +import nl.adaptivity.js.util.asElement +import org.w3c.dom.Element + +fun Element.appendFancyTree(root: VisualObject3D){ + val visualTree = JSVisualTree("world", root) {} + val treeNode = visualTree.root + treeNode.asElement()!!.id = "fancytree" + appendChild(treeNode) +} \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html index 1a27e18d..d7e24b00 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html +++ b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html @@ -6,7 +6,8 @@ Three js demo for particle physics - + + @@ -22,15 +23,15 @@ -
+
- - - - + + @@ -21,18 +23,53 @@

GDML demo

- - + +
+
- +
+ +
+
+
+
+

+ +

+
+ +
+
+
+
+
+
+
+
+

+ +

+
+
+
+
+
+
+
+
+
- diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index ebd9ae83..1e2f96b0 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -5,12 +5,12 @@ plugins { id("org.openjfx.javafxplugin") } -scientifik{ +scientifik { withSerialization() } kotlin { - jvm{ + jvm { withJava() } sourceSets { @@ -19,20 +19,20 @@ kotlin { api(project(":dataforge-vis-common")) } } - jvmMain{ + jvmMain { dependencies { implementation(project(":dataforge-vis-fx")) implementation("org.fxyz3d:fxyz3d:0.4.0") } } - jsMain{ + jsMain { dependencies { implementation(npm("three", "0.106.2")) implementation(npm("@hi-level/three-csg", "1.0.6")) implementation(npm("style-loader")) implementation(npm("element-resize-event")) -// api("kotlin.js.externals:kotlin-js-jquery:3.2.0-0") -// implementation(npm("jquery.fancytree","2.32.0")) + implementation(npm("inspire-tree","6.0.1")) + implementation(npm("inspire-tree-dom","4.0.6")) } } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index c57e6841..79804d44 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -11,6 +11,7 @@ import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY +import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY import kotlinx.serialization.UseSerializers @@ -34,6 +35,7 @@ interface VisualObject3D : VisualObject { companion object { val MATERIAL_KEY = "material".asName() val VISIBLE_KEY = "visible".asName() + val SELECTED_KEY = "selected".asName() val DETAIL_KEY = "detail".asName() val LAYER_KEY = "layer".asName() @@ -117,10 +119,18 @@ var VisualObject.visible: Boolean? get() = getProperty(VISIBLE_KEY).boolean set(value) = setProperty(VISIBLE_KEY, value) +var VisualObject.selected: Boolean? + get() = getProperty(SELECTED_KEY).boolean + set(value) = setProperty(SELECTED_KEY, value) + fun VisualObject.color(rgb: Int) { material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb } } +fun VisualObject.color(rgb: String) { + material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb } +} + fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) { material = buildMeta(builder) } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/tree/VisualTree.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/tree/VisualTree.kt deleted file mode 100644 index 8a0e4b42..00000000 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/tree/VisualTree.kt +++ /dev/null @@ -1,8 +0,0 @@ -package hep.dataforge.vis.spatial.tree - -import hep.dataforge.vis.common.VisualObject - -interface VisualTree { - val item: T? - val children: Collection> -} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt index fbd98c7f..2e8bd0e4 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt @@ -10,8 +10,9 @@ import info.laht.threekt.WebGLRenderer import info.laht.threekt.helpers.AxesHelper import info.laht.threekt.lights.AmbientLight import info.laht.threekt.scenes.Scene -import org.w3c.dom.Element +import org.w3c.dom.HTMLElement import kotlin.browser.window +import kotlin.dom.clear private val elementResizeEvent = require("element-resize-event") @@ -23,7 +24,7 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output Int = { element.clientWidth }) { + fun attach(element: HTMLElement, computeWidth: HTMLElement.() -> Int = { this.offsetWidth }) { + element.clear() val width by meta.number(computeWidth(element)).int val height: Int = (width / camera.aspect).toInt() @@ -56,7 +58,7 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output Unit = {}) = +fun ThreePlugin.output(element: HTMLElement? = null, meta: Meta = EmptyMeta, override: MetaBuilder.() -> Unit = {}) = ThreeOutput(this, buildMeta(meta, override)).apply { if (element != null) { attach(element) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/JSVisualTree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/JSVisualTree.kt deleted file mode 100644 index 07f9e986..00000000 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/JSVisualTree.kt +++ /dev/null @@ -1,74 +0,0 @@ -package hep.dataforge.vis.spatial.tree - -import hep.dataforge.vis.common.VisualGroup -import hep.dataforge.vis.common.VisualObject -import hep.dataforge.vis.spatial.visible -import kotlinx.html.InputType -import kotlinx.html.dom.append -import kotlinx.html.js.* -import org.w3c.dom.HTMLDivElement -import org.w3c.dom.Node -import kotlin.browser.document - -class JSVisualTree( - val title: String, - override val item: VisualObject, - val callback: VisualObject.() -> Unit -) : VisualTree { - - override val children: Collection by lazy { - if (item is VisualGroup) { - item.children.mapNotNull {(key,value)-> - val str = key.toString() - if(!str.startsWith("@")) { - JSVisualTree(str, value, callback) - } else { - null - } - } - } else { - emptyList() - } - } - - var visible: Boolean - get() = item.visible ?: true - set(value) { - item.visible = value - } - - val root: Node by lazy { - (document.createElement("div") as HTMLDivElement).apply { - append { - div(TREE_ITEM_HEADER_CLASS) { - input(type = InputType.checkBox).apply { - checked = visible - onChangeFunction = { - visible = checked - } - } - a { - +this@JSVisualTree.title - +"[${item::class}]" - } - } - if (item is VisualGroup) { - ul { - this@JSVisualTree.children.forEach { value -> - li(TREE_NODE_CLASS).apply { - appendChild(value.root) - } - } - } - } - } - } - } - - companion object { - const val TREE_NODE_CLASS = "tree-node" - const val TREE_LEAF_CLASS = "tree-leaf" - const val TREE_ITEM_HEADER_CLASS = "tree-header" - } - -} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/eventemitter2.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/eventemitter2.kt new file mode 100644 index 00000000..2d6e2e50 --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/eventemitter2.kt @@ -0,0 +1,65 @@ +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION" +) +@file:JsModule("eventemitter2") +@file: JsNonModule + +package hep.dataforge.vis.spatial.tree + +import kotlin.js.Promise + +//typealias eventNS = Array + +external interface ConstructorOptions { + var wildcard: Boolean? get() = definedExternally; set(value) = definedExternally + var delimiter: String? get() = definedExternally; set(value) = definedExternally + var newListener: Boolean? get() = definedExternally; set(value) = definedExternally + var maxListeners: Number? get() = definedExternally; set(value) = definedExternally + var verboseMemoryLeak: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface EventAndListener { + @nativeInvoke + operator fun invoke(event: String, vararg values: Any) + + @nativeInvoke + operator fun invoke(event: Array, vararg values: Any) +} + +external open class EventEmitter2(options: ConstructorOptions? = definedExternally /* null */) { + open fun emit(event: String, vararg values: Any): Boolean + open fun emit(event: Array, vararg values: Any): Boolean + open fun emitAsync(event: String, vararg values: Any): Promise> + open fun emitAsync(event: Array, vararg values: Any): Promise> + open fun addListener(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun on(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun on(event: Array, listener: Function<*>): EventEmitter2 /* this */ + open fun prependListener(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun prependListener(event: Array, listener: Function<*>): EventEmitter2 /* this */ + open fun once(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun once(event: Array, listener: Function<*>): EventEmitter2 /* this */ + open fun prependOnceListener(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun prependOnceListener(event: Array, listener: Function<*>): EventEmitter2 /* this */ + open fun many(event: String, timesToListen: Number, listener: Function<*>): EventEmitter2 /* this */ + open fun many(event: Array, timesToListen: Number, listener: Function<*>): EventEmitter2 /* this */ + open fun prependMany(event: String, timesToListen: Number, listener: Function<*>): EventEmitter2 /* this */ + open fun prependMany(event: Array, timesToListen: Number, listener: Function<*>): EventEmitter2 /* this */ + open fun onAny(listener: EventAndListener): EventEmitter2 /* this */ + open fun prependAny(listener: EventAndListener): EventEmitter2 /* this */ + open fun offAny(listener: Function<*>): EventEmitter2 /* this */ + open fun removeListener(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun removeListener(event: Array, listener: Function<*>): EventEmitter2 /* this */ + open fun off(event: String, listener: Function<*>): EventEmitter2 /* this */ + open fun removeAllListeners(event: String? = definedExternally /* null */): EventEmitter2 /* this */ + open fun removeAllListeners(event: Array? = definedExternally /* null */): EventEmitter2 /* this */ + open fun setMaxListeners(n: Number) + open fun eventNames(): Array + open fun listeners(event: String): Array> + open fun listeners(event: Array): Array> + open fun listenersAny(): Array> + open fun removeAllListeners(): EventEmitter2 /* this */ +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/inspire-tree-dom.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/inspire-tree-dom.kt new file mode 100644 index 00000000..2e595adf --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/inspire-tree-dom.kt @@ -0,0 +1,38 @@ +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION" +) + +package hep.dataforge.vis.spatial.tree + +import org.w3c.dom.HTMLElement + +external interface DropTargetValidator { + @nativeInvoke + operator fun invoke(dragNode: TreeNode, targetNode: TreeNode): Boolean +} + +external interface DragAndDrop { + var enabled: Boolean? get() = definedExternally; set(value) = definedExternally + var validateOn: String? get() = definedExternally; set(value) = definedExternally + var validate: DropTargetValidator +} + +external interface DomConfig { + var autoLoadMore: Boolean? get() = definedExternally; set(value) = definedExternally + var deferredRendering: Boolean? get() = definedExternally; set(value) = definedExternally + var dragAndDrop: DragAndDrop? get() = definedExternally; set(value) = definedExternally + var nodeHeight: Number? get() = definedExternally; set(value) = definedExternally + var showCheckboxes: Boolean? get() = definedExternally; set(value) = definedExternally + var dragTargets: Array? get() = definedExternally; set(value) = definedExternally + var tabindex: Number? get() = definedExternally; set(value) = definedExternally + var target: HTMLElement +} + + +@JsModule("inspire-tree-dom") +@JsNonModule +open external class InspireTreeDOM(tree: Any, opts: DomConfig) \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/inspire-tree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/inspire-tree.kt new file mode 100644 index 00000000..c19df4de --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/inspire-tree.kt @@ -0,0 +1,417 @@ +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION", + "unused" +) + +package hep.dataforge.vis.spatial.tree + +import kotlin.js.Promise +import kotlin.js.RegExp + +external interface NodeIteratee { + @nativeInvoke + operator fun invoke(node: TreeNode): Any +} + +external interface MatchProcessor { + @nativeInvoke + operator fun invoke(matches: TreeNodes): Any +} + +external interface SearchMatcher { + @nativeInvoke + operator fun invoke(query: String, resolve: Any, reject: Any): Any +} + +external interface `T$0` { + var add: Boolean? get() = definedExternally; set(value) = definedExternally + var edit: Boolean? get() = definedExternally; set(value) = definedExternally + var remove: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface `T$1` { + var resetStateOnRestore: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface `T$2` { + var limit: Number? get() = definedExternally; set(value) = definedExternally +} + +external interface `T$3` { + var matcher: SearchMatcher + var matchProcess: MatchProcessor +} + +external interface Selection { + var allow: NodeIteratee? get() = definedExternally; set(value) = definedExternally + var autoDeselect: Boolean? get() = definedExternally; set(value) = definedExternally + var autoSelectChildren: Boolean? get() = definedExternally; set(value) = definedExternally + var disableDirectDeselection: Boolean? get() = definedExternally; set(value) = definedExternally + var mode: String? get() = definedExternally; set(value) = definedExternally + var multiple: Boolean? get() = definedExternally; set(value) = definedExternally + var require: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface Config { + var allowLoadEvents: Array? get() = definedExternally; set(value) = definedExternally +// var checkbox: dynamic get() = definedExternally; set(value) = definedExternally + var contextMenu: Boolean? get() = definedExternally; set(value) = definedExternally + val data: ((node: TreeNode, resolve: (nodes: Array) -> Any, reject: (err: Error) -> Any) -> dynamic)? get() = definedExternally + var deferredLoading: Boolean? get() = definedExternally; set(value) = definedExternally + var editable: Boolean? get() = definedExternally; set(value) = definedExternally + var editing: `T$0`? get() = definedExternally; set(value) = definedExternally + var nodes: `T$1`? get() = definedExternally; set(value) = definedExternally + var pagination: `T$2`? get() = definedExternally; set(value) = definedExternally + var renderer: Any? get() = definedExternally; set(value) = definedExternally + var search: `T$3`? get() = definedExternally; set(value) = definedExternally + var selection: Selection? get() = definedExternally; set(value) = definedExternally + var sort: String? get() = definedExternally; set(value) = definedExternally + var multiselect: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface State { + var checked: Boolean? get() = definedExternally; set(value) = definedExternally + var collapsed: Boolean? get() = definedExternally; set(value) = definedExternally + var draggable: Boolean? get() = definedExternally; set(value) = definedExternally + //var `drop-target`: Boolean? get() = definedExternally; set(value) = definedExternally + var editable: Boolean? get() = definedExternally; set(value) = definedExternally + var focused: Boolean? get() = definedExternally; set(value) = definedExternally + var hidden: Boolean? get() = definedExternally; set(value) = definedExternally + var indeterminate: Boolean? get() = definedExternally; set(value) = definedExternally + var loading: Boolean? get() = definedExternally; set(value) = definedExternally + var matched: Boolean? get() = definedExternally; set(value) = definedExternally + var removed: Boolean? get() = definedExternally; set(value) = definedExternally + var rendered: Boolean? get() = definedExternally; set(value) = definedExternally + var selectable: Boolean? get() = definedExternally; set(value) = definedExternally + var selected: Boolean? get() = definedExternally; set(value) = definedExternally +} + +external interface InspireTag { + var attributes: Any? get() = definedExternally; set(value) = definedExternally +} + +external interface ITree { + var a: InspireTag? get() = definedExternally; set(value) = definedExternally + var icon: String? get() = definedExternally; set(value) = definedExternally + var li: InspireTag? get() = definedExternally; set(value) = definedExternally + var state: State? get() = definedExternally; set(value) = definedExternally +} + +external interface NodeConfig { + var children: dynamic /* Array | true */ + var id: String? get() = definedExternally; set(value) = definedExternally + var text: String + @JsName("itree") + var itree: ITree? get() = definedExternally; set(value) = definedExternally +} + +external interface Pagination { + var limit: Number + var total: Number +} + +@JsModule("inspire-tree") +@JsNonModule +open external class InspireTree(opts: Config) : EventEmitter2 { + constructor(tree: InspireTree) + constructor(tree: InspireTree, array: Array) + constructor(tree: InspireTree, array: TreeNodes) + + open fun addNode(node: NodeConfig): TreeNode + open fun addNodes(node: Array): TreeNodes + open fun available(): TreeNodes + open fun blur(): TreeNodes + open fun blurDeep(): TreeNodes + open fun boundingNodes(): Array + open fun canAutoDeselect(): Boolean + open fun checked(): TreeNodes + open fun clean(): TreeNodes + open fun clearSearch(): InspireTree + open fun clone(): TreeNodes + open fun collapse(): TreeNodes + open fun collapsed(full: Boolean? = definedExternally /* null */): TreeNodes + open fun collapseDeep(): TreeNodes + open fun context(): TreeNode + open fun copy( + dest: InspireTree, + hierarchy: Boolean? = definedExternally /* null */, + includeState: Boolean? = definedExternally /* null */ + ): TreeNodes + + open fun createNode(obj: Any): TreeNode + open fun deepest(): TreeNodes + open fun deselect(): TreeNodes + open fun deselectDeep(): TreeNodes + open fun disableDeselection(): InspireTree + open fun each(iteratee: NodeIteratee): TreeNodes + open fun editable(full: Boolean? = definedExternally /* null */): TreeNodes + open fun editing(full: Boolean? = definedExternally /* null */): TreeNodes + open fun enableDeselection(): InspireTree + open fun expand(): Promise + open fun expandDeep(): TreeNodes + open fun expanded(full: Boolean? = definedExternally /* null */): TreeNodes + open fun expandParents(): TreeNodes + open fun extract(predicate: String): TreeNodes + open fun extract(predicate: NodeIteratee): TreeNodes + open fun filterBy(predicate: String): TreeNodes + open fun filterBy(predicate: NodeIteratee): TreeNodes + open fun find( + predicate: (node: TreeNode, index: Number? /* = null */, obj: Array? /* = null */) -> Boolean, + thisArg: Any? = definedExternally /* null */ + ): TreeNode + + open fun first(predicate: (node: TreeNode) -> Boolean): TreeNode + open fun flatten(predicate: String): TreeNodes + open fun flatten(predicate: NodeIteratee): TreeNodes + open fun focused(full: Boolean? = definedExternally /* null */): TreeNodes + open fun get(index: Number): TreeNode + open fun hidden(full: Boolean? = definedExternally /* null */): TreeNodes + open fun hide(): TreeNodes + open fun hideDeep(): TreeNodes + open var id: dynamic /* String | Number */ + open var config: Config + open var preventDeselection: Boolean + open fun indeterminate(full: Boolean? = definedExternally /* null */): TreeNodes + open fun insertAt(index: Number, `object`: Any): TreeNode + open fun invoke(methods: String): TreeNodes + open fun invoke(methods: Array): TreeNodes + open fun invokeDeep(methods: String): TreeNodes + open fun invokeDeep(methods: Array): TreeNodes + open fun isEventMuted(eventName: String): Boolean + open fun last(predicate: (node: TreeNode) -> Boolean): TreeNode + open fun lastSelectedNode(): TreeNode + open fun load(loader: Promise): Promise + open fun loading(full: Boolean? = definedExternally /* null */): TreeNodes + open fun matched(full: Boolean? = definedExternally /* null */): TreeNodes + open fun move(index: Number, newIndex: Number, target: TreeNodes): TreeNode + open fun mute(events: Array): InspireTree + open fun muted(): Boolean + open fun node(id: String): TreeNode + open fun node(id: Number): TreeNode + open fun nodes(ids: Array? = definedExternally /* null */): TreeNodes + open fun nodes(ids: Array? = definedExternally /* null */): TreeNodes + open fun pagination(): Pagination + open fun recurseDown(iteratee: NodeIteratee): TreeNodes + open fun reload(): Promise + open fun removeAll(): InspireTree + open fun removed(full: Boolean? = definedExternally /* null */): TreeNodes + open fun restore(): TreeNodes + open fun restoreDeep(): TreeNodes + open fun search(query: String): Promise + open fun search(query: RegExp): Promise + open fun search(query: NodeIteratee): Promise + open fun select(): TreeNodes + open fun selectable(full: Boolean? = definedExternally /* null */): TreeNodes + open fun selectBetween(start: TreeNode, end: TreeNode): InspireTree + open fun selectDeep(): TreeNodes + open fun selected(full: Boolean? = definedExternally /* null */): TreeNodes + open fun selectFirstAvailableNode(): TreeNode + open fun show(): TreeNodes + open fun showDeep(): TreeNodes + open fun softRemove(): TreeNodes + open fun sortBy(sorter: String): TreeNodes + open fun sortBy(sorter: NodeIteratee): TreeNodes + open fun state(key: String, `val`: Boolean): TreeNodes + open fun stateDeep(key: String, `val`: Boolean): TreeNodes + open fun swap(node1: TreeNode, node2: TreeNode): TreeNodes + open fun toArray(): Array + open fun toArray(): Array + open fun tree(): InspireTree + open fun unmute(events: Array): InspireTree + open fun visible(full: Boolean? = definedExternally /* null */): TreeNodes + open fun nodes(): TreeNodes + + companion object { + fun isTreeNode(`object`: Any): Boolean + fun isTreeNodes(`object`: Any): Boolean + } +} + +open external class TreeNodes(tree: InspireTree) { + constructor(tree: InspireTree, array: Array) + constructor(tree: InspireTree, array: TreeNodes) + + open fun addNode(node: NodeConfig): TreeNode + open fun available(): TreeNodes + open fun blur(): TreeNodes + open fun blurDeep(): TreeNodes + open fun checked(): TreeNodes + open fun clean(): TreeNodes + open fun clone(): TreeNodes + open fun collapse(): TreeNodes + open fun collapsed(full: Boolean? = definedExternally /* null */): TreeNodes + open fun collapseDeep(): TreeNodes + open fun context(): TreeNode + open fun copy( + dest: InspireTree, + hierarchy: Boolean? = definedExternally /* null */, + includeState: Boolean? = definedExternally /* null */ + ): TreeNodes + + open fun deepest(): TreeNodes + open fun deselect(): TreeNodes + open fun deselectDeep(): TreeNodes + open fun each(iteratee: NodeIteratee): TreeNodes + open fun editable(full: Boolean? = definedExternally /* null */): TreeNodes + open fun editing(full: Boolean? = definedExternally /* null */): TreeNodes + open fun expand(): TreeNodes + open fun expandDeep(): Promise + open fun expanded(full: Boolean? = definedExternally /* null */): TreeNodes + open fun expandParents(): TreeNodes + open fun extract(predicate: String): TreeNodes + open fun extract(predicate: NodeIteratee): TreeNodes + open fun filterBy(predicate: String): TreeNodes + open fun filterBy(predicate: NodeIteratee): TreeNodes + open fun find( + predicate: (node: TreeNode, index: Number? /* = null */, obj: Array? /* = null */) -> Boolean, + thisArg: Any? = definedExternally /* null */ + ): TreeNode + + open fun flatten(predicate: String): TreeNodes + open fun flatten(predicate: NodeIteratee): TreeNodes + open fun focused(full: Boolean? = definedExternally /* null */): TreeNodes + operator fun get(index: Number): TreeNode + open fun hidden(full: Boolean? = definedExternally /* null */): TreeNodes + open fun hide(): TreeNodes + open fun hideDeep(): TreeNodes + open fun indeterminate(full: Boolean? = definedExternally /* null */): TreeNodes + open fun insertAt(index: Number, `object`: Any): TreeNode + open fun invoke(methods: String): TreeNodes + open fun invoke(methods: Array): TreeNodes + open fun invokeDeep(methods: String): TreeNodes + open fun invokeDeep(methods: Array): TreeNodes + open fun loading(full: Boolean? = definedExternally /* null */): TreeNodes + open fun matched(full: Boolean? = definedExternally /* null */): TreeNodes + open fun move(index: Number, newIndex: Number, target: TreeNodes): TreeNode + open fun node(id: String): TreeNode + open fun node(id: Number): TreeNode + open fun nodes(ids: Array? = definedExternally /* null */): TreeNodes + open fun nodes(ids: Array? = definedExternally /* null */): TreeNodes + open fun pagination(): Pagination + open fun recurseDown(iteratee: NodeIteratee): TreeNodes + open fun removed(full: Boolean? = definedExternally /* null */): TreeNodes + open fun restore(): TreeNodes + open fun restoreDeep(): TreeNodes + open fun select(): TreeNodes + open fun selectable(full: Boolean? = definedExternally /* null */): TreeNodes + open fun selectBetween(start: TreeNode, end: TreeNode): InspireTree + open fun selectDeep(): TreeNodes + open fun selected(full: Boolean? = definedExternally /* null */): TreeNodes + open fun show(): TreeNodes + open fun showDeep(): TreeNodes + open fun softRemove(): TreeNodes + open fun sortBy(sorter: String): TreeNodes + open fun sortBy(sorter: NodeIteratee): TreeNodes + open fun state(key: String, `val`: Boolean): TreeNodes + open fun stateDeep(key: String, `val`: Boolean): TreeNodes + open fun swap(node1: TreeNode, node2: TreeNode): TreeNodes + open fun toArray(): Array + open fun tree(): InspireTree + open fun visible(full: Boolean? = definedExternally /* null */): TreeNodes + open fun nodes(): TreeNodes +} + +open external class TreeNode(tree: InspireTree) { + constructor(tree: InspireTree, source: Any, excludeKeys: Array) + constructor(tree: InspireTree, source: TreeNode, excludeKeys: Array) + constructor(tree: InspireTree, source: Any) + constructor(tree: InspireTree, source: TreeNode) + + open fun addChild(node: NodeConfig): TreeNode + open fun addChildren(nodes: Array): TreeNodes + open fun assign(vararg sources: Any?): TreeNode + open fun available(): Boolean + open fun blur(): TreeNode + open fun check(shallow: Boolean? = definedExternally /* null */): TreeNode + open fun checked(): Boolean + open fun clean(): TreeNode + open fun clone(excludeKeys: Array? = definedExternally /* null */): TreeNode + open fun collapse(): TreeNode + open fun collapsed(): Boolean + open var text: String + open var id: String + open var itree: Any + open fun context(): TreeNodes + open fun copy( + dest: InspireTree, + hierarchy: Boolean? = definedExternally /* null */, + includeState: Boolean? = definedExternally /* null */ + ): TreeNode + + open fun copyHierarchy( + excludeNode: Boolean? = definedExternally /* null */, + includeState: Boolean? = definedExternally /* null */ + ): TreeNode + + open fun deselect(shallow: Boolean? = definedExternally /* null */): TreeNode + open fun editable(): Boolean + open fun editing(): Boolean + open fun expand(): Promise + open fun expanded(): Boolean + open fun expandParents(): TreeNode + open fun focus(): TreeNode + open fun focused(): Boolean + open fun getChildren(): TreeNodes + open fun getParent(): TreeNode + open fun getParents(): TreeNodes + open fun getTextualHierarchy(): Array + open fun hasAncestor(): Boolean + open fun hasChildren(): Boolean + open fun hasOrWillHaveChildren(): Boolean + open fun hasParent(): Boolean + open fun hasVisibleChildren(): Boolean + open fun hidden(): Boolean + open fun hide(): TreeNode + open fun indeterminate(): Boolean + open fun indexPath(): String + open fun isFirstRenderable(): Boolean + open fun isLastRenderable(): Boolean + open fun lastDeepestVisibleChild(): TreeNode + open fun loadChildren(): Promise + open fun loading(): Boolean + open fun markDirty(): TreeNode + open fun matched(): TreeNodes + open fun nextVisibleAncestralSiblingNode(): TreeNode + open fun nextVisibleChildNode(): TreeNode + open fun nextVisibleNode(): TreeNode + open fun nextVisibleSiblingNode(): TreeNode + open fun pagination(): Pagination + open fun previousVisibleNode(): TreeNode + open fun previousVisibleSiblingNode(): TreeNode + open fun recurseDown(iteratee: NodeIteratee): TreeNode + open fun recurseUp(iteratee: NodeIteratee): TreeNode + open fun refreshIndeterminateState(): TreeNode + open fun reload(): Promise + open fun remove(includeState: Boolean? = definedExternally /* null */): Any + open fun removed(): Boolean + open fun renderable(): Boolean + open fun rendered(): Boolean + open fun restore(): TreeNode + open fun select(shallow: Boolean? = definedExternally /* null */): TreeNode + open fun selectable(): Boolean + open fun selected(): Boolean + open fun set(key: Number, `val`: Any): TreeNode + open fun set(key: String, `val`: Any): TreeNode + open fun show(): TreeNode + open fun softRemove(): TreeNode + open fun state(key: Any?, `val`: Boolean? = definedExternally /* null */): dynamic /* Boolean | Any? */ + open fun state(key: String, `val`: Boolean? = definedExternally /* null */): dynamic /* Boolean | Any? */ + open fun states(keys: Array, `val`: Boolean): Boolean + open fun toggleCheck(): TreeNode + open fun toggleCollapse(): TreeNode + open fun toggleEditing(): TreeNode + open fun toggleSelect(): TreeNode + open fun toObject( + excludeChildren: Boolean? = definedExternally /* null */, + includeState: Boolean? = definedExternally /* null */ + ): Any + + override fun toString(): String + open fun tree(): InspireTree + open fun uncheck(shallow: Boolean? = definedExternally /* null */): TreeNode + open fun visible(): Boolean +} \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt new file mode 100644 index 00000000..6f9f22ea --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt @@ -0,0 +1,110 @@ +@file:Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE") + +package hep.dataforge.vis.spatial.tree + +import hep.dataforge.meta.string +import hep.dataforge.names.EmptyName +import hep.dataforge.names.Name +import hep.dataforge.names.NameToken +import hep.dataforge.vis.common.VisualGroup +import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.common.getProperty +import hep.dataforge.vis.spatial.selected +import hep.dataforge.vis.spatial.visible +import org.w3c.dom.HTMLElement +import kotlin.js.json + +operator fun Name.plus(other: NameToken): Name = Name(tokens + other) + +fun InspireTree.render(element: HTMLElement, block: DomConfig.() -> Unit = {}) { + val config = (json( + "target" to element + ) as DomConfig).apply(block) + InspireTreeDOM(this, config) +} + +internal fun createInspireTree(block: Config.() -> Unit = {}): InspireTree { + val config = (json( + "checkbox" to json( + "autoCheckChildren" to false + ) + ) as Config).apply(block) + return InspireTree(config) +} + +fun VisualGroup.toTree(onFocus: (VisualObject?, String?)->Unit = {obj,name->}): InspireTree { + + val map = HashMap() + + fun generateNodeConfig(item: VisualObject, fullName: Name): NodeConfig { + val title = item.getProperty("title").string ?: fullName.last()?.toString() ?: "root" + val text = "$title[${item::class.toString().replace("class ","")}]" + return json( + "children" to if ((item as? VisualGroup)?.children?.isEmpty() != false) { + emptyArray() + } else { + true + }, + "text" to text, + "id" to fullName.toString(), + "itree" to json( + "state" to json( + "checked" to (item.visible ?: true) + ) + ) + ) as NodeConfig + + } + + fun TreeNode.fillChildren(group: VisualGroup, groupName: Name) { + group.children.forEach { (token, obj) -> + val name = groupName + token + val nodeConfig = generateNodeConfig(obj, name) + val childNode = addChild(nodeConfig) + map[childNode.id] = obj + if (obj is VisualGroup) { + childNode.fillChildren(obj, name) + } + } + } + + val inspireTree = createInspireTree{ + + } + val nodeConfig = generateNodeConfig(this, EmptyName) + val rootNode = inspireTree.addNode(nodeConfig) + map[rootNode.id] = this + rootNode.fillChildren(this, EmptyName) + + inspireTree.on("node.selected") { node: TreeNode, isLoadEvent: Boolean -> + if (!isLoadEvent) { + map[node.id]?.selected = node.selected() + } + } + + inspireTree.on("node.deselect") { node: TreeNode -> + map[node.id]?.selected = node.selected() + } + + inspireTree.on("node.checked") { node: TreeNode, isLoadEvent: Boolean -> + if (!isLoadEvent) { + map[node.id]?.visible = node.checked() + } + } + + inspireTree.on("node.unchecked") { node: TreeNode -> + if(!node.indeterminate()){ + map[node.id]?.visible = node.checked() + } + } + + inspireTree.on("node.focused") { node: TreeNode, isLoadEvent: Boolean -> + if (!isLoadEvent) { + onFocus(map[node.id],node.id) + } + } + + inspireTree.collapseDeep() + + return inspireTree +} diff --git a/spatial-js-demo/src/main/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt b/spatial-js-demo/src/main/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt index 17c8e330..54279340 100644 --- a/spatial-js-demo/src/main/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt +++ b/spatial-js-demo/src/main/kotlin/hep/dataforge/vis/spatial/demo/ThreeDemoGrid.kt @@ -60,7 +60,9 @@ class ThreeDemoGrid(meta: Meta) : AbstractPlugin(meta), OutputManager { gridRoot.append { span("border") { div("col-6") { - output.attach(div { id = "output-$name" }) { 500 } + div { id = "output-$name" }.also{ + output.attach(it) + } hr() h2 { +(meta["title"].string ?: name.toString()) } } From c5f14fb5e7aa733bce67482302e2ce2d09d77542 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 29 Sep 2019 22:11:09 +0300 Subject: [PATCH 11/55] Tree editor tweaks --- .../kotlin/hep/dataforge/vis/common/Colors.kt | 5 ++ .../vis/spatial/gdml/GDMLTransformer.kt | 6 +- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 49 ++------------ .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 7 +- .../dataforge/vis/spatial/VisualObject3D.kt | 11 ++- .../vis/spatial/three/ThreeOutput.kt | 19 ++++-- .../vis/spatial/three/ThreeProxyFactory.kt | 5 +- .../vis/spatial/tree/jsVisualTree.kt | 22 ++++-- .../vis/spatial/tree/propertyEditor.kt | 67 +++++++++++++++++++ 9 files changed, 126 insertions(+), 65 deletions(-) create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/propertyEditor.kt diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt index 0365e300..437c30ab 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt @@ -174,4 +174,9 @@ object Colors { const val whitesmoke = 0xF5F5F5 const val yellow = 0xFFFF00 const val yellowgreen = 0x9ACD32 + + fun rgbToString(rgb: Int): String { + val string = rgb.toString(16) + return "#" + string.substring(string.length - 6) + } } \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index ad8ac85d..85d8ddec 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -2,6 +2,8 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.Meta import hep.dataforge.meta.buildMeta +import hep.dataforge.names.toName +import hep.dataforge.vis.common.Colors import hep.dataforge.vis.spatial.VisualGroup3D import hep.dataforge.vis.spatial.VisualObject3D import hep.dataforge.vis.spatial.material @@ -36,10 +38,10 @@ class GDMLTransformer(val root: GDML) { val materialColor = materialCache.getOrPut(material) { buildMeta { - "color" to random.nextInt(0, Int.MAX_VALUE) + "color" to Colors.rgbToString(random.nextInt(0, Int.MAX_VALUE)) } } - + obj.setProperty("gdml.material".toName(), material.name) obj.material = materialColor obj.solidConfiguration(parent, solid) } diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 79465f82..b55529fc 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -1,10 +1,7 @@ package hep.dataforge.vis.spatial.gdml.demo import hep.dataforge.context.Global -import hep.dataforge.meta.get -import hep.dataforge.meta.string import hep.dataforge.vis.common.VisualGroup -import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.hmr.ApplicationBase import hep.dataforge.vis.hmr.startApplication import hep.dataforge.vis.spatial.* @@ -14,11 +11,15 @@ import hep.dataforge.vis.spatial.gdml.toVisual import hep.dataforge.vis.spatial.three.ThreeOutput import hep.dataforge.vis.spatial.three.ThreePlugin import hep.dataforge.vis.spatial.three.output +import hep.dataforge.vis.spatial.tree.propertyEditor import hep.dataforge.vis.spatial.tree.render import hep.dataforge.vis.spatial.tree.toTree import kotlinx.html.InputType import kotlinx.html.dom.append -import kotlinx.html.js.* +import kotlinx.html.js.input +import kotlinx.html.js.li +import kotlinx.html.js.p +import kotlinx.html.js.ul import org.w3c.dom.Element import org.w3c.dom.HTMLDivElement import org.w3c.dom.HTMLElement @@ -150,43 +151,6 @@ private class GDMLDemoApp : ApplicationBase() { } - fun showEditor(item: VisualObject?, name: String?) { - val element = document.getElementById("editor") ?: error("Element with id 'canvas' not found on page") - element.clear() - if (item != null) { - element.append { - div("card") { - div("card-body") { - h3(classes = "card-title") { +(name ?: "") } - form { - div("form-group") { - label { - +"Color: " - } - input(InputType.color, classes = "form-control").apply { - onchange = { event -> - item.color(value) - } - } - } - div("form-group form-check") { - input(InputType.checkBox, classes = "form-check-input").apply { - this.value = item.material?.get("color").string ?: "" - onchange = { event -> - item.visible = checked - Unit - } - } - label("form-check-label") { +"Visible" } - } - } - } - } - } - } - } - - override fun start(state: Map) { val context = Global.context("demo") {} @@ -196,6 +160,7 @@ private class GDMLDemoApp : ApplicationBase() { val canvas = document.getElementById("canvas") ?: error("Element with id 'canvas' not found on page") val layers = document.getElementById("layers") ?: error("Element with id 'layers' not found on page") val tree = document.getElementById("tree") ?: error("Element with id 'tree' not found on page") + val editor = document.getElementById("editor") ?: error("Element with id 'editor' not found on page") canvas.clear() val action: (name: String, data: String) -> Unit = { name, data -> @@ -224,7 +189,7 @@ private class GDMLDemoApp : ApplicationBase() { setupLayers(layers, output) if (visual is VisualGroup) { - visual.toTree(::showEditor).render(tree as HTMLElement) { + visual.toTree(editor::propertyEditor).render(tree as HTMLElement) { showCheckboxes = true } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 3c9ca492..44bc6b82 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -85,11 +85,7 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua inner class ProxyChild(val name: Name) : AbstractVisualObject() { override var properties: Config? - get() = propertyCache.getOrPut(name) { - Config().apply { - attachListener(this@ProxyChild) - } - } + get() = propertyCache[name] set(value) { if (value == null) { propertyCache.remove(name)?.removeListener(this@Proxy) @@ -99,7 +95,6 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua } } } - } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index 79804d44..cb882f18 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -6,6 +6,7 @@ import hep.dataforge.io.NameSerializer import hep.dataforge.meta.* import hep.dataforge.names.plus import hep.dataforge.output.Output +import hep.dataforge.vis.common.Colors.rgbToString import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY @@ -124,13 +125,21 @@ var VisualObject.selected: Boolean? set(value) = setProperty(SELECTED_KEY, value) fun VisualObject.color(rgb: Int) { - material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb } + material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgbToString(rgb) } } fun VisualObject.color(rgb: String) { material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb } } +var VisualObject.color: String? + get() = material["color"].string + set(value) { + if (value != null) { + color(value) + } + } + fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) { material = buildMeta(builder) } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt index 2e8bd0e4..91438022 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt @@ -32,15 +32,14 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output Int = { this.offsetWidth }) { + fun attach(element: HTMLElement) { element.clear() - val width by meta.number(computeWidth(element)).int - val height: Int = (width / camera.aspect).toInt() + camera.aspect = 1.0 val renderer = WebGLRenderer { antialias = true }.apply { setClearColor(Colors.skyblue, 1) - setSize(width, height) + } three.addControls(camera, renderer.domElement, meta["controls"].node ?: EmptyMeta) @@ -52,13 +51,19 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output { } } - obj.onChildrenChange(object3D) { name, propertyHolder -> - (object3D.findChild(name) as? Mesh)?.updateProperties(propertyHolder) + obj.onChildrenChange(this) { name, propertyHolder -> + val child = object3D.findChild(name) + (child as? Mesh)?.updateProperties(propertyHolder) } return object3D diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt index 6f9f22ea..191e06ab 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt @@ -9,6 +9,7 @@ import hep.dataforge.names.NameToken import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.getProperty +import hep.dataforge.vis.spatial.Proxy import hep.dataforge.vis.spatial.selected import hep.dataforge.vis.spatial.visible import org.w3c.dom.HTMLElement @@ -32,13 +33,24 @@ internal fun createInspireTree(block: Config.() -> Unit = {}): InspireTree { return InspireTree(config) } -fun VisualGroup.toTree(onFocus: (VisualObject?, String?)->Unit = {obj,name->}): InspireTree { +fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { obj, name -> }): InspireTree { val map = HashMap() fun generateNodeConfig(item: VisualObject, fullName: Name): NodeConfig { val title = item.getProperty("title").string ?: fullName.last()?.toString() ?: "root" - val text = "$title[${item::class.toString().replace("class ","")}]" + val className = if (item is Proxy) { + item.template::class.toString() + } else { + item::class.toString() + }.replace("class ", "") + + val text: String = if (title.startsWith("@")) { + "[$className}]" + } else { + "$title[$className}]" + } + return json( "children" to if ((item as? VisualGroup)?.children?.isEmpty() != false) { emptyArray() @@ -68,7 +80,7 @@ fun VisualGroup.toTree(onFocus: (VisualObject?, String?)->Unit = {obj,name->}): } } - val inspireTree = createInspireTree{ + val inspireTree = createInspireTree { } val nodeConfig = generateNodeConfig(this, EmptyName) @@ -93,14 +105,14 @@ fun VisualGroup.toTree(onFocus: (VisualObject?, String?)->Unit = {obj,name->}): } inspireTree.on("node.unchecked") { node: TreeNode -> - if(!node.indeterminate()){ + if (!node.indeterminate()) { map[node.id]?.visible = node.checked() } } inspireTree.on("node.focused") { node: TreeNode, isLoadEvent: Boolean -> if (!isLoadEvent) { - onFocus(map[node.id],node.id) + onFocus(map[node.id], node.id) } } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/propertyEditor.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/propertyEditor.kt new file mode 100644 index 00000000..dc030b8d --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/propertyEditor.kt @@ -0,0 +1,67 @@ +package hep.dataforge.vis.spatial.tree + +import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.spatial.color +import hep.dataforge.vis.spatial.opacity +import hep.dataforge.vis.spatial.visible +import kotlinx.html.InputType +import kotlinx.html.dom.append +import kotlinx.html.js.* +import org.w3c.dom.Element +import kotlin.dom.clear + +fun Element.propertyEditor(item: VisualObject?, name: String?) { + clear() + if (item != null) { + append { + div("card") { + div("card-body") { + h3(classes = "card-title") { +(name ?: "") } + form { + div("form-group row") { + label("col-form-label col-4") { + +"Color: " + } + input(InputType.color, classes = "form-control col-8") { + value = item.color ?: "#ffffff" + }.apply { + onInputFunction = { + item.color = value + } + } + } + div("form-group row") { + label("col-form-label col-4") { + +"Opacity: " + } + input(InputType.range, classes = "form-control col-8") { + min = "0.0" + max = "1.0" + step = "0.1" + value = item.opacity.toString() + }.apply { + onInputFunction = { + item.opacity = value.toDouble() + } + } + } + div("form-group row") { + label("col-form-label col-4") { +"Visible: " } + div("col-8") { + div("form-check") { + input(InputType.checkBox, classes = "form-check-input").apply { + this.checked = item.visible ?: true + onInputFunction = { + item.visible = checked + } + } + } + } + + } + } + } + } + } + } +} From 2fcfd767c181efe4c5ebcf2288d3500c043201b7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 1 Oct 2019 14:23:54 +0300 Subject: [PATCH 12/55] New styling design --- .../vis/common/AbstractVisualGroup.kt | 1 + .../vis/common/AbstractVisualObject.kt | 64 +++++++++++++------ .../kotlin/hep/dataforge/vis/common/Colors.kt | 4 +- .../hep/dataforge/vis/common/VisualGroup.kt | 41 ++++++++---- .../hep/dataforge/vis/common/VisualObject.kt | 20 +++--- ...ctDelegates.kt => VisualObjectDelegate.kt} | 34 +++++----- .../dataforge/vis/spatial/gdml/visualGDML.kt | 2 +- .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 6 ++ .../dataforge/vis/spatial/VisualGroup3D.kt | 46 +++++++++++-- .../dataforge/vis/spatial/VisualObject3D.kt | 2 +- .../vis/spatial/three/ThreeFactory.kt | 2 +- 11 files changed, 151 insertions(+), 71 deletions(-) rename dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/{VisualObjectDelegates.kt => VisualObjectDelegate.kt} (76%) diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt index f4486451..ba2fabb0 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -21,6 +21,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { */ abstract override val children: Map //get() = _children + // init { // //Do after deserialization // children.values.forEach { diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index 5d4622e2..6624b0b1 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -1,8 +1,10 @@ package hep.dataforge.vis.common import hep.dataforge.meta.* +import hep.dataforge.names.EmptyName import hep.dataforge.names.Name -import hep.dataforge.names.asName +import hep.dataforge.names.toName +import hep.dataforge.vis.common.VisualObject.Companion.STYLE_KEY import kotlinx.serialization.Transient internal data class PropertyListener( @@ -15,17 +17,21 @@ abstract class AbstractVisualObject : VisualObject { @Transient override var parent: VisualObject? = null - override var style: Meta? = null + protected abstract var properties: Config? + + override var style: List + get() = properties?.let { it[STYLE_KEY].stringList } ?: emptyList() set(value) { - //notify about style removed - style?.items?.forEach {(name, value) -> - propertyChanged(name.asName(), value, null) - } - field = value - //notify about style adition - value?.items?.forEach { (name, value) -> - propertyChanged(name.asName(), null, value) - } + setProperty(VisualObject.STYLE_KEY, value) + } + + /** + * The config is initialized and assigned on-demand. + * To avoid unnecessary allocations, one should access [properties] via [getProperty] instead. + */ + override val config: Config + get() = properties ?: Config().also { config -> + properties = config.apply { onChange(this, ::propertyChanged) } } @Transient @@ -45,22 +51,32 @@ abstract class AbstractVisualObject : VisualObject { listeners.removeAll { it.owner == owner } } - protected abstract var properties: Config? - - override val config: Config - get() = properties ?: Config().also { config -> - properties = config.apply { onChange(this, ::propertyChanged) } - } - override fun setProperty(name: Name, value: Any?) { config[name] = value } + private var styleCache: Laminate? = null + + private fun styles(): Laminate { + return styleCache ?: kotlin.run { + Laminate(style.map { it.toName() }.mapNotNull(::findStyle)) + .also { styleCache = it } + } + } + + /** + * Helper to reset style cache + */ + protected fun styleChanged() { + styleCache = null + propertyChanged(EmptyName) + } + override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { - style?.get(name) ?: properties?.get(name) ?: parent?.getProperty(name, inherit) + properties?.get(name) ?: parent?.getProperty(name, inherit) ?: styles()[name] } else { - style?.get(name) ?: properties?.get(name) + properties?.get(name) ?: styles()[name] } } @@ -71,4 +87,12 @@ abstract class AbstractVisualObject : VisualObject { "properties" to properties updateMeta() } +} + +internal fun VisualObject.findStyle(styleName: Name): Meta? { + if (this is VisualGroup) { + val style = getStyle(styleName) + if (style != null) return style + } + return parent?.findStyle(styleName) } \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt index 437c30ab..a908cc53 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt @@ -1,5 +1,7 @@ package hep.dataforge.vis.common +import kotlin.math.max + /** * Taken from https://github.com/markaren/three.kt/blob/master/threejs-wrapper/src/main/kotlin/info/laht/threekt/math/ColorConstants.kt */ @@ -177,6 +179,6 @@ object Colors { fun rgbToString(rgb: Int): String { val string = rgb.toString(16) - return "#" + string.substring(string.length - 6) + return "#" + string.substring(max(0, string.length - 6)) } } \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt index 2be37102..4288d640 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt @@ -1,5 +1,6 @@ package hep.dataforge.vis.common +import hep.dataforge.meta.Meta import hep.dataforge.names.* import hep.dataforge.provider.Provider @@ -11,18 +12,19 @@ interface VisualGroup : VisualObject, Provider, Iterable { override val defaultTarget: String get() = VisualObject.TYPE - override fun provideTop(target: String): Map = if (target == VisualObject.TYPE) { - children.flatMap { (key, value) -> - val res: Map = if (value is VisualGroup) { - value.provideTop(target).mapKeys { key + it.key } - } else { - mapOf(key.asName() to value) - } - res.entries - }.associate { it.toPair() } - } else { - emptyMap() - } + override fun provideTop(target: String): Map = + when (target) { + VisualObject.TYPE -> children.flatMap { (key, value) -> + val res: Map = if (value is VisualGroup) { + value.provideTop(target).mapKeys { key + it.key } + } else { + mapOf(key.asName() to value) + } + res.entries + }.associate { it.toPair() } + //TODO add styles + else -> emptyMap() + } /** * Iterate over children of this group @@ -30,7 +32,20 @@ interface VisualGroup : VisualObject, Provider, Iterable { override fun iterator(): Iterator = children.values.iterator() /** - * Add listener for children change + * Resolve style by its name + * TODO change to Config? + */ + fun getStyle(name: Name): Meta? + + /** + * Add or replace style with given name + */ + fun setStyle(name: Name, meta: Meta) + + /** + * Add listener for children structure change. + * @param owner the handler to properly remove listeners + * @param action First argument of the action is the name of changed child. Second argument is the new value of the object. */ fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt index 4798f36d..a9600be6 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt @@ -1,14 +1,17 @@ package hep.dataforge.vis.common -import hep.dataforge.meta.* +import hep.dataforge.meta.Configurable +import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.MetaRepr import hep.dataforge.names.Name +import hep.dataforge.names.asName import hep.dataforge.names.toName import hep.dataforge.provider.Type import hep.dataforge.vis.common.VisualObject.Companion.TYPE import kotlinx.serialization.Transient -private fun Laminate.withTop(meta: Meta): Laminate = Laminate(listOf(meta) + layers) -private fun Laminate.withBottom(meta: Meta): Laminate = Laminate(layers + meta) +//private fun Laminate.withTop(meta: Meta): Laminate = Laminate(listOf(meta) + layers) +//private fun Laminate.withBottom(meta: Meta): Laminate = Laminate(layers + meta) /** * A root type for display hierarchy @@ -22,11 +25,6 @@ interface VisualObject : MetaRepr, Configurable { @Transient var parent: VisualObject? - /** - * A style which is set externally and could not be modified from inside - */ - var style: Meta? - /** * Set property for this object */ @@ -52,8 +50,11 @@ interface VisualObject : MetaRepr, Configurable { */ fun removeChangeListener(owner: Any?) + var style: List + companion object { const val TYPE = "visual" + val STYLE_KEY = "style".asName() //const val META_KEY = "@meta" //const val TAGS_KEY = "@tags" @@ -61,5 +62,4 @@ interface VisualObject : MetaRepr, Configurable { } fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = getProperty(key.toName(), inherit) -fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value) - +fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value) \ No newline at end of file diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegate.kt similarity index 76% rename from dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt rename to dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegate.kt index c9b88bb3..c51cdfe8 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegates.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObjectDelegate.kt @@ -1,7 +1,6 @@ package hep.dataforge.vis.common import hep.dataforge.meta.* -import hep.dataforge.names.EmptyName import hep.dataforge.names.Name import hep.dataforge.names.NameToken import hep.dataforge.names.asName @@ -11,12 +10,11 @@ import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty -fun String.asName() = if (isBlank()) EmptyName else NameToken(this).asName() /** * A delegate for display object properties */ -class DisplayObjectDelegate( +class VisualObjectDelegate( val key: Name?, val default: MetaItem<*>?, val inherited: Boolean @@ -36,7 +34,7 @@ class DisplayObjectDelegate( } } -class DisplayObjectDelegateWrapper( +class VisualObjectDelegateWrapper( val key: Name?, val default: T, val inherited: Boolean, @@ -63,55 +61,55 @@ class DisplayObjectDelegateWrapper( fun VisualObject.value(default: Value? = null, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.value } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.value } fun VisualObject.string(default: String? = null, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.string } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.string } fun VisualObject.boolean(default: Boolean? = null, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.boolean } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.boolean } fun VisualObject.number(default: Number? = null, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.number } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.number } fun VisualObject.double(default: Double? = null, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.double } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.double } fun VisualObject.int(default: Int? = null, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.int } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.int } fun VisualObject.node(key: String? = null, inherited: Boolean = true) = - DisplayObjectDelegateWrapper(key?.asName(), null, inherited) { it.node } + VisualObjectDelegateWrapper(key?.asName(), null, inherited) { it.node } fun VisualObject.item(key: String? = null, inherited: Boolean = true) = - DisplayObjectDelegateWrapper(key?.asName(), null, inherited) { it } + VisualObjectDelegateWrapper(key?.asName(), null, inherited) { it } //fun Configurable.spec(spec: Specification, key: String? = null) = ChildConfigDelegate(key) { spec.wrap(this) } @JvmName("safeString") fun VisualObject.string(default: String, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.string } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.string } @JvmName("safeBoolean") fun VisualObject.boolean(default: Boolean, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.boolean } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.boolean } @JvmName("safeNumber") fun VisualObject.number(default: Number, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.number } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.number } @JvmName("safeDouble") fun VisualObject.double(default: Double, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.double } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.double } @JvmName("safeInt") fun VisualObject.int(default: Int, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper(key?.asName(), default, inherited) { it.int } + VisualObjectDelegateWrapper(key?.asName(), default, inherited) { it.int } inline fun > VisualObject.enum(default: E, key: String? = null, inherited: Boolean = false) = - DisplayObjectDelegateWrapper( + VisualObjectDelegateWrapper( key?.let { NameToken(it).asName() }, default, inherited diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index 580f487e..84f96717 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -1,8 +1,8 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.names.EmptyName +import hep.dataforge.names.asName import hep.dataforge.names.plus -import hep.dataforge.vis.common.asName import hep.dataforge.vis.common.get import hep.dataforge.vis.spatial.* import scientifik.gdml.* diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 44bc6b82..18faaee2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -5,6 +5,7 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.ConfigSerializer import hep.dataforge.io.NameSerializer import hep.dataforge.meta.Config +import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaItem import hep.dataforge.names.Name @@ -37,6 +38,11 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua get() = (parent as? VisualGroup3D)?.getTemplate(templateName) ?: error("Template with name $templateName not found in $parent") + override fun getStyle(name: Name): Meta? = null + + override fun setStyle(name: Name, meta: Meta) { + //do nothing + } override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 2ec91290..d0057f0c 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -1,21 +1,29 @@ -@file:UseSerializers(Point3DSerializer::class, ConfigSerializer::class, NameTokenSerializer::class) +@file:UseSerializers( + Point3DSerializer::class, + ConfigSerializer::class, + NameTokenSerializer::class, + NameSerializer::class +) package hep.dataforge.vis.spatial import hep.dataforge.io.ConfigSerializer +import hep.dataforge.io.NameSerializer import hep.dataforge.meta.Config +import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.set -import hep.dataforge.names.Name -import hep.dataforge.names.NameToken -import hep.dataforge.names.asName -import hep.dataforge.names.isEmpty +import hep.dataforge.names.* import hep.dataforge.vis.common.AbstractVisualGroup +import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.common.VisualObject import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers +import kotlin.collections.component1 +import kotlin.collections.component2 +import kotlin.collections.set @Serializable class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { @@ -28,8 +36,34 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { field = value } + //FIXME to be lifted to AbstractVisualGroup after https://github.com/Kotlin/kotlinx.serialization/issues/378 is fixed public override var properties: Config? = null + private val styles = HashMap() + + override fun getStyle(name: Name): Meta? = styles[name] + + override fun setStyle(name: Name, meta: Meta) { + fun VisualObject.applyStyle(name: Name, meta: Meta) { + if (style.contains(name.toString())) { + //full update + //TODO do a fine grained update + if(this is AbstractVisualObject){ + styleChanged() + } else { + propertyChanged(EmptyName) + } + } + if (this is VisualGroup) { + this.children.forEach { (_, child) -> + child.applyStyle(name, meta) + } + } + } + styles[name] = meta + applyStyle(name, meta) + } + override var position: Point3D? = null override var rotation: Point3D? = null override var scale: Point3D? = null @@ -96,7 +130,7 @@ fun VisualGroup.attachChildren() { it.parent = this (it as? VisualGroup)?.attachChildren() } - if(this is VisualGroup3D){ + if (this is VisualGroup3D) { templates?.apply { parent = this@attachChildren attachChildren() diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index cb882f18..ed6acd9c 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -4,11 +4,11 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.NameSerializer import hep.dataforge.meta.* +import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.output.Output import hep.dataforge.vis.common.Colors.rgbToString import hep.dataforge.vis.common.VisualObject -import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index 96289702..466e1c4f 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -2,10 +2,10 @@ package hep.dataforge.vis.spatial.three import hep.dataforge.meta.boolean import hep.dataforge.meta.node +import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.names.startsWith import hep.dataforge.provider.Type -import hep.dataforge.vis.common.asName import hep.dataforge.vis.spatial.* import hep.dataforge.vis.spatial.three.ThreeFactory.Companion.TYPE import info.laht.threekt.core.BufferGeometry From d1e2d8d60bef8ed248537e59a57b4670d14e0d23 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 1 Oct 2019 22:22:13 +0300 Subject: [PATCH 13/55] New Proxy child styling and json editor --- .../vis/common/AbstractVisualGroup.kt | 41 +- .../vis/common/AbstractVisualObject.kt | 14 +- .../{VisualGroup.kt => MutableVisualGroup.kt} | 22 +- .../hep/dataforge/vis/common/VisualObject.kt | 12 +- .../vis/spatial/gdml/GDMLTransformer.kt | 32 +- .../vis/spatial/gdml/optimizations.kt | 8 +- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 10 +- .../jsMain/web/css/img/jsoneditor-icons.svg | 748 ++++++++++++++++++ .../src/jsMain/web/css/jsoneditor.min.css | 6 + .../src/jsMain/web/index.html | 1 + .../dataforge/vis/spatial/gdml/testMain.kt | 23 +- dataforge-vis-spatial/build.gradle.kts | 1 + .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 84 +- .../dataforge/vis/spatial/Visual3DPlugin.kt | 4 +- .../dataforge/vis/spatial/VisualGroup3D.kt | 54 +- .../dataforge/vis/spatial/VisualObject3D.kt | 17 +- .../vis/spatial/three/ThreeProxyFactory.kt | 7 +- .../vis/spatial/tree/jsVisualTree.kt | 21 +- .../dataforge/vis/spatial/tree/jsonEditor.kt | 185 +++++ .../vis/spatial/tree/propertyEditor.kt | 19 +- 20 files changed, 1145 insertions(+), 164 deletions(-) rename dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/{VisualGroup.kt => MutableVisualGroup.kt} (93%) create mode 100644 dataforge-vis-spatial-gdml/src/jsMain/web/css/img/jsoneditor-icons.svg create mode 100644 dataforge-vis-spatial-gdml/src/jsMain/web/css/jsoneditor.min.css create mode 100644 dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsonEditor.kt diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt index ba2fabb0..fda6c7fc 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualGroup.kt @@ -1,18 +1,16 @@ package hep.dataforge.vis.common +import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaItem -import hep.dataforge.names.Name -import hep.dataforge.names.NameToken -import hep.dataforge.names.asName -import hep.dataforge.names.isEmpty +import hep.dataforge.names.* import kotlinx.serialization.Transient /** * Abstract implementation of group of [VisualObject] */ -abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { +abstract class AbstractVisualGroup : AbstractVisualObject(), MutableVisualGroup { //protected abstract val _children: MutableMap @@ -21,6 +19,32 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { */ abstract override val children: Map //get() = _children + //TODO replace by custom object with get/set functionality + protected abstract val styles: MutableMap + + override fun getStyle(name: Name): Meta? = styles[name] + + override fun setStyle(name: Name, meta: Meta) { + fun VisualObject.applyStyle(name: Name, meta: Meta) { + if (style.contains(name.toString())) { + //full update + //TODO do a fine grained update + if (this is AbstractVisualObject) { + styleChanged() + } else { + propertyChanged(EmptyName) + } + } + if (this is VisualGroup) { + this.children.forEach { (_, child) -> + child.applyStyle(name, meta) + } + } + } + styles[name] = meta + applyStyle(name, meta) + } + // init { // //Do after deserialization @@ -75,12 +99,13 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { /** * Add a static child. Statics could not be found by name, removed or replaced */ - protected abstract fun addStatic(child: VisualObject) + protected open fun addStatic(child: VisualObject) = + setChild(NameToken("@static(${child.hashCode()})"), child) /** * Recursively create a child group */ - protected abstract fun createGroup(name: Name): VisualGroup + protected abstract fun createGroup(name: Name): MutableVisualGroup /** * Add named or unnamed child to the group. If key is [null] the child is considered unnamed. Both key and value are not @@ -103,7 +128,7 @@ abstract class AbstractVisualGroup : AbstractVisualObject(), VisualGroup { } else -> { //TODO add safety check - val parent = (get(name.cutLast()) as? VisualGroup) ?: createGroup(name.cutLast()) + val parent = (get(name.cutLast()) as? MutableVisualGroup) ?: createGroup(name.cutLast()) parent[name.last()!!.asName()] = child } } diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index 6624b0b1..385c9360 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -17,12 +17,13 @@ abstract class AbstractVisualObject : VisualObject { @Transient override var parent: VisualObject? = null - protected abstract var properties: Config? + abstract override var properties: Config? override var style: List get() = properties?.let { it[STYLE_KEY].stringList } ?: emptyList() set(value) { - setProperty(VisualObject.STYLE_KEY, value) + setProperty(STYLE_KEY, value) + styleChanged() } /** @@ -57,12 +58,11 @@ abstract class AbstractVisualObject : VisualObject { private var styleCache: Laminate? = null - private fun styles(): Laminate { - return styleCache ?: kotlin.run { + protected val actualStyles: Laminate + get() = styleCache ?: run { Laminate(style.map { it.toName() }.mapNotNull(::findStyle)) .also { styleCache = it } } - } /** * Helper to reset style cache @@ -74,9 +74,9 @@ abstract class AbstractVisualObject : VisualObject { override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { - properties?.get(name) ?: parent?.getProperty(name, inherit) ?: styles()[name] + properties?.get(name) ?: parent?.getProperty(name, inherit) ?: actualStyles[name] } else { - properties?.get(name) ?: styles()[name] + properties?.get(name) ?: actualStyles[name] } } diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/MutableVisualGroup.kt similarity index 93% rename from dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt rename to dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/MutableVisualGroup.kt index 4288d640..f3b1ca7d 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualGroup.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/MutableVisualGroup.kt @@ -4,7 +4,7 @@ import hep.dataforge.meta.Meta import hep.dataforge.names.* import hep.dataforge.provider.Provider -interface VisualGroup : VisualObject, Provider, Iterable { +interface VisualGroup : Provider, Iterable, VisualObject { /** * A map of top level named children */ @@ -26,6 +26,7 @@ interface VisualGroup : VisualObject, Provider, Iterable { else -> emptyMap() } + /** * Iterate over children of this group */ @@ -42,6 +43,17 @@ interface VisualGroup : VisualObject, Provider, Iterable { */ fun setStyle(name: Name, meta: Meta) + operator fun get(name: Name): VisualObject? { + return when { + name.isEmpty() -> this + name.length == 1 -> children[name.first()!!] + else -> (children[name.first()!!] as? VisualGroup)?.get(name.cutFirst()) + } + } +} + +interface MutableVisualGroup : VisualGroup { + /** * Add listener for children structure change. * @param owner the handler to properly remove listeners @@ -54,14 +66,6 @@ interface VisualGroup : VisualObject, Provider, Iterable { */ fun removeChildrenChangeListener(owner: Any?) - operator fun get(name: Name): VisualObject? { - return when { - name.isEmpty() -> this - name.length == 1 -> children[name.first()!!] - else -> (children[name.first()!!] as? VisualGroup)?.get(name.cutFirst()) - } - } - operator fun set(name: Name, child: VisualObject?) } diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt index a9600be6..4a5ce8b3 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/VisualObject.kt @@ -1,5 +1,6 @@ package hep.dataforge.vis.common +import hep.dataforge.meta.Config import hep.dataforge.meta.Configurable import hep.dataforge.meta.MetaItem import hep.dataforge.meta.MetaRepr @@ -25,6 +26,11 @@ interface VisualObject : MetaRepr, Configurable { @Transient var parent: VisualObject? + /** + * Direct properties access + */ + val properties: Config? + /** * Set property for this object */ @@ -62,4 +68,8 @@ interface VisualObject : MetaRepr, Configurable { } fun VisualObject.getProperty(key: String, inherit: Boolean = true): MetaItem<*>? = getProperty(key.toName(), inherit) -fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value) \ No newline at end of file +fun VisualObject.setProperty(key: String, value: Any?) = setProperty(key.toName(), value) + +fun VisualObject.applyStyle(name: String) { + style = style + name +} \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index 85d8ddec..da1c7f67 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -1,13 +1,18 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.Meta +import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.buildMeta +import hep.dataforge.names.Name import hep.dataforge.names.toName import hep.dataforge.vis.common.Colors +import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.common.applyStyle import hep.dataforge.vis.spatial.VisualGroup3D import hep.dataforge.vis.spatial.VisualObject3D -import hep.dataforge.vis.spatial.material +import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY import scientifik.gdml.* +import kotlin.collections.set import kotlin.random.Random class GDMLTransformer(val root: GDML) { @@ -24,25 +29,33 @@ class GDMLTransformer(val root: GDML) { * A special group for local templates */ val templates by lazy { VisualGroup3D() } + private val styles = HashMap() var lUnit: LUnit = LUnit.MM var solidAction: (GDMLSolid) -> Action = { Action.CACHE } - var volumeAction: (GDMLGroup) -> Action = { Action.ACCEPT } + var volumeAction: (GDMLGroup) -> Action = { Action.CACHE } var solidConfiguration: VisualObject3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { _, _ -> } + fun VisualObject.useStyle(name: String, builder: MetaBuilder.() -> Unit) { + styles.getOrPut(name.toName()){ + buildMeta(builder) + } + applyStyle(name) + } + internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid) { val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref) - val materialColor = materialCache.getOrPut(material) { - buildMeta { - "color" to Colors.rgbToString(random.nextInt(0, Int.MAX_VALUE)) - } + val styleName = "material[${material.name}]" + + obj.useStyle(styleName){ + COLOR_KEY to Colors.rgbToString(random.nextInt(0, Int.MAX_VALUE)) + "gdml.material" to material.name } - obj.setProperty("gdml.material".toName(), material.name) - obj.material = materialColor + obj.solidConfiguration(parent, solid) } @@ -72,6 +85,9 @@ class GDMLTransformer(val root: GDML) { // res = it(res) // } final.templates = templates + styles.forEach { + final.setStyle(it.key, it.value) + } onFinish(this@GDMLTransformer) return final } diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt index ef842aa7..bf077d72 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/optimizations.kt @@ -2,7 +2,7 @@ package hep.dataforge.vis.spatial.gdml import hep.dataforge.meta.update import hep.dataforge.names.asName -import hep.dataforge.vis.common.VisualGroup +import hep.dataforge.vis.common.MutableVisualGroup import hep.dataforge.vis.spatial.Point3D import hep.dataforge.vis.spatial.VisualGroup3D import hep.dataforge.vis.spatial.VisualObject3D @@ -16,7 +16,7 @@ typealias GDMLOptimization = GDMLTransformer.(VisualGroup3D) -> VisualGroup3D * Collapse nodes with single child */ val optimizeSingleChild: GDMLOptimization = { tree -> - fun VisualGroup.replaceChildren() { + fun MutableVisualGroup.replaceChildren() { children.forEach { (key, child) -> if (child is VisualGroup3D && child.children.size == 1) { val newChild = child.children.values.first().apply { @@ -40,13 +40,13 @@ val optimizeSingleChild: GDMLOptimization = { tree -> } } - if (newChild is VisualGroup) { + if (newChild is MutableVisualGroup) { newChild.replaceChildren() } //actual replacement set(key.asName(), newChild) - } else if (child is VisualGroup) { + } else if (child is MutableVisualGroup) { child.replaceChildren() } } diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index b55529fc..49f8a382 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -57,11 +57,11 @@ private class GDMLDemoApp : ApplicationBase() { onload = { val string = result as String - try { +// try { block(file.name, string) - } catch (ex: Exception) { - console.error(ex) - } +// } catch (ex: Exception) { +// console.error(ex) +// } } readAsText(file) @@ -190,7 +190,7 @@ private class GDMLDemoApp : ApplicationBase() { if (visual is VisualGroup) { visual.toTree(editor::propertyEditor).render(tree as HTMLElement) { - showCheckboxes = true + showCheckboxes = false } } diff --git a/dataforge-vis-spatial-gdml/src/jsMain/web/css/img/jsoneditor-icons.svg b/dataforge-vis-spatial-gdml/src/jsMain/web/css/img/jsoneditor-icons.svg new file mode 100644 index 00000000..332be179 --- /dev/null +++ b/dataforge-vis-spatial-gdml/src/jsMain/web/css/img/jsoneditor-icons.svg @@ -0,0 +1,748 @@ + + + JSON Editor Icons + + + + image/svg+xml + + JSON Editor Icons + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dataforge-vis-spatial-gdml/src/jsMain/web/css/jsoneditor.min.css b/dataforge-vis-spatial-gdml/src/jsMain/web/css/jsoneditor.min.css new file mode 100644 index 00000000..e436fb54 --- /dev/null +++ b/dataforge-vis-spatial-gdml/src/jsMain/web/css/jsoneditor.min.css @@ -0,0 +1,6 @@ +.jsoneditor .search input{height:auto;border:inherit;border:none;box-shadow:none}.jsoneditor table{border-collapse:collapse;width:auto}.jsoneditor td,.jsoneditor th{padding:0;display:table-cell;text-align:left;vertical-align:inherit;border-radius:inherit}.jsoneditor{color:#1a1a1a;border:thin solid #3883fa;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;width:100%;height:100%;position:relative;padding:0;line-height:100%}div.jsoneditor-default,div.jsoneditor-field,div.jsoneditor-readonly,div.jsoneditor-value{border:1px solid transparent;min-height:16px;min-width:32px;padding:2px;margin:1px;word-wrap:break-word;float:left}div.jsoneditor-field p,div.jsoneditor-value p{margin:0}div.jsoneditor-value{word-break:break-word}div.jsoneditor-value.jsoneditor-empty::after{content:"value"}div.jsoneditor-value.jsoneditor-string{color:#006000}div.jsoneditor-value.jsoneditor-number{color:#ee422e}div.jsoneditor-value.jsoneditor-boolean{color:#ff8c00}div.jsoneditor-value.jsoneditor-null{color:#004ed0}div.jsoneditor-value.jsoneditor-invalid{color:#000}div.jsoneditor-readonly{min-width:16px;color:grey}div.jsoneditor-empty{border-color:#d3d3d3;border-style:dashed;border-radius:2px}div.jsoneditor-field.jsoneditor-empty::after{content:"field"}div.jsoneditor td{vertical-align:top}div.jsoneditor td.jsoneditor-separator{padding:3px 0;vertical-align:top;color:grey}div.jsoneditor td.jsoneditor-tree{vertical-align:top}div.jsoneditor div.jsoneditor-anchor{cursor:pointer}div.jsoneditor div.jsoneditor-anchor .picker_wrapper.popup.popup_bottom{top:28px;left:-10px}div.jsoneditor.busy pre.jsoneditor-preview{background:#f5f5f5;color:grey}div.jsoneditor.busy div.jsoneditor-busy{display:inherit}div.jsoneditor code.jsoneditor-preview{background:0 0}div.jsoneditor.jsoneditor-mode-preview pre.jsoneditor-preview{width:100%;height:100%;box-sizing:border-box;overflow:auto;padding:2px;margin:0;white-space:pre-wrap;word-break:break-all}div.jsoneditor-default{color:grey;padding-left:10px}div.jsoneditor-tree{width:100%;height:100%;position:relative;overflow:auto}div.jsoneditor-tree button.jsoneditor-button{width:24px;height:24px;padding:0;margin:0;border:none;cursor:pointer;background:transparent url(img/jsoneditor-icons.svg)}div.jsoneditor-tree button.jsoneditor-button:focus{background-color:#f5f5f5;outline:#e5e5e5 solid 1px}div.jsoneditor-tree button.jsoneditor-collapsed{background-position:0 -48px}div.jsoneditor-tree button.jsoneditor-expanded{background-position:0 -72px}div.jsoneditor-tree button.jsoneditor-contextmenu{background-position:-48px -72px}div.jsoneditor-tree button.jsoneditor-invisible{visibility:hidden;background:0 0}div.jsoneditor-tree button.jsoneditor-dragarea{background:url(img/jsoneditor-icons.svg) -72px -72px;cursor:move}div.jsoneditor-tree :focus{outline:0}div.jsoneditor-tree div.jsoneditor-show-more{display:inline-block;padding:3px 4px;margin:2px 0;background-color:#e5e5e5;border-radius:3px;color:grey;font-family:arial,sans-serif;font-size:10pt}div.jsoneditor-tree div.jsoneditor-show-more a{display:inline-block;color:grey}div.jsoneditor-tree div.jsoneditor-color{display:inline-block;width:12px;height:12px;margin:4px;border:1px solid grey;cursor:pointer}div.jsoneditor-tree div.jsoneditor-date{background:#a1a1a1;color:#fff;font-family:arial,sans-serif;border-radius:3px;display:inline-block;padding:3px;margin:0 3px}div.jsoneditor-tree table.jsoneditor-tree{border-collapse:collapse;border-spacing:0;width:100%}div.jsoneditor-tree .jsoneditor-button.jsoneditor-schema-error{width:24px;height:24px;padding:0;margin:0 4px 0 0;background:url(img/jsoneditor-icons.svg) -168px -48px}div.jsoneditor-outer{position:static;width:100%;height:100%;margin:0;padding:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}div.jsoneditor-outer.has-nav-bar{margin-top:-26px;padding-top:26px}div.jsoneditor-outer.has-nav-bar.has-main-menu-bar{margin-top:-61px;padding-top:61px}div.jsoneditor-outer.has-status-bar{margin-bottom:-26px;padding-bottom:26px}div.jsoneditor-outer.has-main-menu-bar{margin-top:-35px;padding-top:35px}div.jsoneditor-busy{position:absolute;top:15%;left:0;box-sizing:border-box;width:100%;text-align:center;display:none}div.jsoneditor-busy span{background-color:#ffffab;border:1px solid #fe0;border-radius:3px;padding:5px 15px;box-shadow:0 0 5px rgba(0,0,0,.4)}div.jsoneditor-field.jsoneditor-empty::after,div.jsoneditor-value.jsoneditor-empty::after{pointer-events:none;color:#d3d3d3;font-size:8pt}a.jsoneditor-value.jsoneditor-url,div.jsoneditor-value.jsoneditor-url{color:#006000;text-decoration:underline}a.jsoneditor-value.jsoneditor-url{display:inline-block;padding:2px;margin:2px}a.jsoneditor-value.jsoneditor-url:focus,a.jsoneditor-value.jsoneditor-url:hover{color:#ee422e}div.jsoneditor-field.jsoneditor-highlight,div.jsoneditor-field[contenteditable=true]:focus,div.jsoneditor-field[contenteditable=true]:hover,div.jsoneditor-value.jsoneditor-highlight,div.jsoneditor-value[contenteditable=true]:focus,div.jsoneditor-value[contenteditable=true]:hover{background-color:#ffffab;border:1px solid #fe0;border-radius:2px}div.jsoneditor-field.jsoneditor-highlight-active,div.jsoneditor-field.jsoneditor-highlight-active:focus,div.jsoneditor-field.jsoneditor-highlight-active:hover,div.jsoneditor-value.jsoneditor-highlight-active,div.jsoneditor-value.jsoneditor-highlight-active:focus,div.jsoneditor-value.jsoneditor-highlight-active:hover{background-color:#fe0;border:1px solid #ffc700;border-radius:2px}div.jsoneditor-value.jsoneditor-array,div.jsoneditor-value.jsoneditor-object{min-width:16px}div.jsoneditor-mode-form tr.jsoneditor-expandable td.jsoneditor-tree,div.jsoneditor-mode-view tr.jsoneditor-expandable td.jsoneditor-tree{cursor:pointer}div.jsoneditor-tree button.jsoneditor-contextmenu.jsoneditor-selected,div.jsoneditor-tree button.jsoneditor-contextmenu:focus,div.jsoneditor-tree button.jsoneditor-contextmenu:hover,tr.jsoneditor-selected.jsoneditor-first button.jsoneditor-contextmenu{background-position:-48px -48px}div.jsoneditor-tree div.jsoneditor-show-more a:focus,div.jsoneditor-tree div.jsoneditor-show-more a:hover{color:#ee422e}.ace-jsoneditor,textarea.jsoneditor-text{min-height:150px}textarea.jsoneditor-text{width:100%;height:100%;margin:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;outline-width:0;border:none;background-color:#fff;resize:none}tr.jsoneditor-highlight,tr.jsoneditor-selected{background-color:#d3d3d3}tr.jsoneditor-selected button.jsoneditor-contextmenu,tr.jsoneditor-selected button.jsoneditor-dragarea{visibility:hidden}tr.jsoneditor-selected.jsoneditor-first button.jsoneditor-contextmenu,tr.jsoneditor-selected.jsoneditor-first button.jsoneditor-dragarea{visibility:visible}div.jsoneditor-tree button.jsoneditor-dragarea:focus,div.jsoneditor-tree button.jsoneditor-dragarea:hover,tr.jsoneditor-selected.jsoneditor-first button.jsoneditor-dragarea{background-position:-72px -48px}div.jsoneditor td,div.jsoneditor th,div.jsoneditor tr{padding:0;margin:0}.jsoneditor-popover,.jsoneditor-schema-error,div.jsoneditor td,div.jsoneditor textarea,div.jsoneditor th,div.jsoneditor-field,div.jsoneditor-value,pre.jsoneditor-preview{font-family:"dejavu sans mono","droid sans mono",consolas,monaco,"lucida console","courier new",courier,monospace,sans-serif;font-size:10pt;color:#1a1a1a}.jsoneditor-schema-error{cursor:default;display:inline-block;height:24px;line-height:24px;position:relative;text-align:center;width:24px}.jsoneditor-popover{background-color:#4c4c4c;border-radius:3px;box-shadow:0 0 5px rgba(0,0,0,.4);color:#fff;padding:7px 10px;position:absolute;cursor:auto;width:200px;z-index:999}.jsoneditor-popover.jsoneditor-above{bottom:32px;left:-98px}.jsoneditor-popover.jsoneditor-above:before{border-top:7px solid #4c4c4c;bottom:-7px}.jsoneditor-popover.jsoneditor-below{top:32px;left:-98px}.jsoneditor-popover.jsoneditor-below:before{border-bottom:7px solid #4c4c4c;top:-7px}.jsoneditor-popover.jsoneditor-left{top:-7px;right:32px}.jsoneditor-popover.jsoneditor-left:before{border-left:7px solid #4c4c4c;border-top:7px solid transparent;border-bottom:7px solid transparent;content:"";top:19px;right:-14px;left:inherit;margin-left:inherit;margin-top:-7px;position:absolute}.jsoneditor-popover.jsoneditor-right{top:-7px;left:32px}.jsoneditor-popover.jsoneditor-right:before{border-right:7px solid #4c4c4c;border-top:7px solid transparent;border-bottom:7px solid transparent;content:"";top:19px;left:-14px;margin-left:inherit;margin-top:-7px;position:absolute}.jsoneditor-popover:before{border-right:7px solid transparent;border-left:7px solid transparent;content:"";display:block;left:50%;margin-left:-7px;position:absolute}.jsoneditor-text-errors tr.jump-to-line:hover{text-decoration:underline;cursor:pointer}.jsoneditor-schema-error:focus .jsoneditor-popover,.jsoneditor-schema-error:hover .jsoneditor-popover{display:block;animation:fade-in .3s linear 1,move-up .3s linear 1}@keyframes fade-in{from{opacity:0}to{opacity:1}}.jsoneditor .jsoneditor-validation-errors-container{max-height:130px;overflow-y:auto}.jsoneditor .jsoneditor-validation-errors{width:100%;overflow:hidden}.jsoneditor .jsoneditor-additional-errors{position:absolute;margin:auto;bottom:31px;left:calc(50% - 92px);color:grey;background-color:#ebebeb;padding:7px 15px;border-radius:8px}.jsoneditor .jsoneditor-additional-errors.visible{visibility:visible;opacity:1;transition:opacity 2s linear}.jsoneditor .jsoneditor-additional-errors.hidden{visibility:hidden;opacity:0;transition:visibility 0s 2s,opacity 2s linear}.jsoneditor .jsoneditor-text-errors{width:100%;border-collapse:collapse;border-top:1px solid #ffc700}.jsoneditor .jsoneditor-text-errors td{padding:3px 6px;vertical-align:middle}.jsoneditor .jsoneditor-text-errors td pre{margin:0;white-space:normal}.jsoneditor .jsoneditor-text-errors tr{background-color:#ffffab}.jsoneditor .jsoneditor-text-errors tr.parse-error{background-color:#ee2e2e70}.jsoneditor-text-errors .jsoneditor-schema-error{border:none;width:24px;height:24px;padding:0;margin:0 4px 0 0;cursor:pointer}.jsoneditor-text-errors tr .jsoneditor-schema-error{background:url(img/jsoneditor-icons.svg) -168px -48px}.jsoneditor-text-errors tr.parse-error .jsoneditor-schema-error{background:url(img/jsoneditor-icons.svg) -25px 0}.fadein{-webkit-animation:fadein .3s;animation:fadein .3s;-moz-animation:fadein .3s;-o-animation:fadein .3s}@keyframes fadein{0%{opacity:0}100%{opacity:1}}.jsoneditor-contextmenu-root{position:relative;width:0;height:0}.jsoneditor-contextmenu{position:absolute;box-sizing:content-box;z-index:99}.jsoneditor-contextmenu .jsoneditor-menu{position:relative;left:0;top:0;width:128px;height:auto;background:#fff;border:1px solid #d3d3d3;box-shadow:2px 2px 12px rgba(128,128,128,.3);list-style:none;margin:0;padding:0}.jsoneditor-contextmenu .jsoneditor-menu button{position:relative;padding:0 4px 0 0;margin:0;width:128px;height:auto;border:none;cursor:pointer;color:#4d4d4d;background:0 0;font-size:10pt;font-family:arial,sans-serif;box-sizing:border-box;text-align:left}.jsoneditor-contextmenu .jsoneditor-menu button::-moz-focus-inner{padding:0;border:0}.jsoneditor-contextmenu .jsoneditor-menu button.jsoneditor-default{width:96px}.jsoneditor-contextmenu .jsoneditor-menu button.jsoneditor-expand{float:right;width:32px;height:24px;border-left:1px solid #e5e5e5}.jsoneditor-contextmenu .jsoneditor-menu li{overflow:hidden}.jsoneditor-contextmenu .jsoneditor-menu li ul{display:none;position:relative;left:-10px;top:0;border:none;box-shadow:inset 0 0 10px rgba(128,128,128,.5);padding:0 10px;-webkit-transition:all .3s ease-out;-moz-transition:all .3s ease-out;-o-transition:all .3s ease-out;transition:all .3s ease-out}.jsoneditor-contextmenu .jsoneditor-menu li ul .jsoneditor-icon{margin-left:24px}.jsoneditor-contextmenu .jsoneditor-menu li ul li button{padding-left:24px;animation:all ease-in-out 1s}.jsoneditor-contextmenu .jsoneditor-menu li button .jsoneditor-expand{position:absolute;top:0;right:0;width:24px;height:24px;padding:0;margin:0 4px 0 0;background:url(img/jsoneditor-icons.svg) 0 -72px}.jsoneditor-contextmenu .jsoneditor-icon{position:absolute;top:0;left:0;width:24px;height:24px;border:none;padding:0;margin:0;background-image:url(img/jsoneditor-icons.svg)}.jsoneditor-contextmenu .jsoneditor-text{padding:4px 0 4px 24px;word-wrap:break-word}.jsoneditor-contextmenu .jsoneditor-text.jsoneditor-right-margin{padding-right:24px}.jsoneditor-contextmenu .jsoneditor-separator{height:0;border-top:1px solid #e5e5e5;padding-top:5px;margin-top:5px}.jsoneditor-contextmenu button.jsoneditor-remove .jsoneditor-icon{background-position:-24px 0}.jsoneditor-contextmenu button.jsoneditor-append .jsoneditor-icon{background-position:0 0}.jsoneditor-contextmenu button.jsoneditor-insert .jsoneditor-icon{background-position:0 0}.jsoneditor-contextmenu button.jsoneditor-duplicate .jsoneditor-icon{background-position:-48px 0}.jsoneditor-contextmenu button.jsoneditor-sort-asc .jsoneditor-icon{background-position:-168px 0}.jsoneditor-contextmenu button.jsoneditor-sort-desc .jsoneditor-icon{background-position:-192px 0}.jsoneditor-contextmenu button.jsoneditor-transform .jsoneditor-icon{background-position:-216px 0}.jsoneditor-contextmenu button.jsoneditor-extract .jsoneditor-icon{background-position:0 -24px}.jsoneditor-contextmenu button.jsoneditor-type-string .jsoneditor-icon{background-position:-144px 0}.jsoneditor-contextmenu button.jsoneditor-type-auto .jsoneditor-icon{background-position:-120px 0}.jsoneditor-contextmenu button.jsoneditor-type-object .jsoneditor-icon{background-position:-72px 0}.jsoneditor-contextmenu button.jsoneditor-type-array .jsoneditor-icon{background-position:-96px 0}.jsoneditor-contextmenu button.jsoneditor-type-modes .jsoneditor-icon{background-image:none;width:6px}.jsoneditor-contextmenu li,.jsoneditor-contextmenu ul{box-sizing:content-box;position:relative}.jsoneditor-contextmenu .jsoneditor-menu button:focus,.jsoneditor-contextmenu .jsoneditor-menu button:hover{color:#1a1a1a;background-color:#f5f5f5;outline:0}.jsoneditor-contextmenu .jsoneditor-menu li button.jsoneditor-selected,.jsoneditor-contextmenu .jsoneditor-menu li button.jsoneditor-selected:focus,.jsoneditor-contextmenu .jsoneditor-menu li button.jsoneditor-selected:hover{color:#fff;background-color:#ee422e}.jsoneditor-contextmenu .jsoneditor-menu li ul li button:focus,.jsoneditor-contextmenu .jsoneditor-menu li ul li button:hover{background-color:#f5f5f5}.jsoneditor-modal{max-width:95%;border-radius:2px!important;padding:45px 15px 15px 15px!important;box-shadow:2px 2px 12px rgba(128,128,128,.3);color:#4d4d4d;line-height:1.3em}.jsoneditor-modal.jsoneditor-modal-transform{width:600px!important}.jsoneditor-modal .pico-modal-header{position:absolute;box-sizing:border-box;top:0;left:0;width:100%;padding:0 10px;height:30px;line-height:30px;font-family:arial,sans-serif;font-size:11pt;background:#3883fa;color:#fff}.jsoneditor-modal table{width:100%}.jsoneditor-modal table td{padding:3px 0}.jsoneditor-modal table td.jsoneditor-modal-input{text-align:right;padding-right:0;white-space:nowrap}.jsoneditor-modal table td.jsoneditor-modal-actions{padding-top:15px}.jsoneditor-modal table th{vertical-align:middle}.jsoneditor-modal p:first-child{margin-top:0}.jsoneditor-modal a{color:#3883fa}.jsoneditor-modal .jsoneditor-jmespath-block{margin-bottom:10px}.jsoneditor-modal .pico-close{background:0 0!important;font-size:24px!important;top:7px!important;right:7px!important;color:#fff}.jsoneditor-modal input{padding:4px}.jsoneditor-modal input[type=text]{cursor:inherit}.jsoneditor-modal input[disabled]{background:#d3d3d3;color:grey}.jsoneditor-modal .jsoneditor-select-wrapper{position:relative;display:inline-block}.jsoneditor-modal .jsoneditor-select-wrapper:after{content:"";width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #666;position:absolute;right:8px;top:14px;pointer-events:none}.jsoneditor-modal select{padding:3px 24px 3px 10px;min-width:180px;max-width:350px;-webkit-appearance:none;-moz-appearance:none;appearance:none;text-indent:0;text-overflow:"";font-size:10pt;line-height:1.5em}.jsoneditor-modal select::-ms-expand{display:none}.jsoneditor-modal .jsoneditor-button-group input{padding:4px 10px;margin:0;border-radius:0;border-left-style:none}.jsoneditor-modal .jsoneditor-button-group input.jsoneditor-button-first{border-top-left-radius:3px;border-bottom-left-radius:3px;border-left-style:solid}.jsoneditor-modal .jsoneditor-button-group input.jsoneditor-button-last{border-top-right-radius:3px;border-bottom-right-radius:3px}.jsoneditor-modal .jsoneditor-transform-preview{background:#f5f5f5;height:200px}.jsoneditor-modal .jsoneditor-transform-preview.jsoneditor-error{color:#ee422e}.jsoneditor-modal .jsoneditor-jmespath-wizard{line-height:1.2em;width:100%;padding:0;border-radius:3px}.jsoneditor-modal .jsoneditor-jmespath-label{font-weight:700;color:#1e90ff;margin-top:20px;margin-bottom:5px}.jsoneditor-modal .jsoneditor-jmespath-wizard-table{width:100%}.jsoneditor-modal .jsoneditor-jmespath-wizard-label{font-style:italic;margin:4px 0 2px 0}.jsoneditor-modal .jsoneditor-inline{position:relative;display:inline-block;width:100%;padding-top:2px;padding-bottom:2px}.jsoneditor-modal .jsoneditor-inline:not(:last-child){padding-right:2px}.jsoneditor-modal .jsoneditor-jmespath-filter{display:flex;flex-wrap:wrap}.jsoneditor-modal .jsoneditor-jmespath-filter-field{width:180px}.jsoneditor-modal .jsoneditor-jmespath-filter-relation{width:100px}.jsoneditor-modal .jsoneditor-jmespath-filter-value{min-width:180px;flex:1}.jsoneditor-modal .jsoneditor-jmespath-sort-field{width:170px}.jsoneditor-modal .jsoneditor-jmespath-sort-order{width:150px}.jsoneditor-modal .jsoneditor-jmespath-select-fields{width:100%}.jsoneditor-modal .selectr-selected{border-color:#d3d3d3;padding:4px 28px 4px 8px}.jsoneditor-modal .selectr-selected .selectr-tag{background-color:#3883fa;border-radius:5px}.jsoneditor-modal table td,.jsoneditor-modal table th{text-align:left;vertical-align:top;font-weight:400;color:#4d4d4d;border-spacing:0;border-collapse:collapse}.jsoneditor-modal #query,.jsoneditor-modal input,.jsoneditor-modal select,.jsoneditor-modal textarea{background:#fff;border:1px solid #d3d3d3;color:#4d4d4d;border-radius:3px;padding:4px}.jsoneditor-modal,.jsoneditor-modal #query,.jsoneditor-modal input,.jsoneditor-modal option,.jsoneditor-modal select,.jsoneditor-modal table td,.jsoneditor-modal table th,.jsoneditor-modal textarea{font-size:10.5pt;font-family:arial,sans-serif}.jsoneditor-modal #query,.jsoneditor-modal .jsoneditor-transform-preview{font-family:"dejavu sans mono","droid sans mono",consolas,monaco,"lucida console","courier new",courier,monospace,sans-serif;font-size:10pt;width:100%;box-sizing:border-box}.jsoneditor-modal input[type=button],.jsoneditor-modal input[type=submit]{background:#f5f5f5;padding:4px 20px}.jsoneditor-modal input,.jsoneditor-modal select{cursor:pointer}.jsoneditor-modal .jsoneditor-button-group.jsoneditor-button-group-value-asc input.jsoneditor-button-asc,.jsoneditor-modal .jsoneditor-button-group.jsoneditor-button-group-value-desc input.jsoneditor-button-desc{background:#3883fa;border-color:#3883fa;color:#fff}.jsoneditor-menu{width:100%;height:35px;padding:2px;margin:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;color:#fff;background-color:#3883fa;border-bottom:1px solid #3883fa}.jsoneditor-menu>.jsoneditor-modes>button,.jsoneditor-menu>button{width:26px;height:26px;margin:2px;padding:0;border-radius:2px;border:1px solid transparent;background:transparent url(img/jsoneditor-icons.svg);color:#fff;opacity:.8;font-family:arial,sans-serif;font-size:10pt;float:left}.jsoneditor-menu>.jsoneditor-modes>button:hover,.jsoneditor-menu>button:hover{background-color:rgba(255,255,255,.2);border:1px solid rgba(255,255,255,.4)}.jsoneditor-menu>.jsoneditor-modes>button:active,.jsoneditor-menu>.jsoneditor-modes>button:focus,.jsoneditor-menu>button:active,.jsoneditor-menu>button:focus{background-color:rgba(255,255,255,.3)}.jsoneditor-menu>.jsoneditor-modes>button:disabled,.jsoneditor-menu>button:disabled{opacity:.5;background-color:transparent;border:none}.jsoneditor-menu>button.jsoneditor-collapse-all{background-position:0 -96px}.jsoneditor-menu>button.jsoneditor-expand-all{background-position:0 -120px}.jsoneditor-menu>button.jsoneditor-sort{background-position:-120px -96px}.jsoneditor-menu>button.jsoneditor-transform{background-position:-144px -96px}.jsoneditor.jsoneditor-mode-form>.jsoneditor-menu>button.jsoneditor-sort,.jsoneditor.jsoneditor-mode-form>.jsoneditor-menu>button.jsoneditor-transform,.jsoneditor.jsoneditor-mode-view>.jsoneditor-menu>button.jsoneditor-sort,.jsoneditor.jsoneditor-mode-view>.jsoneditor-menu>button.jsoneditor-transform{display:none}.jsoneditor-menu>button.jsoneditor-undo{background-position:-24px -96px}.jsoneditor-menu>button.jsoneditor-undo:disabled{background-position:-24px -120px}.jsoneditor-menu>button.jsoneditor-redo{background-position:-48px -96px}.jsoneditor-menu>button.jsoneditor-redo:disabled{background-position:-48px -120px}.jsoneditor-menu>button.jsoneditor-compact{background-position:-72px -96px}.jsoneditor-menu>button.jsoneditor-format{background-position:-72px -120px}.jsoneditor-menu>button.jsoneditor-repair{background-position:-96px -96px}.jsoneditor-menu>.jsoneditor-modes{display:inline-block;float:left}.jsoneditor-menu>.jsoneditor-modes>button{background-image:none;width:auto;padding-left:6px;padding-right:6px}.jsoneditor-menu>.jsoneditor-modes>button.jsoneditor-separator,.jsoneditor-menu>button.jsoneditor-separator{margin-left:10px}.jsoneditor-menu a{font-family:arial,sans-serif;font-size:10pt;color:#fff;opacity:.8;vertical-align:middle}.jsoneditor-menu a:hover{opacity:1}.jsoneditor-menu a.jsoneditor-poweredBy{font-size:8pt;position:absolute;right:0;top:0;padding:10px}.jsoneditor-search{font-family:arial,sans-serif;position:absolute;right:4px;top:4px;border-collapse:collapse;border-spacing:0;display:flex}.jsoneditor-search input{color:#1a1a1a;width:120px;border:none;outline:0;margin:1px;line-height:20px}.jsoneditor-search button{width:16px;height:24px;padding:0;margin:0;border:none;background:url(img/jsoneditor-icons.svg);vertical-align:top}.jsoneditor-search button:hover{background-color:transparent}.jsoneditor-search button.jsoneditor-refresh{width:18px;background-position:-99px -73px}.jsoneditor-search button.jsoneditor-next{cursor:pointer;background-position:-124px -73px}.jsoneditor-search button.jsoneditor-next:hover{background-position:-124px -49px}.jsoneditor-search button.jsoneditor-previous{cursor:pointer;background-position:-148px -73px;margin-right:2px}.jsoneditor-search button.jsoneditor-previous:hover{background-position:-148px -49px}.jsoneditor-results{font-family:arial,sans-serif;color:#fff;padding-right:5px;line-height:26px}.jsoneditor-frame{border:1px solid transparent;background-color:#fff;padding:0 2px;margin:0}.jsoneditor .autocomplete.dropdown{position:absolute;background:#fff;box-shadow:2px 2px 12px rgba(128,128,128,.3);border:1px solid #d3d3d3;z-index:100;overflow-x:hidden;overflow-y:auto;cursor:default;margin:0;padding:5px;text-align:left;outline:0;font-family:"dejavu sans mono","droid sans mono",consolas,monaco,"lucida console","courier new",courier,monospace,sans-serif;font-size:10pt}.jsoneditor .autocomplete.dropdown .item{color:#333}.jsoneditor .autocomplete.dropdown .item.hover{background-color:#ddd}.jsoneditor .autocomplete.hint{color:#aaa;top:4px;left:4px}.jsoneditor-treepath{padding:0 5px;overflow:hidden;white-space:nowrap;outline:0}.jsoneditor-treepath.show-all{word-wrap:break-word;white-space:normal;position:absolute;background-color:#ebebeb;z-index:999;box-shadow:2px 2px 12px rgba(128,128,128,.3)}.jsoneditor-treepath.show-all span.jsoneditor-treepath-show-all-btn{display:none}.jsoneditor-treepath div.jsoneditor-contextmenu-root{position:absolute;left:0}.jsoneditor-treepath .jsoneditor-treepath-show-all-btn{position:absolute;background-color:#ebebeb;left:0;height:20px;padding:0 3px;cursor:pointer}.jsoneditor-treepath .jsoneditor-treepath-element{margin:1px;font-family:arial,sans-serif;font-size:10pt}.jsoneditor-treepath .jsoneditor-treepath-seperator{margin:2px;font-size:9pt;font-family:arial,sans-serif}.jsoneditor-treepath span.jsoneditor-treepath-element:hover,.jsoneditor-treepath span.jsoneditor-treepath-seperator:hover{cursor:pointer;text-decoration:underline}.jsoneditor-statusbar{line-height:26px;height:26px;color:grey;background-color:#ebebeb;border-top:1px solid #d3d3d3;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;font-size:10pt}.jsoneditor-statusbar>.jsoneditor-curserinfo-val{margin-right:12px}.jsoneditor-statusbar>.jsoneditor-curserinfo-count{margin-left:4px}.jsoneditor-statusbar>.jsoneditor-validation-error-icon{float:right;width:24px;height:24px;padding:0;margin-top:1px;background:url(img/jsoneditor-icons.svg) -168px -48px;cursor:pointer}.jsoneditor-statusbar>.jsoneditor-validation-error-count{float:right;margin:0 4px 0 0;cursor:pointer}.jsoneditor-statusbar>.jsoneditor-parse-error-icon{float:right;width:24px;height:24px;padding:0;margin:1px;background:url(img/jsoneditor-icons.svg) -25px 0}.jsoneditor-statusbar .jsoneditor-array-info a{color:inherit}div.jsoneditor-statusbar>.jsoneditor-curserinfo-label,div.jsoneditor-statusbar>.jsoneditor-size-info{margin:0 4px}.jsoneditor-navigation-bar{width:100%;height:26px;line-height:26px;padding:0;margin:0;border-bottom:1px solid #d3d3d3;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;color:grey;background-color:#ebebeb;overflow:hidden;font-family:arial,sans-serif;font-size:10pt}/*! + * Selectr 2.4.0 + * https://github.com/Mobius1/Selectr + * + * Released under the MIT license + */.selectr-container{position:relative}.selectr-container li{list-style:none}.selectr-hidden{position:absolute;overflow:hidden;clip:rect(0,0,0,0);width:1px;height:1px;margin:-1px;padding:0;border:0 none}.selectr-visible{position:absolute;left:0;top:0;width:100%;height:100%;opacity:0;z-index:11}.selectr-desktop.multiple .selectr-visible{display:none}.selectr-desktop.multiple.native-open .selectr-visible{top:100%;min-height:200px!important;height:auto;opacity:1;display:block}.selectr-container.multiple.selectr-mobile .selectr-selected{z-index:0}.selectr-selected{position:relative;z-index:1;box-sizing:border-box;width:100%;padding:7px 28px 7px 14px;cursor:pointer;border:1px solid #999;border-radius:3px;background-color:#fff}.selectr-selected::before{position:absolute;top:50%;right:10px;width:0;height:0;content:'';-o-transform:rotate(0) translate3d(0,-50%,0);-ms-transform:rotate(0) translate3d(0,-50%,0);-moz-transform:rotate(0) translate3d(0,-50%,0);-webkit-transform:rotate(0) translate3d(0,-50%,0);transform:rotate(0) translate3d(0,-50%,0);border-width:4px 4px 0 4px;border-style:solid;border-color:#6c7a86 transparent transparent}.selectr-container.native-open .selectr-selected::before,.selectr-container.open .selectr-selected::before{border-width:0 4px 4px 4px;border-style:solid;border-color:transparent transparent #6c7a86}.selectr-label{display:none;overflow:hidden;width:100%;white-space:nowrap;text-overflow:ellipsis}.selectr-placeholder{color:#6c7a86}.selectr-tags{margin:0;padding:0;white-space:normal}.has-selected .selectr-tags{margin:0 0 -2px}.selectr-tag{list-style:none;position:relative;float:left;padding:2px 25px 2px 8px;margin:0 2px 2px 0;cursor:default;color:#fff;border:medium none;border-radius:10px;background:#acb7bf none repeat scroll 0 0}.selectr-container.multiple.has-selected .selectr-selected{padding:5px 28px 5px 5px}.selectr-options-container{position:absolute;z-index:10000;top:calc(100% - 1px);left:0;display:none;box-sizing:border-box;width:100%;border-width:0 1px 1px;border-style:solid;border-color:transparent #999 #999;border-radius:0 0 3px 3px;background-color:#fff}.selectr-container.open .selectr-options-container{display:block}.selectr-input-container{position:relative;display:none}.selectr-clear,.selectr-input-clear,.selectr-tag-remove{position:absolute;top:50%;right:22px;width:20px;height:20px;padding:0;cursor:pointer;-o-transform:translate3d(0,-50%,0);-ms-transform:translate3d(0,-50%,0);-moz-transform:translate3d(0,-50%,0);-webkit-transform:translate3d(0,-50%,0);transform:translate3d(0,-50%,0);border:medium none;background-color:transparent;z-index:11}.selectr-clear,.selectr-input-clear{display:none}.selectr-container.has-selected .selectr-clear,.selectr-input-container.active .selectr-input-clear{display:block}.selectr-selected .selectr-tag-remove{right:2px}.selectr-clear::after,.selectr-clear::before,.selectr-input-clear::after,.selectr-input-clear::before,.selectr-tag-remove::after,.selectr-tag-remove::before{position:absolute;top:5px;left:9px;width:2px;height:10px;content:' ';background-color:#6c7a86}.selectr-tag-remove::after,.selectr-tag-remove::before{top:4px;width:3px;height:12px;background-color:#fff}.selectr-clear:before,.selectr-input-clear::before,.selectr-tag-remove::before{-o-transform:rotate(45deg);-ms-transform:rotate(45deg);-moz-transform:rotate(45deg);-webkit-transform:rotate(45deg);transform:rotate(45deg)}.selectr-clear:after,.selectr-input-clear::after,.selectr-tag-remove::after{-o-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.selectr-input-container.active,.selectr-input-container.active .selectr-clear{display:block}.selectr-input{top:5px;left:5px;box-sizing:border-box;width:calc(100% - 30px);margin:10px 15px;padding:7px 30px 7px 9px;border:1px solid #999;border-radius:3px}.selectr-notice{display:none;box-sizing:border-box;width:100%;padding:8px 16px;border-top:1px solid #999;border-radius:0 0 3px 3px;background-color:#fff}.selectr-container.notice .selectr-notice{display:block}.selectr-container.notice .selectr-selected{border-radius:3px 3px 0 0}.selectr-options{position:relative;top:calc(100% + 2px);display:none;overflow-x:auto;overflow-y:scroll;max-height:200px;margin:0;padding:0}.selectr-container.notice .selectr-options-container,.selectr-container.open .selectr-input-container,.selectr-container.open .selectr-options{display:block}.selectr-option{position:relative;display:block;padding:5px 20px;list-style:outside none none;cursor:pointer;font-weight:400}.selectr-options.optgroups>.selectr-option{padding-left:25px}.selectr-optgroup{font-weight:700;padding:0}.selectr-optgroup--label{font-weight:700;margin-top:10px;padding:5px 15px}.selectr-match{text-decoration:underline}.selectr-option.selected{background-color:#ddd}.selectr-option.active{color:#fff;background-color:#5897fb}.selectr-option.disabled{opacity:.4}.selectr-option.excluded{display:none}.selectr-container.open .selectr-selected{border-color:#999 #999 transparent #999;border-radius:3px 3px 0 0}.selectr-container.open .selectr-selected::after{-o-transform:rotate(180deg) translate3d(0,50%,0);-ms-transform:rotate(180deg) translate3d(0,50%,0);-moz-transform:rotate(180deg) translate3d(0,50%,0);-webkit-transform:rotate(180deg) translate3d(0,50%,0);transform:rotate(180deg) translate3d(0,50%,0)}.selectr-disabled{opacity:.6}.has-selected .selectr-placeholder,.selectr-empty{display:none}.has-selected .selectr-label{display:block}.taggable .selectr-selected{padding:4px 28px 4px 4px}.taggable .selectr-selected::after{display:table;content:" ";clear:both}.taggable .selectr-label{width:auto}.taggable .selectr-tags{float:left;display:block}.taggable .selectr-placeholder{display:none}.input-tag{float:left;min-width:90px;width:auto}.selectr-tag-input{border:medium none;padding:3px 10px;width:100%;font-family:inherit;font-weight:inherit;font-size:inherit}.selectr-input-container.loading::after{position:absolute;top:50%;right:20px;width:20px;height:20px;content:'';-o-transform:translate3d(0,-50%,0);-ms-transform:translate3d(0,-50%,0);-moz-transform:translate3d(0,-50%,0);-webkit-transform:translate3d(0,-50%,0);transform:translate3d(0,-50%,0);-o-transform-origin:50% 0 0;-ms-transform-origin:50% 0 0;-moz-transform-origin:50% 0 0;-webkit-transform-origin:50% 0 0;transform-origin:50% 0 0;-moz-animation:.5s linear 0s normal forwards infinite running spin;-webkit-animation:.5s linear 0s normal forwards infinite running spin;animation:.5s linear 0s normal forwards infinite running spin;border-width:3px;border-style:solid;border-color:#aaa #ddd #ddd;border-radius:50%}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0) translate3d(0,-50%,0);transform:rotate(0) translate3d(0,-50%,0)}100%{-webkit-transform:rotate(360deg) translate3d(0,-50%,0);transform:rotate(360deg) translate3d(0,-50%,0)}}@keyframes spin{0%{-webkit-transform:rotate(0) translate3d(0,-50%,0);transform:rotate(0) translate3d(0,-50%,0)}100%{-webkit-transform:rotate(360deg) translate3d(0,-50%,0);transform:rotate(360deg) translate3d(0,-50%,0)}}.selectr-container.open.inverted .selectr-selected{border-color:transparent #999 #999;border-radius:0 0 3px 3px}.selectr-container.inverted .selectr-options-container{border-width:1px 1px 0;border-color:#999 #999 transparent;border-radius:3px 3px 0 0;background-color:#fff}.selectr-container.inverted .selectr-options-container{top:auto;bottom:calc(100% - 1px)}.selectr-container ::-webkit-input-placeholder{color:#6c7a86;opacity:1}.selectr-container ::-moz-placeholder{color:#6c7a86;opacity:1}.selectr-container :-ms-input-placeholder{color:#6c7a86;opacity:1}.selectr-container ::placeholder{color:#6c7a86;opacity:1} \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html index 2455997a..f99f2803 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/web/index.html +++ b/dataforge-vis-spatial-gdml/src/jsMain/web/index.html @@ -11,6 +11,7 @@ integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> + diff --git a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt index 37e45cda..019a8856 100644 --- a/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt +++ b/dataforge-vis-spatial-gdml/src/jvmMain/kotlin/hep/dataforge/vis/spatial/gdml/testMain.kt @@ -15,30 +15,17 @@ fun main() { val xml = GDML.format.parse(GDML.serializer(), xmlReader) val visual = xml.toVisual { lUnit = LUnit.CM - volumeAction = { volume -> - when { - volume.name.startsWith("ecal01lay") -> GDMLTransformer.Action.REJECT - volume.name.startsWith("ecal") -> GDMLTransformer.Action.CACHE - volume.name.startsWith("UPBL") -> GDMLTransformer.Action.REJECT - volume.name.startsWith("USCL") -> GDMLTransformer.Action.REJECT - volume.name.startsWith("U") -> GDMLTransformer.Action.CACHE - volume.name.startsWith("VPBL") -> GDMLTransformer.Action.REJECT - volume.name.startsWith("VSCL") -> GDMLTransformer.Action.REJECT - volume.name.startsWith("V") -> GDMLTransformer.Action.CACHE - else -> GDMLTransformer.Action.ACCEPT - } - } solidConfiguration = { parent, solid -> - if (parent.physVolumes.isNotEmpty()) { - opacity = 0.3 - } - if (solid.name.startsWith("Coil") + if (parent.physVolumes.isNotEmpty() + || solid.name.startsWith("Coil") || solid.name.startsWith("Yoke") || solid.name.startsWith("Magnet") || solid.name.startsWith("Pole") ) { - opacity = 0.3 + useStyle("opaque") { + opacity = 0.3 + } } } diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index 1e2f96b0..51c7108b 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -33,6 +33,7 @@ kotlin { implementation(npm("element-resize-event")) implementation(npm("inspire-tree","6.0.1")) implementation(npm("inspire-tree-dom","4.0.6")) + implementation(npm("jsoneditor")) } } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 18faaee2..5d5b0d2a 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -4,18 +4,16 @@ package hep.dataforge.vis.spatial import hep.dataforge.io.ConfigSerializer import hep.dataforge.io.NameSerializer -import hep.dataforge.meta.Config -import hep.dataforge.meta.Meta -import hep.dataforge.meta.MetaBuilder -import hep.dataforge.meta.MetaItem +import hep.dataforge.meta.* import hep.dataforge.names.Name import hep.dataforge.names.NameToken import hep.dataforge.names.asName +import hep.dataforge.names.plus import hep.dataforge.vis.common.AbstractVisualObject +import hep.dataforge.vis.common.MutableVisualGroup import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.common.VisualObject import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient import kotlinx.serialization.UseSerializers /** @@ -34,21 +32,22 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua /** * Recursively search for defined template in the parent */ - val template: VisualObject3D + val prototype: VisualObject3D get() = (parent as? VisualGroup3D)?.getTemplate(templateName) ?: error("Template with name $templateName not found in $parent") - override fun getStyle(name: Name): Meta? = null + override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name) override fun setStyle(name: Name, meta: Meta) { + (parent as VisualGroup?)?.setStyle(name, meta) //do nothing } override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { - super.getProperty(name, false) ?: template.getProperty(name, false) ?: parent?.getProperty(name, inherit) + super.getProperty(name, false) ?: prototype.getProperty(name, false) ?: parent?.getProperty(name, inherit) } else { - super.getProperty(name, false) ?: template.getProperty(name, false) + super.getProperty(name, false) ?: prototype.getProperty(name, false) } } @@ -58,49 +57,56 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua } override val children: Map - get() = (template as? VisualGroup)?.children?.mapValues { + get() = (prototype as? MutableVisualGroup)?.children?.mapValues { ProxyChild(it.key.asName()) } ?: emptyMap() - private data class ProxyChangeListeners(val owner: Any?, val callback: (Name, VisualObject?) -> Unit) - - @Transient - private val listeners = HashSet() - - override fun onChildrenChange(owner: Any?, action: (Name, VisualObject?) -> Unit) { - listeners.add(ProxyChangeListeners(owner, action)) - } - - override fun removeChildrenChangeListener(owner: Any?) { - listeners.removeAll { it.owner == owner } - } - - override fun set(name: Name, child: VisualObject?) { - error("Content change not supported for proxy") - } - private val propertyCache: HashMap = HashMap() - private fun Config.attachListener(obj: VisualObject) { - onChange(this@Proxy) { name, before, after -> - listeners.forEach { listener -> - listener.callback(name, obj) - } - } - } + inner class ProxyChild(val name: Name) : AbstractVisualObject(), VisualGroup { + + override val children: Map + get() = ((prototype as? MutableVisualGroup)?.get(name) as? MutableVisualGroup) + ?.children + ?.mapValues { (key, _) -> + ProxyChild( + name + key.asName() + ) + } + ?: emptyMap() + + override fun getStyle(name: Name): Meta? = this@Proxy.getStyle(name) + + override fun setStyle(name: Name, meta: Meta) { + this@Proxy.setStyle(name, meta) + } + + val prototype: VisualObject + get() = (this@Proxy.prototype as? VisualGroup)?.get(name) + ?: error("Prototype with name $name not found in ${this@Proxy}") - inner class ProxyChild(val name: Name) : AbstractVisualObject() { override var properties: Config? get() = propertyCache[name] set(value) { if (value == null) { - propertyCache.remove(name)?.removeListener(this@Proxy) + propertyCache.remove(name) } else { - propertyCache[name] = value.apply { - attachListener(this@ProxyChild) - } + propertyCache[name] = value } } + + override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { + return if (inherit) { + properties?.get(name) + ?: parent?.getProperty(name, inherit) + ?: actualStyles[name] + ?: prototype.getProperty(name, inherit) + } else { + properties?.get(name) + ?: actualStyles[name] + ?: prototype.getProperty(name, inherit) + } + } } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt index 2d5089e8..02886ed9 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Visual3DPlugin.kt @@ -37,10 +37,10 @@ class Visual3DPlugin(meta: Meta) : AbstractPlugin(meta) { contextual(Point2DSerializer) contextual(NameSerializer) contextual(NameTokenSerializer) - contextual(MetaSerializer) + contextual(Meta::class, MetaSerializer) contextual(ConfigSerializer) - polymorphic(VisualObject::class,VisualObject3D::class) { + polymorphic(VisualObject::class, VisualObject3D::class) { VisualGroup3D::class with VisualGroup3D.serializer() Proxy::class with Proxy.serializer() Composite::class with Composite.serializer() diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index d0057f0c..e2ccbd25 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -2,27 +2,29 @@ Point3DSerializer::class, ConfigSerializer::class, NameTokenSerializer::class, - NameSerializer::class + NameSerializer::class, + MetaSerializer::class ) package hep.dataforge.vis.spatial import hep.dataforge.io.ConfigSerializer +import hep.dataforge.io.MetaSerializer import hep.dataforge.io.NameSerializer import hep.dataforge.meta.Config import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.set -import hep.dataforge.names.* +import hep.dataforge.names.Name +import hep.dataforge.names.NameToken +import hep.dataforge.names.asName +import hep.dataforge.names.isEmpty import hep.dataforge.vis.common.AbstractVisualGroup -import hep.dataforge.vis.common.AbstractVisualObject -import hep.dataforge.vis.common.VisualGroup +import hep.dataforge.vis.common.MutableVisualGroup import hep.dataforge.vis.common.VisualObject import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers -import kotlin.collections.component1 -import kotlin.collections.component2 import kotlin.collections.set @Serializable @@ -37,32 +39,8 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { } //FIXME to be lifted to AbstractVisualGroup after https://github.com/Kotlin/kotlinx.serialization/issues/378 is fixed - public override var properties: Config? = null - - private val styles = HashMap() - - override fun getStyle(name: Name): Meta? = styles[name] - - override fun setStyle(name: Name, meta: Meta) { - fun VisualObject.applyStyle(name: Name, meta: Meta) { - if (style.contains(name.toString())) { - //full update - //TODO do a fine grained update - if(this is AbstractVisualObject){ - styleChanged() - } else { - propertyChanged(EmptyName) - } - } - if (this is VisualGroup) { - this.children.forEach { (_, child) -> - child.applyStyle(name, meta) - } - } - } - styles[name] = meta - applyStyle(name, meta) - } + override var properties: Config? = null + override val styles = HashMap() override var position: Point3D? = null override var rotation: Point3D? = null @@ -87,10 +65,10 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { childrenChanged(token.asName(), child) } - /** - * TODO add special static group to hold statics without propagation - */ - override fun addStatic(child: VisualObject) = setChild(NameToken("@static(${child.hashCode()})"), child) +// /** +// * TODO add special static group to hold statics without propagation +// */ +// override fun addStatic(child: VisualObject) = setChild(NameToken("@static(${child.hashCode()})"), child) override fun createGroup(name: Name): VisualGroup3D { return when { @@ -125,10 +103,10 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { /** * A fix for serialization bug that writes all proper parents inside the tree after deserialization */ -fun VisualGroup.attachChildren() { +fun MutableVisualGroup.attachChildren() { this.children.values.forEach { it.parent = this - (it as? VisualGroup)?.attachChildren() + (it as? MutableVisualGroup)?.attachChildren() } if (this is VisualGroup3D) { templates?.apply { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index ed6acd9c..e2c78e34 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -9,9 +9,11 @@ import hep.dataforge.names.plus import hep.dataforge.output.Output import hep.dataforge.vis.common.Colors.rgbToString import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY +import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY import kotlinx.serialization.UseSerializers @@ -40,6 +42,9 @@ interface VisualObject3D : VisualObject { val DETAIL_KEY = "detail".asName() val LAYER_KEY = "layer".asName() + val COLOR_KEY = MATERIAL_KEY + "color" + val OPACITY_KEY = MATERIAL_KEY + "opacity" + val x = "x".asName() val y = "y".asName() val z = "z".asName() @@ -109,11 +114,9 @@ var VisualObject.material: Meta? set(value) = setProperty(MATERIAL_KEY, value) var VisualObject.opacity: Double - get() = material?.get("opacity").double ?: 1.0 + get() = getProperty(OPACITY_KEY).double ?: 1.0 set(value) { - material = (material?.builder() ?: MetaBuilder()).apply { - "opacity" to value - } + setProperty(OPACITY_KEY, value) } var VisualObject.visible: Boolean? @@ -125,15 +128,15 @@ var VisualObject.selected: Boolean? set(value) = setProperty(SELECTED_KEY, value) fun VisualObject.color(rgb: Int) { - material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgbToString(rgb) } + setProperty(COLOR_KEY, rgbToString(rgb)) } fun VisualObject.color(rgb: String) { - material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb } + setProperty(COLOR_KEY, rgb) } var VisualObject.color: String? - get() = material["color"].string + get() = getProperty(COLOR_KEY).string set(value) { if (value != null) { color(value) diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt index ad9ac987..45f8a9bb 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt @@ -20,7 +20,7 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { } override fun invoke(obj: Proxy): Object3D { - val template = obj.template + val template = obj.prototype val cachedObject = cache.getOrPut(template) { three.buildObject3D(template) } @@ -45,11 +45,6 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { } } - obj.onChildrenChange(this) { name, propertyHolder -> - val child = object3D.findChild(name) - (child as? Mesh)?.updateProperties(propertyHolder) - } - return object3D } } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt index 191e06ab..2d86b7f4 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt @@ -10,7 +10,6 @@ import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.getProperty import hep.dataforge.vis.spatial.Proxy -import hep.dataforge.vis.spatial.selected import hep.dataforge.vis.spatial.visible import org.w3c.dom.HTMLElement import kotlin.js.json @@ -40,7 +39,7 @@ fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { obj, name - fun generateNodeConfig(item: VisualObject, fullName: Name): NodeConfig { val title = item.getProperty("title").string ?: fullName.last()?.toString() ?: "root" val className = if (item is Proxy) { - item.template::class.toString() + item.prototype::class.toString() } else { item::class.toString() }.replace("class ", "") @@ -88,15 +87,15 @@ fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { obj, name - map[rootNode.id] = this rootNode.fillChildren(this, EmptyName) - inspireTree.on("node.selected") { node: TreeNode, isLoadEvent: Boolean -> - if (!isLoadEvent) { - map[node.id]?.selected = node.selected() - } - } - - inspireTree.on("node.deselect") { node: TreeNode -> - map[node.id]?.selected = node.selected() - } +// inspireTree.on("node.selected") { node: TreeNode, isLoadEvent: Boolean -> +// if (!isLoadEvent) { +// map[node.id]?.selected = node.selected() +// } +// } +// +// inspireTree.on("node.deselect") { node: TreeNode -> +// map[node.id]?.selected = node.selected() +// } inspireTree.on("node.checked") { node: TreeNode, isLoadEvent: Boolean -> if (!isLoadEvent) { diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsonEditor.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsonEditor.kt new file mode 100644 index 00000000..1e3abd3c --- /dev/null +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsonEditor.kt @@ -0,0 +1,185 @@ +@file:Suppress( + "INTERFACE_WITH_SUPERCLASS", + "OVERRIDING_FINAL_MEMBER", + "RETURN_TYPE_MISMATCH_ON_OVERRIDE", + "CONFLICTING_OVERLOADS", + "EXTERNAL_DELEGATION" +) + +package hep.dataforge.vis.spatial.tree + +import org.w3c.dom.HTMLElement + +external interface Node { + var field: String + var value: String? get() = definedExternally; set(value) = definedExternally + var path: dynamic +} + +external interface NodeName { + var path: Array + var type: dynamic /* 'object' | 'array' */ + var size: Number +} + +external interface ValidationError { + var path: dynamic + var message: String +} + +external interface Template { + var text: String + var title: String + var className: String? get() = definedExternally; set(value) = definedExternally + var field: String + var value: Any +} + +external interface `T$6` { + var startFrom: Number + var options: Array +} + +external interface AutoCompleteOptions { + var confirmKeys: Array? get() = definedExternally; set(value) = definedExternally + var caseSensitive: Boolean? get() = definedExternally; set(value) = definedExternally +// var getOptions: AutoCompleteOptionsGetter? get() = definedExternally; set(value) = definedExternally +} + +external interface SelectionPosition { + var row: Number + var column: Number +} + +external interface SerializableNode { + var value: Any + var path: dynamic +} + +external interface Color { + var rgba: Array + var hsla: Array + var rgbString: String + var rgbaString: String + var hslString: String + var hslaString: String + var hex: String +} + +//external interface `T$0` { +// var field: Boolean +// var value: Boolean +//} +// +//external interface `T$1` { +// @nativeGetter +// operator fun get(key: String): String? +// +// @nativeSetter +// operator fun set(key: String, value: String) +//} + +//external interface Languages { +// @nativeGetter +// operator fun get(lang: String): `T$1`? +// +// @nativeSetter +// operator fun set(lang: String, value: `T$1`) +//} + +external interface JSONEditorOptions { +// var ace: AceAjax.Ace? get() = definedExternally; set(value) = definedExternally +// var ajv: Ajv? get() = definedExternally; set(value) = definedExternally + var onChange: (() -> Unit)? get() = definedExternally; set(value) = definedExternally + var onChangeJSON: ((json: Any) -> Unit)? get() = definedExternally; set(value) = definedExternally + var onChangeText: ((jsonString: String) -> Unit)? get() = definedExternally; set(value) = definedExternally + var onEditable: ((node: Node) -> dynamic)? get() = definedExternally; set(value) = definedExternally + var onError: ((error: Error) -> Unit)? get() = definedExternally; set(value) = definedExternally + var onModeChange: ((newMode: dynamic /* 'tree' | 'view' | 'form' | 'code' | 'text' */, oldMode: dynamic /* 'tree' | 'view' | 'form' | 'code' | 'text' */) -> Unit)? get() = definedExternally; set(value) = definedExternally + var onNodeName: ((nodeName: NodeName) -> String?)? get() = definedExternally; set(value) = definedExternally + var onValidate: ((json: Any) -> dynamic)? get() = definedExternally; set(value) = definedExternally + var escapeUnicode: Boolean? get() = definedExternally; set(value) = definedExternally + var sortObjectKeys: Boolean? get() = definedExternally; set(value) = definedExternally + var history: Boolean? get() = definedExternally; set(value) = definedExternally + var mode: dynamic /* 'tree' | 'view' | 'form' | 'code' | 'text' */ + var modes: Array? get() = definedExternally; set(value) = definedExternally + var name: String? get() = definedExternally; set(value) = definedExternally + var schema: Any? get() = definedExternally; set(value) = definedExternally + var schemaRefs: Any? get() = definedExternally; set(value) = definedExternally + var search: Boolean? get() = definedExternally; set(value) = definedExternally + var indentation: Number? get() = definedExternally; set(value) = definedExternally + var theme: String? get() = definedExternally; set(value) = definedExternally + var templates: Array