From 589afaa9b8fb6a7535d85c9b12054a264a571433 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 18 Aug 2019 22:29:26 +0300 Subject: [PATCH] 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