diff --git a/.github/actions/get-pr-number/action.yml b/.github/actions/get-pr-number/action.yml index 94b999d1a75..23da26d09c3 100644 --- a/.github/actions/get-pr-number/action.yml +++ b/.github/actions/get-pr-number/action.yml @@ -1,9 +1,5 @@ name: 'get-pr-number' description: 'Gets the PR number from an artifact' -inputs: - platform-name: - description: "Name of the target platform" - required: true outputs: pr-number: description: "PR number or empty string" @@ -13,7 +9,7 @@ runs: steps: - uses: ./.github/actions/download-workflow-run-artifact with: - artifact-name: pr-number-${{ inputs.platform-name }} + artifact-name: pr-number - run: touch ./pr_number shell: bash diff --git a/.github/actions/save-pr-number/action.yml b/.github/actions/save-pr-number/action.yml index dbff4fb0350..9df58650a5a 100644 --- a/.github/actions/save-pr-number/action.yml +++ b/.github/actions/save-pr-number/action.yml @@ -1,9 +1,5 @@ name: 'save-pr-number' description: 'Saves the current PR number as artifact' -inputs: - platform-name: - description: "Name of the target platform" - required: true runs: using: "composite" steps: @@ -16,5 +12,6 @@ runs: - name: Upload pr_number uses: actions/upload-artifact@v4 with: - name: pr-number-${{ inputs.platform-name }} - path: ./pr_number \ No newline at end of file + name: pr-number + path: ./pr_number + overwrite: true \ No newline at end of file diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml index 8cf566585ba..a26ad33a352 100644 --- a/.github/workflows/android-ci.yml +++ b/.github/workflows/android-ci.yml @@ -184,8 +184,6 @@ jobs: - if: github.event_name == 'pull_request' uses: ./.github/actions/save-pr-number - with: - platform-name: "android" - name: Build Instrumentation Tests, copy to platform/android run: | diff --git a/.github/workflows/android-device-test.yml b/.github/workflows/android-device-test.yml index 2190eea907e..6c19057b957 100644 --- a/.github/workflows/android-device-test.yml +++ b/.github/workflows/android-device-test.yml @@ -84,8 +84,6 @@ jobs: - uses: ./.github/actions/get-pr-number id: get-pr-number - with: - platform-name: "android" - name: Generate token id: generate_token diff --git a/.github/workflows/ios-ci.yml b/.github/workflows/ios-ci.yml index ae3bd09520b..a11bdf3d8ef 100644 --- a/.github/workflows/ios-ci.yml +++ b/.github/workflows/ios-ci.yml @@ -92,8 +92,8 @@ jobs: - name: Lint plist files run: bazel run //platform/ios:lint-plists --//:renderer=metal - # - name: Running iOS tests - # run: bazel test //platform/ios/test:ios_test --test_output=errors --//:renderer=metal + - name: Running iOS tests + run: bazel test //platform/ios/test:ios_test --test_output=errors --//:renderer=metal # tsan run fails with 'Interceptors are not working. This may be because ThreadSanitizer is loaded too late...' #- name: Running iOS UI tests (Thread Sanitizer) @@ -193,8 +193,6 @@ jobs: - if: github.event_name == 'pull_request' uses: ./.github/actions/save-pr-number - with: - platform-name: "ios" - name: Build DocC documentation working-directory: . diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index f26003cc47e..97b90961f82 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -177,8 +177,6 @@ jobs: - if: github.event_name == 'pull_request' uses: ./.github/actions/save-pr-number - with: - platform-name: "linux-${{ matrix.renderer }}" linux-coverage: runs-on: ubuntu-22.04 diff --git a/.github/workflows/pr-bloaty-ios.yml b/.github/workflows/pr-bloaty-ios.yml index bc4487afcd3..31d7ff6c065 100644 --- a/.github/workflows/pr-bloaty-ios.yml +++ b/.github/workflows/pr-bloaty-ios.yml @@ -63,8 +63,6 @@ jobs: - uses: ./.github/actions/get-pr-number id: get-pr-number - with: - platform-name: "ios" - uses: ./.github/actions/download-workflow-run-artifact with: diff --git a/.github/workflows/pr-linux-tests.yml b/.github/workflows/pr-linux-tests.yml index 3a1907de4f8..292ce8291ce 100644 --- a/.github/workflows/pr-linux-tests.yml +++ b/.github/workflows/pr-linux-tests.yml @@ -37,8 +37,6 @@ jobs: - uses: ./.github/actions/get-pr-number id: get-pr-number - with: - platform-name: "linux-vulkan" - uses: ./.github/actions/download-workflow-run-artifact with: @@ -136,8 +134,6 @@ jobs: - uses: ./.github/actions/get-pr-number id: get-pr-number - with: - platform-name: "linux-vulkan" - uses: ./.github/actions/download-workflow-run-artifact with: diff --git a/platform/BUILD.bazel b/platform/BUILD.bazel index 9d961d07115..ae82104a002 100644 --- a/platform/BUILD.bazel +++ b/platform/BUILD.bazel @@ -4,6 +4,8 @@ load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS", "WARNING_FLAGS") objc_library( name = "macos-objcpp", srcs = [ + "//platform/darwin:darwin_gltf_hdrs", + "//platform/darwin:darwin_gltf_srcs", "//platform/darwin:darwin_objcpp_custom_drawable_srcs", "//platform/darwin:darwin_objcpp_srcs", "//platform/darwin:darwin_private_hdrs", @@ -36,6 +38,7 @@ objc_library( "CoreLocation", "AppKit", "SystemConfiguration", + "Accelerate", ], visibility = ["//visibility:public"], deps = [ @@ -50,8 +53,6 @@ objc_library( objc_library( name = "macos-objc", srcs = [ - "//platform/darwin:darwin_gltf_hdrs", - "//platform/darwin:darwin_gltf_srcs", "//platform/darwin:darwin_objc_hdrs", "//platform/darwin:darwin_objc_srcs", "//platform/darwin:darwin_private_hdrs", diff --git a/platform/darwin/bazel/files.bzl b/platform/darwin/bazel/files.bzl index 8776c4c0fd2..460747b2771 100644 --- a/platform/darwin/bazel/files.bzl +++ b/platform/darwin/bazel/files.bzl @@ -1,5 +1,5 @@ MLN_GLTF_HEADERS = [ - "src/gltf/GLTFModelLayer.h" + "src/gltf/GLTFModelLayer.h", ] MLN_GLTF_SOURCE = [ @@ -20,68 +20,66 @@ MLN_GLTF_SOURCE = [ "src/gltf/GLTFModelLayer.h", "src/gltf/GLTFModelLayer.mm", "src/gltf/GLTFModelLoader.h", - "src/gltf/GLTFModelLoader.m", + "src/gltf/GLTFModelLoader.mm", "src/gltf/GLTFMTLRenderItem.h", - "src/gltf/GLTFMTLRenderItem.m", + "src/gltf/GLTFMTLRenderItem.mm", "src/gltf/GLTFRenderer.hpp", "src/gltf/GLTFRenderer.cpp", "src/gltf/MetalRenderer+GLTFAsset.mm", "src/gltf/gltfkit/GLTFAsset.h", - "src/gltf/gltfkit/GLTFAsset.m", + "src/gltf/gltfkit/GLTFAsset.mm", "src/gltf/gltfkit/GLTFAccessor.h", - "src/gltf/gltfkit/GLTFAccessor.m", + "src/gltf/gltfkit/GLTFAccessor.mm", "src/gltf/gltfkit/GLTFAnimation.h", - "src/gltf/gltfkit/GLTFAnimation.m", + "src/gltf/gltfkit/GLTFAnimation.mm", "src/gltf/gltfkit/GLTFBinaryChunk.h", - "src/gltf/gltfkit/GLTFBinaryChunk.m", + "src/gltf/gltfkit/GLTFBinaryChunk.mm", "src/gltf/gltfkit/GLTFBuffer.h", "src/gltf/gltfkit/GLTFBufferAllocator.h", "src/gltf/gltfkit/GLTFBufferView.h", - "src/gltf/gltfkit/GLTFBufferView.m", + "src/gltf/gltfkit/GLTFBufferView.mm", "src/gltf/gltfkit/GLTFCamera.h", - "src/gltf/gltfkit/GLTFCamera.m", + "src/gltf/gltfkit/GLTFCamera.mm", "src/gltf/gltfkit/GLTFDefaultBufferAllocator.h", - "src/gltf/gltfkit/GLTFDefaultBufferAllocator.m", + "src/gltf/gltfkit/GLTFDefaultBufferAllocator.mm", "src/gltf/gltfkit/GLTFEnums.h", "src/gltf/gltfkit/GLTFExtensionNames.h", - "src/gltf/gltfkit/GLTFExtensionNames.m", + "src/gltf/gltfkit/GLTFExtensionNames.mm", "src/gltf/gltfkit/GLTFImage.h", - "src/gltf/gltfkit/GLTFImage.m", + "src/gltf/gltfkit/GLTFImage.mm", "src/gltf/gltfkit/GLTFKHRLight.h", - "src/gltf/gltfkit/GLTFKHRLight.m", + "src/gltf/gltfkit/GLTFKHRLight.mm", "src/gltf/gltfkit/GLTFMaterial.h", - "src/gltf/gltfkit/GLTFMaterial.m", + "src/gltf/gltfkit/GLTFMaterial.mm", "src/gltf/gltfkit/GLTFMesh.h", - "src/gltf/gltfkit/GLTFMesh.m", + "src/gltf/gltfkit/GLTFMesh.mm", "src/gltf/gltfkit/GLTFMTLBufferAllocator.h", - "src/gltf/gltfkit/GLTFMTLBufferAllocator.m", + "src/gltf/gltfkit/GLTFMTLBufferAllocator.mm", "src/gltf/gltfkit/GLTFMTLShaderBuilder.h", - "src/gltf/gltfkit/GLTFMTLShaderBuilder.m", + "src/gltf/gltfkit/GLTFMTLShaderBuilder.mm", "src/gltf/gltfkit/GLTFMTLTextureLoader.h", - "src/gltf/gltfkit/GLTFMTLTextureLoader.m", + "src/gltf/gltfkit/GLTFMTLTextureLoader.mm", "src/gltf/gltfkit/GLTFMTLUtilities.h", - "src/gltf/gltfkit/GLTFMTLUtilities.m", + "src/gltf/gltfkit/GLTFMTLUtilities.mm", "src/gltf/gltfkit/GLTFNode.h", - "src/gltf/gltfkit/GLTFNode.m", + "src/gltf/gltfkit/GLTFNode.mm", "src/gltf/gltfkit/GLTFNodeVisitor.h", "src/gltf/gltfkit/GLTFObject.h", - "src/gltf/gltfkit/GLTFObject.m", + "src/gltf/gltfkit/GLTFObject.mm", "src/gltf/gltfkit/GLTFScene.h", - "src/gltf/gltfkit/GLTFScene.m", + "src/gltf/gltfkit/GLTFScene.mm", "src/gltf/gltfkit/GLTFSkin.h", - "src/gltf/gltfkit/GLTFSkin.m", + "src/gltf/gltfkit/GLTFSkin.mm", "src/gltf/gltfkit/GLTFTexture.h", "src/gltf/gltfkit/GLTFTexture.mm", "src/gltf/gltfkit/GLTFTextureSampler.h", - "src/gltf/gltfkit/GLTFTextureSampler.m", + "src/gltf/gltfkit/GLTFTextureSampler.mm", "src/gltf/gltfkit/GLTFUtilities.h", - "src/gltf/gltfkit/GLTFUtilities.m", + "src/gltf/gltfkit/GLTFUtilities.mm", "src/gltf/gltfkit/GLTFVertexDescriptor.h", - "src/gltf/gltfkit/GLTFVertexDescriptor.m", - + "src/gltf/gltfkit/GLTFVertexDescriptor.mm", ] - MLN_GENERATED_DARWIN_STYLE_SOURCE = [ "src/MLNLight.mm", "src/MLNBackgroundStyleLayer.mm", diff --git a/platform/darwin/src/gltf/Camera.cpp b/platform/darwin/src/gltf/Camera.cpp index d716830ac50..6dc63dced2f 100644 --- a/platform/darwin/src/gltf/Camera.cpp +++ b/platform/darwin/src/gltf/Camera.cpp @@ -20,43 +20,35 @@ Camera::Camera() { _rotationVelocity = 0; _velocity = 0; _distance = 4; // 0; // 2; - } simd_double4x4 Camera::projectionMatrix() { - float fov = M_PI / 3; // original + float fov = M_PI / 3; // original fov = 0.6435011087932844; // Constant that i found in ML simd_double4x4 matrix = GLTFPerspectiveProjectionMatrixAspectFovRH(fov, 1.0, 0.01, 250); return matrix; } void Camera::updateWithTimestep(double timestep) { - - _rotationAngles += _rotationVelocity * timestep; static double rot = 0; // rot += 0.03; -// self.rotationAngles = rot; -// _rotationAngles = simd_make_float3(rot, M_PI/4.0, 0); + // self.rotationAngles = rot; + // _rotationAngles = simd_make_float3(rot, M_PI/4.0, 0); _rotationAngles = simd_make_float3(rot, 0, 0); - // Clamp pitch - _rotationAngles = (simd_float3){ _rotationAngles.x, - static_cast(fmax(-M_PI_2, fmin(_rotationAngles.y, M_PI_2))), - 0 }; - + _rotationAngles = (simd_float3){ + _rotationAngles.x, static_cast(fmax(-M_PI_2, fmin(_rotationAngles.y, M_PI_2))), 0}; _rotationVelocity *= GLTFViewerOrbitCameraRotationDrag; // _distance += _velocity * timestep; _velocity *= GLTFViewerOrbitCameraZoomDrag; - + simd_double4x4 pitchRotation = GLTFRotationMatrixFromAxisAngleD(GLTFAxisXD, -_rotationAngles.y); simd_double4x4 yawRotation = GLTFRotationMatrixFromAxisAngleD(GLTFAxisYD, -_rotationAngles.x); - simd_double4x4 translation = GLTFMatrixFromTranslationD((simd_double3){ 0, 0, _distance }); + simd_double4x4 translation = GLTFMatrixFromTranslationD((simd_double3){0, 0, _distance}); _viewMatrix = matrix_invert(matrix_multiply(matrix_multiply(yawRotation, pitchRotation), translation)); - - } diff --git a/platform/darwin/src/gltf/Camera.hpp b/platform/darwin/src/gltf/Camera.hpp index 05ebba2f6e8..89f760c7e03 100644 --- a/platform/darwin/src/gltf/Camera.hpp +++ b/platform/darwin/src/gltf/Camera.hpp @@ -11,7 +11,8 @@ #include #include -namespace maplibre { namespace gltf { +namespace maplibre { +namespace gltf { class Camera { public: @@ -23,10 +24,9 @@ class Camera { simd_double4x4 projectionMatrix(); simd_double4x4 _viewMatrix; void updateWithTimestep(double timestep); - }; -}} - +} // namespace gltf +} // namespace maplibre #endif /* Camera_hpp */ diff --git a/platform/darwin/src/gltf/GLTFMTLRenderItem.h b/platform/darwin/src/gltf/GLTFMTLRenderItem.h index 4b9cc968b0d..68b0753b1a6 100644 --- a/platform/darwin/src/gltf/GLTFMTLRenderItem.h +++ b/platform/darwin/src/gltf/GLTFMTLRenderItem.h @@ -6,13 +6,12 @@ // #import -#import "gltfkit/GLTFNode.h" #import "gltfkit/GLTFMesh.h" +#import "gltfkit/GLTFNode.h" NS_ASSUME_NONNULL_BEGIN - -@interface GLTFMTLRenderItem: NSObject +@interface GLTFMTLRenderItem : NSObject @property (nonatomic) NSString *label; @property (nonatomic) GLTFNode *node; @property (nonatomic, strong) GLTFSubmesh *submesh; diff --git a/platform/darwin/src/gltf/GLTFMTLRenderItem.m b/platform/darwin/src/gltf/GLTFMTLRenderItem.mm similarity index 100% rename from platform/darwin/src/gltf/GLTFMTLRenderItem.m rename to platform/darwin/src/gltf/GLTFMTLRenderItem.mm diff --git a/platform/darwin/src/gltf/GLTFManager.hpp b/platform/darwin/src/gltf/GLTFManager.hpp index fcd1061e8dd..9fce472cb1e 100644 --- a/platform/darwin/src/gltf/GLTFManager.hpp +++ b/platform/darwin/src/gltf/GLTFManager.hpp @@ -17,91 +17,90 @@ #include "GLTFModel.hpp" #include "GLTFManagerRenderingEnvironment.hpp" -namespace maplibre { namespace gltf { - - // The type of rendering environment we're in - typedef enum { - RenderingEnvironmentUnknown, - RenderingEnvironmentMetal, - RenderingEnvironmentOpenGL, - RenderingEnvironmentVulkan - } RenderingEnvironment; - - struct Coordinate2D { - double _lat; - double _lon; - }; - - struct Cartesian3D { - double _x; - double _y; - double _z; - }; - - - typedef std::function ProjectionCallback; - - // The GLTF Manager class is the top level entry point - // for all things model based - class GLTFManager { - public: - // Set the callback - void setProjectionCallback(ProjectionCallback projectionCallback); - - // Instantiate the manager with the appropriate environment - GLTFManager(RenderingEnvironment renderingEnvironment); - - // Load a model - void addModel(std::shared_ptr model); - - // Remove a model - void removeModel(std::shared_ptr model); - - // Current meter to screen pixel scale - double _metersPerPixel = 1.0; - - // Set the drawable size - void setDrawableSize(int width, int height); - - // Set the tilt deg - void setTiltDeg(double tiltDeg); - - // Set the rotation deg - void setRotationDeg(double rotationDeg); - - // Set the rendering environment variables - void setRenderingEnvironmentVariables(std::shared_ptr environmentVars); - - // Update any animations - void updateScene(float timeSinceLastDraw); - - // Render - void render(); - - private: - RenderingEnvironment _renderingEnvironment = RenderingEnvironmentUnknown; - - // List of models - std::vector> _models; - - // Projection callback - ProjectionCallback _projectionCallback; - - private: - // Rendering environment - void createRenderingEnvironment(); - - // The renderer - std::shared_ptr _renderer = nullptr; - - - int _drawableWidth = 1; - int _drawableHeight = 1; - double _tiltDeg = 0; - double _rotationDeg = 0; - - }; - -}} +namespace maplibre { +namespace gltf { + +// The type of rendering environment we're in +typedef enum { + RenderingEnvironmentUnknown, + RenderingEnvironmentMetal, + RenderingEnvironmentOpenGL, + RenderingEnvironmentVulkan +} RenderingEnvironment; + +struct Coordinate2D { + double _lat; + double _lon; +}; + +struct Cartesian3D { + double _x; + double _y; + double _z; +}; + +typedef std::function ProjectionCallback; + +// The GLTF Manager class is the top level entry point +// for all things model based +class GLTFManager { +public: + // Set the callback + void setProjectionCallback(ProjectionCallback projectionCallback); + + // Instantiate the manager with the appropriate environment + GLTFManager(RenderingEnvironment renderingEnvironment); + + // Load a model + void addModel(std::shared_ptr model); + + // Remove a model + void removeModel(std::shared_ptr model); + + // Current meter to screen pixel scale + double _metersPerPixel = 1.0; + + // Set the drawable size + void setDrawableSize(int width, int height); + + // Set the tilt deg + void setTiltDeg(double tiltDeg); + + // Set the rotation deg + void setRotationDeg(double rotationDeg); + + // Set the rendering environment variables + void setRenderingEnvironmentVariables(std::shared_ptr environmentVars); + + // Update any animations + void updateScene(float timeSinceLastDraw); + + // Render + void render(); + +private: + RenderingEnvironment _renderingEnvironment = RenderingEnvironmentUnknown; + + // List of models + std::vector> _models; + + // Projection callback + ProjectionCallback _projectionCallback; + +private: + // Rendering environment + void createRenderingEnvironment(); + + // The renderer + std::shared_ptr _renderer = nullptr; + + int _drawableWidth = 1; + int _drawableHeight = 1; + double _tiltDeg = 0; + double _rotationDeg = 0; +}; + +} // namespace gltf +} // namespace maplibre #endif /* GLTFManager_hpp */ diff --git a/platform/darwin/src/gltf/GLTFManagerRenderingEnvironment.hpp b/platform/darwin/src/gltf/GLTFManagerRenderingEnvironment.hpp index 0be4b404648..1e37c11260c 100644 --- a/platform/darwin/src/gltf/GLTFManagerRenderingEnvironment.hpp +++ b/platform/darwin/src/gltf/GLTFManagerRenderingEnvironment.hpp @@ -11,31 +11,30 @@ #include #include -namespace maplibre { namespace gltf { +namespace maplibre { +namespace gltf { - // Bsae class does nothing really, just a place holder - class GLTFManagerRenderingEnvironment { - public: - // If the bloom should be used - bool _useBloomPass = false; +// Bsae class does nothing really, just a place holder +class GLTFManagerRenderingEnvironment { +public: + // If the bloom should be used + bool _useBloomPass = false; - // FOV - double _currentFOVDEG = 50; - - // Environment projection matrix - simd_double4x4 _currentProjectionMatrix; - - // Current zoom level - double _currentZoomLevel = 1; + // FOV + double _currentFOVDEG = 50; - // - simd_float3 _lightDirection; + // Environment projection matrix + simd_double4x4 _currentProjectionMatrix; - GLTFManagerRenderingEnvironment() { - _lightDirection = simd_make_float3(0.0, 10000.0, 10000.0); - } + // Current zoom level + double _currentZoomLevel = 1; - }; + // + simd_float3 _lightDirection; -}} + GLTFManagerRenderingEnvironment() { _lightDirection = simd_make_float3(0.0, 10000.0, 10000.0); } +}; + +} // namespace gltf +} // namespace maplibre #endif /* GLTFManagerRenderingEnvironment_hpp */ diff --git a/platform/darwin/src/gltf/GLTFManagerRenderingEnvironmentMetal.hpp b/platform/darwin/src/gltf/GLTFManagerRenderingEnvironmentMetal.hpp index ba73b24973e..b64b422bf6b 100644 --- a/platform/darwin/src/gltf/GLTFManagerRenderingEnvironmentMetal.hpp +++ b/platform/darwin/src/gltf/GLTFManagerRenderingEnvironmentMetal.hpp @@ -13,28 +13,29 @@ #include #include "GLTFManagerRenderingEnvironment.hpp" -namespace maplibre { namespace gltf { - - // Bsae class does nothing really, just a place holder - class GLTFManagerRenderingEnvironmentMetal: public GLTFManagerRenderingEnvironment { - public: - // Allows command buffer and render encoder to be passed in. - // if these are nil, then the renderer will create them - id _currentCommandEncoder = nullptr; - id _currentCommandBuffer = nullptr; - - id _currentDrawable = nullptr; - MTLRenderPassDescriptor *_currentRenderPassDescriptor = nullptr; - id _metalDevice = nullptr; - - // TBD: These are placeholders as we noodle how to integrate with ML - // Depth descriptor: If this is null, then use an internal depth - id _depthStencilTexture = nullptr; - - id _colorTexture = nullptr; - }; - -}} - +namespace maplibre { +namespace gltf { + +// Bsae class does nothing really, just a place holder +class GLTFManagerRenderingEnvironmentMetal : public GLTFManagerRenderingEnvironment { +public: + // Allows command buffer and render encoder to be passed in. + // if these are nil, then the renderer will create them + id _currentCommandEncoder = nullptr; + id _currentCommandBuffer = nullptr; + + id _currentDrawable = nullptr; + MTLRenderPassDescriptor *_currentRenderPassDescriptor = nullptr; + id _metalDevice = nullptr; + + // TBD: These are placeholders as we noodle how to integrate with ML + // Depth descriptor: If this is null, then use an internal depth + id _depthStencilTexture = nullptr; + + id _colorTexture = nullptr; +}; + +} // namespace gltf +} // namespace maplibre #endif /* GLTFManagerRenderingEnvironmentMetal_hpp */ diff --git a/platform/darwin/src/gltf/GLTFMath.cpp b/platform/darwin/src/gltf/GLTFMath.cpp index 97f5821e903..8a067505ef5 100644 --- a/platform/darwin/src/gltf/GLTFMath.cpp +++ b/platform/darwin/src/gltf/GLTFMath.cpp @@ -7,7 +7,6 @@ #include "GLTFMath.hpp" - simd_float4x4 GLTFMatrixFromScale(const simd_float3 s) { simd_float4x4 m = matrix_identity_float4x4; m.columns[0].x = s.x; @@ -24,7 +23,6 @@ simd_double4x4 GLTFMatrixFromScaleD(const simd_double3 s) { return m; } - simd_float4x4 GLTFMatrixFromUniformScale(float s) { simd_float4x4 m = matrix_identity_float4x4; m.columns[0].x = s; @@ -41,17 +39,15 @@ simd_double4x4 GLTFMatrixFromUniformScaleD(double s) { return m; } - simd_double4x4 GLTFMatrixFromTranslationD(simd_double3 t) { simd_double4x4 m = matrix_identity_double4x4; - m.columns[3] = (simd_double4) { t.x, t.y, t.z, 1.0 }; + m.columns[3] = (simd_double4){t.x, t.y, t.z, 1.0}; return m; } - simd_float4x4 GLTFMatrixFromTranslation(simd_float3 t) { simd_float4x4 m = matrix_identity_float4x4; - m.columns[3] = (simd_float4) { t.x, t.y, t.z, 1.0 }; + m.columns[3] = (simd_float4){t.x, t.y, t.z, 1.0}; return m; } @@ -60,10 +56,10 @@ GLTFBoundingSphere GLTFBoundingSphereFromBox(const GLTFBoundingBox b) { double midX = (b.maxPoint.x + b.minPoint.x) * 0.5; double midY = (b.maxPoint.y + b.minPoint.y) * 0.5; double midZ = (b.maxPoint.z + b.minPoint.z) * 0.5; - + double r = sqrt(pow(b.maxPoint.x - midX, 2) + pow(b.maxPoint.y - midY, 2) + pow(b.maxPoint.z - midZ, 2)); - - s.center = (simd_double3){ midX, midY, midZ }; + + s.center = (simd_double3){midX, midY, midZ}; s.radius = r; return s; } @@ -73,13 +69,13 @@ simd_float4x4 GLTFRotationMatrixFromAxisAngle(simd_float3 axis, float angle) { float c = cosf(angle); float s = sinf(angle); float t = 1 - c; - - simd_float4 c0 = { t * x * x + c, t * x * y + z * s, t * x * z - y * s, 0 }; - simd_float4 c1 = { t * x * y - z * s, t * y * y + c, t * y * z + x * s, 0 }; - simd_float4 c2 = { t * x * z + y * s, t * y * z - x * s, t * z * z + c, 0 }; - simd_float4 c3 = { 0, 0, 0, 1 }; - - return (simd_float4x4){ c0, c1, c2, c3 }; + + simd_float4 c0 = {t * x * x + c, t * x * y + z * s, t * x * z - y * s, 0}; + simd_float4 c1 = {t * x * y - z * s, t * y * y + c, t * y * z + x * s, 0}; + simd_float4 c2 = {t * x * z + y * s, t * y * z - x * s, t * z * z + c, 0}; + simd_float4 c3 = {0, 0, 0, 1}; + + return (simd_float4x4){c0, c1, c2, c3}; } simd_double4x4 GLTFRotationMatrixFromAxisAngleD(simd_double3 axis, double angle) { @@ -87,83 +83,68 @@ simd_double4x4 GLTFRotationMatrixFromAxisAngleD(simd_double3 axis, double angle) double c = cos(angle); double s = sin(angle); double t = 1 - c; - - simd_double4 c0 = { t * x * x + c, t * x * y + z * s, t * x * z - y * s, 0 }; - simd_double4 c1 = { t * x * y - z * s, t * y * y + c, t * y * z + x * s, 0 }; - simd_double4 c2 = { t * x * z + y * s, t * y * z - x * s, t * z * z + c, 0 }; - simd_double4 c3 = { 0, 0, 0, 1 }; - - return (simd_double4x4){ c0, c1, c2, c3 }; -} + simd_double4 c0 = {t * x * x + c, t * x * y + z * s, t * x * z - y * s, 0}; + simd_double4 c1 = {t * x * y - z * s, t * y * y + c, t * y * z + x * s, 0}; + simd_double4 c2 = {t * x * z + y * s, t * y * z - x * s, t * z * z + c, 0}; + simd_double4 c3 = {0, 0, 0, 1}; -simd_float3 GLTFAxisX = (simd_float3){ 1, 0, 0 }; -simd_float3 GLTFAxisY = (simd_float3){ 0, 1, 0 }; -simd_float3 GLTFAxisZ = (simd_float3){ 0, 0, 1 }; + return (simd_double4x4){c0, c1, c2, c3}; +} -simd_double3 GLTFAxisXD = (simd_double3){ 1, 0, 0 }; -simd_double3 GLTFAxisYD = (simd_double3){ 0, 1, 0 }; -simd_double3 GLTFAxisZD = (simd_double3){ 0, 0, 1 }; +simd_float3 GLTFAxisX = (simd_float3){1, 0, 0}; +simd_float3 GLTFAxisY = (simd_float3){0, 1, 0}; +simd_float3 GLTFAxisZ = (simd_float3){0, 0, 1}; -simd_double4x4 GLTFPerspectiveProjectionMatrixAspectFovRH(const double fovY, const double aspect, const double nearZ, const double farZ) -{ +simd_double3 GLTFAxisXD = (simd_double3){1, 0, 0}; +simd_double3 GLTFAxisYD = (simd_double3){0, 1, 0}; +simd_double3 GLTFAxisZD = (simd_double3){0, 0, 1}; + +simd_double4x4 GLTFPerspectiveProjectionMatrixAspectFovRH(const double fovY, + const double aspect, + const double nearZ, + const double farZ) { double yscale = 1 / tanf(fovY * 0.5f); // 1 / tan == cot double xscale = yscale / aspect; double q = -farZ / (farZ - nearZ); - - simd_double4x4 m = { - .columns[0] = { xscale, 0, 0, 0 }, - .columns[1] = { 0, yscale, 0, 0 }, - .columns[2] = { 0, 0, q, -1 }, - .columns[3] = { 0, 0, q * nearZ, 0 } - }; - + + simd_double4x4 m = {.columns[0] = {xscale, 0, 0, 0}, + .columns[1] = {0, yscale, 0, 0}, + .columns[2] = {0, 0, q, -1}, + .columns[3] = {0, 0, q * nearZ, 0}}; + return m; } - -simd_float4x4 GLTFOrthoProjectionMatrix(const float left, - const float right, - const float bottom, - const float top, - const float nearZ, - const float farZ) { - +simd_float4x4 GLTFOrthoProjectionMatrix( + const float left, const float right, const float bottom, const float top, const float nearZ, const float farZ) { simd_float4x4 m = { - .columns[0] = { 2 / (right - left), 0, 0, 0 }, - .columns[1] = { 0, 2 / (top - bottom), 0, 0 }, - .columns[2] = { 0, 0, 1 / (farZ - nearZ), 0 }, - .columns[3] = { (left + right) / (left - right), (top + bottom) / (bottom - top), nearZ / (nearZ - farZ), 1 } - }; - + .columns[0] = {2 / (right - left), 0, 0, 0}, + .columns[1] = {0, 2 / (top - bottom), 0, 0}, + .columns[2] = {0, 0, 1 / (farZ - nearZ), 0}, + .columns[3] = {(left + right) / (left - right), (top + bottom) / (bottom - top), nearZ / (nearZ - farZ), 1}}; + return m; - } - simd_float3x3 GLTFMatrixUpperLeft3x3(simd_float4x4 m) { - simd_float3x3 mout = { { - { m.columns[0][0], m.columns[0][1], m.columns[0][2] }, - { m.columns[1][0], m.columns[1][1], m.columns[1][2] }, - { m.columns[2][0], m.columns[2][1], m.columns[2][2] } - } }; + simd_float3x3 mout = {{{m.columns[0][0], m.columns[0][1], m.columns[0][2]}, + {m.columns[1][0], m.columns[1][1], m.columns[1][2]}, + {m.columns[2][0], m.columns[2][1], m.columns[2][2]}}}; return mout; } simd_double3x3 GLTFMatrixUpperLeft3x3D(simd_double4x4 m) { - simd_double3x3 mout = { { - { m.columns[0][0], m.columns[0][1], m.columns[0][2] }, - { m.columns[1][0], m.columns[1][1], m.columns[1][2] }, - { m.columns[2][0], m.columns[2][1], m.columns[2][2] } - } }; + simd_double3x3 mout = {{{m.columns[0][0], m.columns[0][1], m.columns[0][2]}, + {m.columns[1][0], m.columns[1][1], m.columns[1][2]}, + {m.columns[2][0], m.columns[2][1], m.columns[2][2]}}}; return mout; } - GLTFTextureTransform GLTFTextureTransformMakeIdentity(void) { GLTFTextureTransform t = { - .offset = (simd_float2){ 0, 0 }, - .scale = (simd_float2){ 1, 1 }, + .offset = (simd_float2){0, 0}, + .scale = (simd_float2){1, 1}, .rotation = 0, }; return t; @@ -185,31 +166,27 @@ simd_float3x3 GLTFTextureMatrixFromTransform(GLTFTextureTransform transform) { float ty = transform.offset.y; float sx = transform.scale.x; float sy = transform.scale.y; - simd_float3 c0 = (simd_float3){ rc * sx, rs * sy, 0 }; - simd_float3 c1 = (simd_float3){ -rs * sx, rc * sy, 0 }; - simd_float3 c2 = (simd_float3){ tx, ty, 1 }; - simd_float3x3 m = (simd_float3x3){ c0, c1, c2 }; + simd_float3 c0 = (simd_float3){rc * sx, rs * sy, 0}; + simd_float3 c1 = (simd_float3){-rs * sx, rc * sy, 0}; + simd_float3 c2 = (simd_float3){tx, ty, 1}; + simd_float3x3 m = (simd_float3x3){c0, c1, c2}; return m; } simd_float4x4 GLTFNormalMatrixFromModelMatrix(simd_float4x4 m) { simd_float3x3 nm = simd_inverse(simd_transpose(GLTFMatrixUpperLeft3x3(m))); - simd_float4x4 mout = { { - { nm.columns[0][0], nm.columns[0][1], nm.columns[0][2], 0 }, - { nm.columns[1][0], nm.columns[1][1], nm.columns[1][2], 0 }, - { nm.columns[2][0], nm.columns[2][1], nm.columns[2][2], 0 }, - { 0, 0, 0, 1 } - } }; + simd_float4x4 mout = {{{nm.columns[0][0], nm.columns[0][1], nm.columns[0][2], 0}, + {nm.columns[1][0], nm.columns[1][1], nm.columns[1][2], 0}, + {nm.columns[2][0], nm.columns[2][1], nm.columns[2][2], 0}, + {0, 0, 0, 1}}}; return mout; } simd_double4x4 GLTFNormalMatrixFromModelMatrixD(simd_double4x4 m) { simd_double3x3 nm = simd_inverse(simd_transpose(GLTFMatrixUpperLeft3x3D(m))); - simd_double4x4 mout = { { - { nm.columns[0][0], nm.columns[0][1], nm.columns[0][2], 0 }, - { nm.columns[1][0], nm.columns[1][1], nm.columns[1][2], 0 }, - { nm.columns[2][0], nm.columns[2][1], nm.columns[2][2], 0 }, - { 0, 0, 0, 1 } - } }; + simd_double4x4 mout = {{{nm.columns[0][0], nm.columns[0][1], nm.columns[0][2], 0}, + {nm.columns[1][0], nm.columns[1][1], nm.columns[1][2], 0}, + {nm.columns[2][0], nm.columns[2][1], nm.columns[2][2], 0}, + {0, 0, 0, 1}}}; return mout; } diff --git a/platform/darwin/src/gltf/GLTFMath.hpp b/platform/darwin/src/gltf/GLTFMath.hpp index eae5a828c56..6e8ce7a4f39 100644 --- a/platform/darwin/src/gltf/GLTFMath.hpp +++ b/platform/darwin/src/gltf/GLTFMath.hpp @@ -22,8 +22,8 @@ typedef enum { GLTFTextureBindIndexBRDFLookup, } GLTFMTLTextureBindIndex; -#define DEG_RAD (M_PI/180.0) -#define RAD_DEG (180.0/M_PI) +#define DEG_RAD (M_PI / 180.0) +#define RAD_DEG (180.0 / M_PI) // 0.0174533 // 57.2958 @@ -31,7 +31,6 @@ typedef enum { #define GLTFMTLMaximumLightCount 3 #define GLTFMTLMaximumTextureCount (GLTFTextureBindIndexEmissive + 1) - typedef struct { simd_float3 minPoint; simd_float3 maxPoint; @@ -42,7 +41,6 @@ typedef struct { float radius; } GLTFBoundingSphere; - typedef struct { simd_float4x4 modelMatrix; simd_float4x4 modelViewProjectionMatrix; @@ -112,14 +110,13 @@ simd_float4x4 GLTFRotationMatrixFromAxisAngle(simd_float3 axis, float angle); simd_double4x4 GLTFRotationMatrixFromAxisAngleD(simd_double3 axis, double angle); -simd_double4x4 GLTFPerspectiveProjectionMatrixAspectFovRH(const double fovY, const double aspect, const double nearZ, const double farZ); +simd_double4x4 GLTFPerspectiveProjectionMatrixAspectFovRH(const double fovY, + const double aspect, + const double nearZ, + const double farZ); -simd_float4x4 GLTFOrthoProjectionMatrix(const float left, - const float right, - const float bottom, - const float top, - const float nearZ, - const float farZ); +simd_float4x4 GLTFOrthoProjectionMatrix( + const float left, const float right, const float bottom, const float top, const float nearZ, const float farZ); simd_float3x3 GLTFMatrixUpperLeft3x3(simd_float4x4 m); @@ -135,7 +132,6 @@ simd_float4x4 GLTFNormalMatrixFromModelMatrix(simd_float4x4 m); simd_double4x4 GLTFNormalMatrixFromModelMatrixD(simd_double4x4 m); - #ifdef __cplusplus } #endif diff --git a/platform/darwin/src/gltf/GLTFModel.hpp b/platform/darwin/src/gltf/GLTFModel.hpp index a09e05b56e5..174b7dd91ee 100644 --- a/platform/darwin/src/gltf/GLTFModel.hpp +++ b/platform/darwin/src/gltf/GLTFModel.hpp @@ -11,36 +11,36 @@ #include #include -namespace maplibre { namespace gltf { - - // Model - class GLTFModel { - public: - // - double _referenceLat = 0; - double _referenceLon = 0; - - // What it takes to scale this model to meters units - float _scaleFactor = 1; - - // Rotation around the reference point - float _rotationDeg = 0; - - // The URL for the model, used by the loader - std::string _modelURL; - - // The brightness - float _brightness = 1.0; - - // This is a hack to deal with passing in the translation vector. - // NEed to reconcile this with the renderable model's version of it - double _xLateX = 0; - double _xLateY = 0; - double _xLateZ = 0; - - }; - - -}} +namespace maplibre { +namespace gltf { + +// Model +class GLTFModel { +public: + // + double _referenceLat = 0; + double _referenceLon = 0; + + // What it takes to scale this model to meters units + float _scaleFactor = 1; + + // Rotation around the reference point + float _rotationDeg = 0; + + // The URL for the model, used by the loader + std::string _modelURL; + + // The brightness + float _brightness = 1.0; + + // This is a hack to deal with passing in the translation vector. + // NEed to reconcile this with the renderable model's version of it + double _xLateX = 0; + double _xLateY = 0; + double _xLateZ = 0; +}; + +} // namespace gltf +} // namespace maplibre #endif /* GLTFModel_hpp */ diff --git a/platform/darwin/src/gltf/GLTFModelLayer.h b/platform/darwin/src/gltf/GLTFModelLayer.h index d9715474eb8..640f3735565 100644 --- a/platform/darwin/src/gltf/GLTFModelLayer.h +++ b/platform/darwin/src/gltf/GLTFModelLayer.h @@ -13,16 +13,16 @@ NS_ASSUME_NONNULL_BEGIN // This sets the relative light position for all the models being rendered // The light position is in meters from the origin of the model. --(void)setLightPositionX:(float)x y:(float)y z:(float)z; +- (void)setLightPositionX:(float)x y:(float)y z:(float)z; --(void)loadModelFromJSON:(NSString *)modelMetadataFilename; +- (void)loadModelFromJSON:(NSString *)modelMetadataFilename; --(void)loadModel:(NSString *)appResourceFilename - lat:(double)lat - lon:(double)lon - rotationDeg:(double)rotationDeg - scaleFactor:(float)scaleFactor - brightness:(float)brightness; +- (void)loadModel:(NSString *)appResourceFilename + lat:(double)lat + lon:(double)lon + rotationDeg:(double)rotationDeg + scaleFactor:(float)scaleFactor + brightness:(float)brightness; @end diff --git a/platform/darwin/src/gltf/GLTFModelLayer.mm b/platform/darwin/src/gltf/GLTFModelLayer.mm index c88150a4e31..b21e7e46a7f 100644 --- a/platform/darwin/src/gltf/GLTFModelLayer.mm +++ b/platform/darwin/src/gltf/GLTFModelLayer.mm @@ -9,7 +9,6 @@ #import #import "MLNBackendResource.h" #import "MLNMapView.h" -#import "MLNMapProjection.h" #include #import "GLTFManagerRenderingEnvironmentMetal.hpp" #import "GLTFManager.hpp" @@ -344,11 +343,6 @@ - (void)drawInMapView:(MLNMapView *)mapView withContext:(MLNStyleLayerDrawingCon _viewportSize.y = resource.mtkView.drawableSize.height; _manager->setDrawableSize(_viewportSize.x, _viewportSize.y); - MLNMapProjection *proj2 = mapView.mapProjection; - _manager->_metersPerPixel = proj2.metersPerPoint / 2.0; - _manager->setTiltDeg(90-mapView.camera.pitch); - _manager->setRotationDeg(-mapView.camera.heading); - float timestep = (1 / 60.0f); _manager->updateScene(timestep); diff --git a/platform/darwin/src/gltf/GLTFModelLoader.h b/platform/darwin/src/gltf/GLTFModelLoader.h index 6cf1b928b98..d1e3ab9d787 100644 --- a/platform/darwin/src/gltf/GLTFModelLoader.h +++ b/platform/darwin/src/gltf/GLTFModelLoader.h @@ -14,10 +14,9 @@ typedef void (^GLTFModelLoaderCompletionHandler)(GLTFAsset *asset); @interface GLTFModelLoader : NSObject --(void)loadURL:(NSURL *)assetURL -withCompletionHandler:(GLTFModelLoaderCompletionHandler)completionHandler -bufferAllocator:(id)bufferAllocator; - +- (void)loadURL:(NSURL *)assetURL + withCompletionHandler:(GLTFModelLoaderCompletionHandler)completionHandler + bufferAllocator:(id)bufferAllocator; @end diff --git a/platform/darwin/src/gltf/GLTFModelLoader.m b/platform/darwin/src/gltf/GLTFModelLoader.mm similarity index 100% rename from platform/darwin/src/gltf/GLTFModelLoader.m rename to platform/darwin/src/gltf/GLTFModelLoader.mm diff --git a/platform/darwin/src/gltf/GLTFRenderer.cpp b/platform/darwin/src/gltf/GLTFRenderer.cpp index 86fc66be865..c308e566f32 100644 --- a/platform/darwin/src/gltf/GLTFRenderer.cpp +++ b/platform/darwin/src/gltf/GLTFRenderer.cpp @@ -18,14 +18,13 @@ GLTFRenderer::~GLTFRenderer() { // Base class does nothing } - // Update any animations void GLTFRenderer::update(float timeSinceLastDraw) { // Base class does nothing } // Render - void GLTFRenderer::render() { +void GLTFRenderer::render() { // Base class does nothing } @@ -35,18 +34,11 @@ void GLTFRenderer::setDrawableSize(int width, int height) { } // Protected items -void GLTFRenderer::loadBloomPipelines() { - -} - -void GLTFRenderer::loadTonemapPipeline() { - -} +void GLTFRenderer::loadBloomPipelines() {} -void GLTFRenderer::updateFramebufferSize() { - -} +void GLTFRenderer::loadTonemapPipeline() {} +void GLTFRenderer::updateFramebufferSize() {} // Load a model void GLTFRenderer::loadGLTFModel(std::shared_ptr model) { @@ -68,14 +60,11 @@ void GLTFRenderer::setRotationDeg(double rotationDeg) { _rotationDeg = rotationDeg; } - - // Use bloom pass void GLTFRenderer::setUseBloomPass(bool useBloomPass) { _useBloomPass = useBloomPass; } - // Set the rendering environemnt variables void GLTFRenderer::setRenderingEnvironemnt(std::shared_ptr renderingEnvironment) { _renderingEnvironment = renderingEnvironment; diff --git a/platform/darwin/src/gltf/GLTFRenderer.hpp b/platform/darwin/src/gltf/GLTFRenderer.hpp index 22d52ad0722..dba305678e6 100644 --- a/platform/darwin/src/gltf/GLTFRenderer.hpp +++ b/platform/darwin/src/gltf/GLTFRenderer.hpp @@ -14,56 +14,57 @@ #include "GLTFManagerRenderingEnvironment.hpp" #include -namespace maplibre { namespace gltf { - - class GLTFRenderer { - public: - // Constructor - GLTFRenderer(); - - // Destructor - virtual ~GLTFRenderer(); - - // Update any animations - virtual void update(float timeSinceLastDraw); - - // Render - virtual void render(); - - // Set the drawable size - virtual void setDrawableSize(int width, int height); - - // Load a model - virtual void loadGLTFModel(std::shared_ptr model); - - // Set the meters per pixel scale - void setMetersPerPixel(double metersPerPixel); - - // Set tilt - void setTiltDeg(double tiltDeg); - - // Set the rotation deg - void setRotationDeg(double rotationDeg); - - // Use bloom pass - void setUseBloomPass(bool useBloomPass); - - // Set the rendering environemnt variables - virtual void setRenderingEnvironemnt(std::shared_ptr renderingEnvironment); - - protected: - std::unique_ptr _camera = nullptr; - double _metersPerPixel = 1; - std::shared_ptr _renderingEnvironment = nullptr; - double _tiltDeg = 0; - double _rotationDeg = 0; - bool _useBloomPass = true; - virtual void loadBloomPipelines(); - virtual void loadTonemapPipeline(); - virtual void updateFramebufferSize(); - - }; - -}} +namespace maplibre { +namespace gltf { + +class GLTFRenderer { +public: + // Constructor + GLTFRenderer(); + + // Destructor + virtual ~GLTFRenderer(); + + // Update any animations + virtual void update(float timeSinceLastDraw); + + // Render + virtual void render(); + + // Set the drawable size + virtual void setDrawableSize(int width, int height); + + // Load a model + virtual void loadGLTFModel(std::shared_ptr model); + + // Set the meters per pixel scale + void setMetersPerPixel(double metersPerPixel); + + // Set tilt + void setTiltDeg(double tiltDeg); + + // Set the rotation deg + void setRotationDeg(double rotationDeg); + + // Use bloom pass + void setUseBloomPass(bool useBloomPass); + + // Set the rendering environemnt variables + virtual void setRenderingEnvironemnt(std::shared_ptr renderingEnvironment); + +protected: + std::unique_ptr _camera = nullptr; + double _metersPerPixel = 1; + std::shared_ptr _renderingEnvironment = nullptr; + double _tiltDeg = 0; + double _rotationDeg = 0; + bool _useBloomPass = true; + virtual void loadBloomPipelines(); + virtual void loadTonemapPipeline(); + virtual void updateFramebufferSize(); +}; + +} // namespace gltf +} // namespace maplibre #endif /* GLTFRenderer_hpp */ diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAccessor.h b/platform/darwin/src/gltf/gltfkit/GLTFAccessor.h index 4414b8ab58f..e5bdf0d2f77 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAccessor.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFAccessor.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" #import @@ -24,8 +24,8 @@ NS_ASSUME_NONNULL_BEGIN @class GLTFBufferView; typedef struct { - float minValue[16]; - float maxValue[16]; + float minValue[16]; + float maxValue[16]; } GLTFValueRange; @interface GLTFAccessor : GLTFObject diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAccessor.m b/platform/darwin/src/gltf/gltfkit/GLTFAccessor.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFAccessor.m rename to platform/darwin/src/gltf/gltfkit/GLTFAccessor.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAnimation.h b/platform/darwin/src/gltf/gltfkit/GLTFAnimation.h index b70ab091a02..e00693e578f 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAnimation.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFAnimation.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" NS_ASSUME_NONNULL_BEGIN diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAnimation.m b/platform/darwin/src/gltf/gltfkit/GLTFAnimation.mm similarity index 87% rename from platform/darwin/src/gltf/gltfkit/GLTFAnimation.m rename to platform/darwin/src/gltf/gltfkit/GLTFAnimation.mm index 7bde7e06013..e716fc0113f 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAnimation.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFAnimation.mm @@ -15,6 +15,7 @@ // #import "GLTFAnimation.h" +#include "GLTFUtilities.h" #import "GLTFAccessor.h" #import "GLTFBufferView.h" #import "GLTFBuffer.h" @@ -27,11 +28,11 @@ - (NSString *)description { } - (const void *)inputValues { - return [self.inputAccessor.bufferView.buffer contents] + self.inputAccessor.bufferView.offset + self.inputAccessor.offset; + return (uint8_t*)[self.inputAccessor.bufferView.buffer contents] + self.inputAccessor.bufferView.offset + self.inputAccessor.offset; } - (const void *)outputValues { - return [self.outputAccessor.bufferView.buffer contents] + self.outputAccessor.bufferView.offset + self.outputAccessor.offset; + return (uint8_t*)[self.outputAccessor.bufferView.buffer contents] + self.outputAccessor.bufferView.offset + self.outputAccessor.offset; } - (int)keyFrameCount { @@ -48,14 +49,14 @@ - (NSString *)description { - (NSTimeInterval)startTime { GLTFAnimationSampler *sampler = self.sampler; - const float *timeValues = sampler.inputValues; + const float *timeValues = (const float*)sampler.inputValues; float startTime = timeValues[0]; return startTime; } - (NSTimeInterval)endTime { GLTFAnimationSampler *sampler = self.sampler; - const float *timeValues = sampler.inputValues; + const float *timeValues = (const float*)sampler.inputValues; int keyFrameCount = sampler.keyFrameCount; float endTime = timeValues[keyFrameCount - 1]; return endTime; @@ -81,7 +82,7 @@ - (void)runAtTime:(NSTimeInterval)time { int keyFrameCount = sampler.keyFrameCount; - const float *timeValues = sampler.inputValues; + const float *timeValues = (const float*)sampler.inputValues; float minTime = timeValues[0]; float maxTime = timeValues[keyFrameCount - 1]; @@ -115,7 +116,7 @@ - (void)runAtTime:(NSTimeInterval)time { NSLog(@"WARNING: Only float accessors are supported for rotation animations. This will only be reported once."); }); } - const GLTFQuaternion *rotationValues = sampler.outputValues; + const GLTFQuaternion *rotationValues = (const GLTFQuaternion*)sampler.outputValues; GLTFQuaternion previousRotation = rotationValues[previousKeyFrame]; GLTFQuaternion nextRotation = rotationValues[nextKeyFrame]; @@ -123,11 +124,11 @@ - (void)runAtTime:(NSTimeInterval)time { target.rotationQuaternion = interpRotation; } else if ([path isEqualToString:@"translation"]) { - const GLTFVector3 *translationValues = sampler.outputValues; + const GLTFVector3 *translationValues = (const GLTFVector3*)sampler.outputValues; GLTFVector3 previousTranslation = translationValues[previousKeyFrame]; GLTFVector3 nextTranslation = translationValues[nextKeyFrame]; - + GLTFVector3 interpTranslation = (GLTFVector3) { ((1 - frameProgress) * previousTranslation.x) + (frameProgress * nextTranslation.x), ((1 - frameProgress) * previousTranslation.y) + (frameProgress * nextTranslation.y), @@ -136,7 +137,7 @@ - (void)runAtTime:(NSTimeInterval)time { target.translation = (simd_float3){ interpTranslation.x, interpTranslation.y, interpTranslation.z }; } else if ([path isEqualToString:@"scale"]) { - const float *scaleValues = sampler.outputValues; + const float *scaleValues = (const float*)sampler.outputValues; float previousScale = scaleValues[previousKeyFrame]; float nextScale = scaleValues[nextKeyFrame]; @@ -151,7 +152,7 @@ - (void)runAtTime:(NSTimeInterval)time { NSLog(@"WARNING: Only scalar float accessors are supported for weight animations. This will only be reported once."); }); } - const float *weightValues = sampler.outputValues; + const float *weightValues = (const float*)sampler.outputValues; long weightCount = sampler.outputAccessor.count / keyFrameCount; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAsset.h b/platform/darwin/src/gltf/gltfkit/GLTFAsset.h index 2f883a685bd..bbd795d35a7 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAsset.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFAsset.h @@ -16,8 +16,8 @@ #import -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" NS_ASSUME_NONNULL_BEGIN @@ -27,7 +27,9 @@ NS_ASSUME_NONNULL_BEGIN @protocol GLTFBufferAllocator; @protocol GLTFAssetLoadingDelegate -- (void)assetWithURL:(NSURL *)assetURL requiresContentsOfURL:(NSURL *)url completionHandler:(void (^)(NSData *_Nullable, NSError *_Nullable))completionHandler; +- (void)assetWithURL:(NSURL *)assetURL + requiresContentsOfURL:(NSURL *)url + completionHandler:(void (^)(NSData *_Nullable, NSError *_Nullable))completionHandler; - (void)assetWithURL:(NSURL *)assetURL didFinishLoading:(GLTFAsset *)asset; - (void)assetWithURL:(NSURL *)assetURL didFailToLoadWithError:(NSError *)error; @end @@ -35,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GLTFAsset : NSObject @property (nonatomic, readonly, strong) NSArray *scenes; -@property (nonatomic, readonly) GLTFScene * _Nullable defaultScene; +@property (nonatomic, readonly) GLTFScene *_Nullable defaultScene; @property (nonatomic, readonly, strong) NSArray *animations; @@ -43,16 +45,18 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly, strong) NSArray *cameras; -@property (nonatomic, copy) NSString * _Nullable generator; -@property (nonatomic, copy) NSString * _Nullable copyright; -@property (nonatomic, copy) NSString * _Nullable formatVersion; +@property (nonatomic, copy) NSString *_Nullable generator; +@property (nonatomic, copy) NSString *_Nullable copyright; +@property (nonatomic, copy) NSString *_Nullable formatVersion; @property (nonatomic, copy) NSArray *extensionsUsed; -/// Load an asset asynchronously. The asset may either be a local asset or a remote asset; the provided -/// delegate will receive callbacks requesting the contents of remote URLs referenced by the asset. These -/// callbacks will occur on an arbitrary internal queue. -+ (void)loadAssetWithURL:(NSURL *)url bufferAllocator:(id)bufferAllocator delegate:(id)delegate; +/// Load an asset asynchronously. The asset may either be a local asset or a remote asset; the +/// provided delegate will receive callbacks requesting the contents of remote URLs referenced by +/// the asset. These callbacks will occur on an arbitrary internal queue. ++ (void)loadAssetWithURL:(NSURL *)url + bufferAllocator:(id)bufferAllocator + delegate:(id)delegate; /// Load a local asset. The provided URL must be a file URL, or else loading will fail. - (instancetype)initWithURL:(NSURL *)url bufferAllocator:(id)bufferAllocator; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFAsset.m b/platform/darwin/src/gltf/gltfkit/GLTFAsset.mm similarity index 96% rename from platform/darwin/src/gltf/gltfkit/GLTFAsset.m rename to platform/darwin/src/gltf/gltfkit/GLTFAsset.mm index b54289e4dde..ccda5f5ed2d 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFAsset.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFAsset.mm @@ -15,6 +15,7 @@ // #import "GLTFAsset.h" +#include "GLTFEnums.h" #import "GLTFAnimation.h" #import "GLTFAccessor.h" #import "GLTFBinaryChunk.h" @@ -263,11 +264,11 @@ - (void)readBinaryChunks:(NSData *)assetData { [assetData getBytes:&chunkHeader range:NSMakeRange(offset, sizeof(chunkHeader))]; - NSData *chunkData = [NSData dataWithBytesNoCopy:(void *)(assetData.bytes + offset + sizeof(chunkHeader)) + NSData *chunkData = [NSData dataWithBytesNoCopy:(void *)((uint8_t*)assetData.bytes + offset + sizeof(chunkHeader)) length:chunkHeader.length freeWhenDone:NO]; chunk.data = chunkData; - chunk.chunkType = chunkHeader.type; + chunk.chunkType = (GLTFChunkType)chunkHeader.type; [chunks addObject:chunk]; @@ -296,7 +297,7 @@ - (BOOL)loadAccessors:(NSArray *)accessorsMap { NSMutableArray *accessors = [NSMutableArray arrayWithCapacity:accessorsMap.count]; for (NSDictionary *properties in accessorsMap) { GLTFAccessor *accessor = [[GLTFAccessor alloc] init]; - accessor.componentType = [properties[@"componentType"] integerValue]; + accessor.componentType = (GLTFDataType)[properties[@"componentType"] integerValue]; accessor.dimension = GLTFDataDimensionForName(properties[@"type"]); accessor.offset = [properties[@"byteOffset"] integerValue]; accessor.count = [properties[@"count"] integerValue]; @@ -315,7 +316,7 @@ - (BOOL)loadAccessors:(NSArray *)accessorsMap { NSLog(@"WARNING: Accessor had misaligned offset %d, which is not a multiple of %d. Building auxiliary buffer of length %d and continuing...", (int)dataOffset, (int)alignment, (int)length); id buffer = [_bufferAllocator newBufferWithLength:length]; - memcpy(buffer.contents, accessor.bufferView.buffer.contents + accessor.bufferView.offset + accessor.offset, buffer.length); + memcpy(buffer.contents, (uint8_t*)accessor.bufferView.buffer.contents + accessor.bufferView.offset + accessor.offset, buffer.length); _buffers = [_buffers arrayByAddingObject:buffer]; GLTFBufferView *bufferView = [GLTFBufferView new]; @@ -329,7 +330,7 @@ - (BOOL)loadAccessors:(NSArray *)accessorsMap { } } - __block GLTFValueRange valueRange = { 0 }; + __block GLTFValueRange valueRange = { {}, {} }; NSArray *minValues = properties[@"min"]; [minValues enumerateObjectsUsingBlock:^(NSNumber *num, NSUInteger index, BOOL *stop) { valueRange.minValue[index] = num.floatValue; @@ -408,7 +409,7 @@ - (BOOL)loadBufferViews:(NSArray *)bufferViewsMap { bufferView.length = [properties[@"byteLength"] integerValue]; bufferView.stride = [properties[@"byteStride"] integerValue]; bufferView.offset = [properties[@"byteOffset"] integerValue]; - bufferView.target = [properties[@"target"] integerValue]; + bufferView.target = (GLTFTarget)[properties[@"target"] integerValue]; // if ((bufferView.buffer != nil) && (bufferView.offset % 16 != 0)) { // NSLog(@"WARNING: Buffer view %d had misaligned offset of %d. Creating auxilliary buffer of length %d and continuing...", @@ -435,10 +436,10 @@ - (BOOL)loadSamplers:(NSArray *)samplersMap { NSMutableArray *samplers = [NSMutableArray arrayWithCapacity:samplersMap.count]; for (NSDictionary *properties in samplersMap) { GLTFTextureSampler *sampler = [[GLTFTextureSampler alloc] init]; - sampler.minFilter = [properties[@"minFilter"] integerValue] ?: sampler.minFilter; - sampler.magFilter = [properties[@"magFilter"] integerValue] ?: sampler.magFilter; - sampler.sAddressMode = [properties[@"wrapS"] integerValue] ?: sampler.sAddressMode; - sampler.tAddressMode = [properties[@"wrapT"] integerValue] ?: sampler.tAddressMode; + sampler.minFilter = (GLTFSamplingFilter)([properties[@"minFilter"] integerValue] ?: sampler.minFilter); + sampler.magFilter = (GLTFSamplingFilter)([properties[@"magFilter"] integerValue] ?: sampler.magFilter); + sampler.sAddressMode = (GLTFAddressMode)([properties[@"wrapS"] integerValue] ?: sampler.sAddressMode); + sampler.tAddressMode = (GLTFAddressMode)([properties[@"wrapT"] integerValue] ?: sampler.tAddressMode); sampler.name = properties[@"name"]; sampler.extensions = properties[@"extensions"]; sampler.extras = properties[@"extras"]; @@ -510,10 +511,10 @@ - (BOOL)loadTextures:(NSArray *)texturesMap { texture.image = _images[imageIndex]; } - texture.format = [properties[@"format"] integerValue] ?: texture.format; - texture.internalFormat = [properties[@"internalFormat"] integerValue] ?: texture.internalFormat; - texture.target = [properties[@"target"] integerValue] ?: texture.target; - texture.type = [properties[@"type"] integerValue] ?: texture.type; + texture.format = (GLTFTextureFormat)([properties[@"format"] integerValue] ?: texture.format); + texture.internalFormat = (GLTFTextureFormat)([properties[@"internalFormat"] integerValue] ?: texture.internalFormat); + texture.target = (GLTFTextureTarget)([properties[@"target"] integerValue] ?: texture.target); + texture.type = (GLTFTextureType)([properties[@"type"] integerValue] ?: texture.type); texture.name = properties[@"name"]; texture.extensions = properties[@"extensions"]; texture.extras = properties[@"extras"]; @@ -665,12 +666,12 @@ - (BOOL)loadMeshes:(NSArray *)meshesMap { NSUInteger indexAccessorIndex = [submeshProperties[@"indices"] intValue]; if (indexAccessorIndex < _accessors.count) { GLTFAccessor *indexAccessor = _accessors[indexAccessorIndex]; - if (indexAccessor.componentType == GLTFTextureTypeUChar) { + if (indexAccessor.componentType == (GLTFDataType)GLTFTextureTypeUChar) { // Fix up 8-bit indices, since they're unsupported in modern APIs - uint8_t *sourceIndices = indexAccessor.bufferView.buffer.contents + indexAccessor.offset + indexAccessor.bufferView.offset; + uint8_t *sourceIndices = (uint8_t*)indexAccessor.bufferView.buffer.contents + indexAccessor.offset + indexAccessor.bufferView.offset; id shortBuffer = [_bufferAllocator newBufferWithLength:indexAccessor.count * sizeof(uint16_t)]; - uint16_t *destIndices = shortBuffer.contents; + uint16_t *destIndices = (uint16_t*)shortBuffer.contents; for (int i = 0; i < indexAccessor.count; ++i) { destIndices[i] = (uint16_t)sourceIndices[i]; } diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.h b/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.h index 593b8329f29..cb4fd22591c 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.h @@ -19,14 +19,14 @@ extern const UInt32 GLTFBinaryMagic; typedef NS_ENUM(NSInteger, GLTFChunkType) { - GLTFChunkTypeJSON = 0x4E4F534A, - GLTFChunkTypeBinary = 0x004E4942 + GLTFChunkTypeJSON = 0x4E4F534A, + GLTFChunkTypeBinary = 0x004E4942 }; typedef struct { - UInt32 magic; - UInt32 version; - UInt32 length; + UInt32 magic; + UInt32 version; + UInt32 length; } GLTFBinaryHeader; @interface GLTFBinaryChunk : NSObject diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.m b/platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.m rename to platform/darwin/src/gltf/gltfkit/GLTFBinaryChunk.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBuffer.h b/platform/darwin/src/gltf/gltfkit/GLTFBuffer.h index 0be3d201b02..a91cd8fda24 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFBuffer.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFBuffer.h @@ -22,7 +22,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSInteger length; -/// The actual data associated with this buffer. If uri is a data URI, this is populated when loading; else it is nil +/// The actual data associated with this buffer. If uri is a data URI, this is populated when +/// loading; else it is nil @property (nonatomic, readonly) void *contents; @end diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBufferView.h b/platform/darwin/src/gltf/gltfkit/GLTFBufferView.h index 2b41ec2f46c..3f83f265f35 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFBufferView.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFBufferView.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" NS_ASSUME_NONNULL_BEGIN diff --git a/platform/darwin/src/gltf/gltfkit/GLTFBufferView.m b/platform/darwin/src/gltf/gltfkit/GLTFBufferView.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFBufferView.m rename to platform/darwin/src/gltf/gltfkit/GLTFBufferView.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFCamera.h b/platform/darwin/src/gltf/gltfkit/GLTFCamera.h index 2d710a7ffcb..67d729b85c9 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFCamera.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFCamera.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" #import @@ -26,10 +26,10 @@ NS_ASSUME_NONNULL_BEGIN @interface GLTFCamera : GLTFObject @property (nonatomic, assign) GLTFCameraType cameraType; -@property (nonatomic, assign) float aspectRatio; // Only applicable when type is perspective -@property (nonatomic, assign) float yfov; // Only applicable when type is perspective -@property (nonatomic, assign) float xmag; // Only applicable when type is orthographic -@property (nonatomic, assign) float ymag; // Only applicable when type is orthographic +@property (nonatomic, assign) float aspectRatio; // Only applicable when type is perspective +@property (nonatomic, assign) float yfov; // Only applicable when type is perspective +@property (nonatomic, assign) float xmag; // Only applicable when type is orthographic +@property (nonatomic, assign) float ymag; // Only applicable when type is orthographic @property (nonatomic, assign) float znear; @property (nonatomic, assign) float zfar; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFCamera.m b/platform/darwin/src/gltf/gltfkit/GLTFCamera.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFCamera.m rename to platform/darwin/src/gltf/gltfkit/GLTFCamera.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.m b/platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.m rename to platform/darwin/src/gltf/gltfkit/GLTFDefaultBufferAllocator.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFEnums.h b/platform/darwin/src/gltf/gltfkit/GLTFEnums.h index dbf5177be5f..76bffbc8779 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFEnums.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFEnums.h @@ -17,162 +17,162 @@ #import typedef NS_ENUM(NSInteger, GLTFDataType) { - GLTFBaseTypeUnknown, - GLTFDataTypeChar = 0x1400, - GLTFDataTypeUChar = 0x1401, - GLTFDataTypeShort = 0x1402, - GLTFDataTypeUShort = 0x1403, - GLTFDataTypeInt = 0x1404, - GLTFDataTypeUInt = 0x1405, - GLTFDataTypeFloat = 0x1406, - - GLTFDataTypeFloat2 = 0x8B50, - GLTFDataTypeFloat3 = 0x8B51, - GLTFDataTypeFloat4 = 0x8B52, - GLTFDataTypeInt2 = 0x8B53, - GLTFDataTypeInt3 = 0x8B54, - GLTFDataTypeInt4 = 0x8B55, - GLTFDataTypeBool = 0x8B56, - GLTFDataTypeBool2 = 0x8B57, - GLTFDataTypeBool3 = 0x8B58, - GLTFDataTypeBool4 = 0x8B59, - GLTFDataTypeFloat2x2 = 0x8B5A, - GLTFDataTypeFloat3x3 = 0x8B5B, - GLTFDataTypeFloat4x4 = 0x8B5C, - GLTFDataTypeSampler2D = 0x8B5E, + GLTFBaseTypeUnknown, + GLTFDataTypeChar = 0x1400, + GLTFDataTypeUChar = 0x1401, + GLTFDataTypeShort = 0x1402, + GLTFDataTypeUShort = 0x1403, + GLTFDataTypeInt = 0x1404, + GLTFDataTypeUInt = 0x1405, + GLTFDataTypeFloat = 0x1406, + + GLTFDataTypeFloat2 = 0x8B50, + GLTFDataTypeFloat3 = 0x8B51, + GLTFDataTypeFloat4 = 0x8B52, + GLTFDataTypeInt2 = 0x8B53, + GLTFDataTypeInt3 = 0x8B54, + GLTFDataTypeInt4 = 0x8B55, + GLTFDataTypeBool = 0x8B56, + GLTFDataTypeBool2 = 0x8B57, + GLTFDataTypeBool3 = 0x8B58, + GLTFDataTypeBool4 = 0x8B59, + GLTFDataTypeFloat2x2 = 0x8B5A, + GLTFDataTypeFloat3x3 = 0x8B5B, + GLTFDataTypeFloat4x4 = 0x8B5C, + GLTFDataTypeSampler2D = 0x8B5E, }; typedef NS_ENUM(NSInteger, GLTFDataDimension) { - GLTFDataDimensionUnknown, - GLTFDataDimensionScalar, - GLTFDataDimensionVector2, - GLTFDataDimensionVector3, - GLTFDataDimensionVector4, - GLTFDataDimensionMatrix2x2, - GLTFDataDimensionMatrix3x3, - GLTFDataDimensionMatrix4x4, + GLTFDataDimensionUnknown, + GLTFDataDimensionScalar, + GLTFDataDimensionVector2, + GLTFDataDimensionVector3, + GLTFDataDimensionVector4, + GLTFDataDimensionMatrix2x2, + GLTFDataDimensionMatrix3x3, + GLTFDataDimensionMatrix4x4, }; typedef NS_ENUM(NSInteger, GLTFTarget) { - GLTFTargetUnknown, - GLTFTargetArrayBuffer = 0x8892, - GLTFTargetElementArrayBuffer = 0x8893, + GLTFTargetUnknown, + GLTFTargetArrayBuffer = 0x8892, + GLTFTargetElementArrayBuffer = 0x8893, }; typedef NS_ENUM(NSInteger, GLTFPrimitiveType) { - GLTFPrimitiveTypePoints, - GLTFPrimitiveTypeLines, - GLTFPrimitiveTypeLineLoop, - GLTFPrimitiveTypeLineStrip, - GLTFPrimitiveTypeTriangles, - GLTFPrimitiveTypeTriangleStrip, - GLTFPrimitiveTypeTriangleFan, + GLTFPrimitiveTypePoints, + GLTFPrimitiveTypeLines, + GLTFPrimitiveTypeLineLoop, + GLTFPrimitiveTypeLineStrip, + GLTFPrimitiveTypeTriangles, + GLTFPrimitiveTypeTriangleStrip, + GLTFPrimitiveTypeTriangleFan, }; typedef NS_ENUM(NSInteger, GLTFCameraType) { - GLTFCameraTypePerspective, - GLTFCameraTypeOrthographic, + GLTFCameraTypePerspective, + GLTFCameraTypeOrthographic, }; typedef NS_ENUM(NSInteger, GLTFTextureTarget) { - GLTFTextureTargetTexture2D = 0x0DE1, + GLTFTextureTargetTexture2D = 0x0DE1, }; typedef NS_ENUM(NSInteger, GLTFTextureFormat) { - GLTFTextureFormatUnknown, - GLTFTextureFormatAlpha = 0x1906, - GLTFTextureFormatRGB = 0x1907, - GLTFTextureFormatRGBA = 0x1908, - GLTFTextureFormatLuminance = 0x1909, - GLTFTextureFormatLuminanceAlpha = 0x190A, + GLTFTextureFormatUnknown, + GLTFTextureFormatAlpha = 0x1906, + GLTFTextureFormatRGB = 0x1907, + GLTFTextureFormatRGBA = 0x1908, + GLTFTextureFormatLuminance = 0x1909, + GLTFTextureFormatLuminanceAlpha = 0x190A, }; typedef NS_ENUM(NSInteger, GLTFTextureType) { - GLTFTextureTypeUnknown, - GLTFTextureTypeUChar = 0x1401, - GLTFTextureTypeUShort565 = 0x8363, - GLTFTextureTypeUShort4444 = 0x8033, - GLTFTextureTypeUShort5551 = 0x8034, + GLTFTextureTypeUnknown, + GLTFTextureTypeUChar = 0x1401, + GLTFTextureTypeUShort565 = 0x8363, + GLTFTextureTypeUShort4444 = 0x8033, + GLTFTextureTypeUShort5551 = 0x8034, }; typedef NS_ENUM(NSInteger, GLTFShaderType) { - GLTFShaderTypeVertex = 0x8B31, - GLTFShaderTypeFragment = 0x8B30, + GLTFShaderTypeVertex = 0x8B31, + GLTFShaderTypeFragment = 0x8B30, }; typedef NS_ENUM(NSInteger, GLTFSamplingFilter) { - GLTFSamplingFilterUnknown, - GLTFSamplingFilterNearest = 0x2600, - GLTFSamplingFilterLinear = 0x2601, - GLTFSamplingFilterNearestMipNearest = 0x2700, - GLTFSamplingFilterLinearMipNearest = 0x2701, - GLTFSamplingFilterNearestMipLinear = 0x2702, - GLTFSamplingLinearMipLinear = 0x2703, + GLTFSamplingFilterUnknown, + GLTFSamplingFilterNearest = 0x2600, + GLTFSamplingFilterLinear = 0x2601, + GLTFSamplingFilterNearestMipNearest = 0x2700, + GLTFSamplingFilterLinearMipNearest = 0x2701, + GLTFSamplingFilterNearestMipLinear = 0x2702, + GLTFSamplingLinearMipLinear = 0x2703, }; typedef NS_ENUM(NSInteger, GLTFAddressMode) { - GLTFAddressModeUnknown, - GLTFAddressModeClampToEdge = 0x812F, - GLTFAddressModeMirroredRepeat = 0x8370, - GLTFAddressModeRepeat = 0x2901, + GLTFAddressModeUnknown, + GLTFAddressModeClampToEdge = 0x812F, + GLTFAddressModeMirroredRepeat = 0x8370, + GLTFAddressModeRepeat = 0x2901, }; typedef NS_ENUM(NSInteger, GLTFComparisonFunc) { - GLTFComparisonFuncLess = 0x0201, - GLTFComparisonFuncEqual = 0x0202, - GLTFComparisonFuncLessEqual = 0x0203, - GLTFComparisonFuncGreater = 0x0204, - GLTFComparisonFuncNotEqual = 0x0205, - GLTFComparisonFuncGreaterEqual = 0x0206, - GLTFComparisonFuncAlways = 0x0207, + GLTFComparisonFuncLess = 0x0201, + GLTFComparisonFuncEqual = 0x0202, + GLTFComparisonFuncLessEqual = 0x0203, + GLTFComparisonFuncGreater = 0x0204, + GLTFComparisonFuncNotEqual = 0x0205, + GLTFComparisonFuncGreaterEqual = 0x0206, + GLTFComparisonFuncAlways = 0x0207, }; typedef NS_ENUM(NSInteger, GLTFFace) { - GLTFFaceFront = 0x0404, - GLTFFaceBack = 0x405, - GLTFFaceFrontAndBack = 0x408, + GLTFFaceFront = 0x0404, + GLTFFaceBack = 0x405, + GLTFFaceFrontAndBack = 0x408, }; typedef NS_ENUM(NSInteger, GLTFWinding) { - GLTFWindingClockwise = 0x900, - GLTFWindingCounterclockwise = 0x0901, + GLTFWindingClockwise = 0x900, + GLTFWindingCounterclockwise = 0x0901, }; typedef NS_ENUM(NSInteger, GLTFState) { - GLTFStateBlendingEnabled = 0x0BE2, - GLTFStateCullFaceEnabled = 0x0B44, - GLTFStateDepthTestEnabled = 0x0B71, - GLTFStatePolygonOffsetFillEnabled = 0x8037, - GLTFStateAlphaToCoverageEnabled = 0x809E, - GLTFStateScissorTestEnabled = 0x0C11, + GLTFStateBlendingEnabled = 0x0BE2, + GLTFStateCullFaceEnabled = 0x0B44, + GLTFStateDepthTestEnabled = 0x0B71, + GLTFStatePolygonOffsetFillEnabled = 0x8037, + GLTFStateAlphaToCoverageEnabled = 0x809E, + GLTFStateScissorTestEnabled = 0x0C11, }; typedef NS_ENUM(NSInteger, GLTFBlendFunction) { - GLTFBlendFunctionAdd = 0x8006, - GLTFBlendFunctionSubtract = 0x800A, - GLTFBlendFunctionReverseSubtract = 0x800B, + GLTFBlendFunctionAdd = 0x8006, + GLTFBlendFunctionSubtract = 0x800A, + GLTFBlendFunctionReverseSubtract = 0x800B, }; typedef NS_ENUM(NSInteger, GLTFBlendEquation) { - GLTFBlendEquationZero = 0x0000, - GLTFBlendEquationOne = 0x0001, - GLTFBlendEquationSrcColor = 0x0300, - GLTFBlendEquationOneMinusSrcColor = 0x0301, - GLTFBlendEquationSrcAlpha = 0x0302, - GLTFBlendEquationOneMinusSrcAlpha = 0x0303, - GLTFBlendEquationDestAlpha = 0x0304, - GLTFBlendEquationOneMinusDestAlpha = 0x0305, - GLTFBlendEquationDestColor = 0x0306, - GLTFBlendEquationOneMinusDestColor = 0x0307, - GLTFBlendEquationSrcAlphaSaturate = 0x0308, - GLTFBlendEquationConstantColor = 0x8001, - GLTFBlendEquationOneMinusConstColor = 0x8002, - GLTFBlendEquationConstantAlpha = 0x8003, - GLTFBlendEquationOneMinusConstAlpha = 0x8004, + GLTFBlendEquationZero = 0x0000, + GLTFBlendEquationOne = 0x0001, + GLTFBlendEquationSrcColor = 0x0300, + GLTFBlendEquationOneMinusSrcColor = 0x0301, + GLTFBlendEquationSrcAlpha = 0x0302, + GLTFBlendEquationOneMinusSrcAlpha = 0x0303, + GLTFBlendEquationDestAlpha = 0x0304, + GLTFBlendEquationOneMinusDestAlpha = 0x0305, + GLTFBlendEquationDestColor = 0x0306, + GLTFBlendEquationOneMinusDestColor = 0x0307, + GLTFBlendEquationSrcAlphaSaturate = 0x0308, + GLTFBlendEquationConstantColor = 0x8001, + GLTFBlendEquationOneMinusConstColor = 0x8002, + GLTFBlendEquationConstantAlpha = 0x8003, + GLTFBlendEquationOneMinusConstAlpha = 0x8004, }; typedef NS_ENUM(NSInteger, GLTFInterpolationMode) { - GLTFInterpolationModeStep, - GLTFInterpolationModeLinear, - GLTFInterpolationModeCubic, + GLTFInterpolationModeStep, + GLTFInterpolationModeLinear, + GLTFInterpolationModeCubic, }; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.m b/platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.m rename to platform/darwin/src/gltf/gltfkit/GLTFExtensionNames.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFImage.h b/platform/darwin/src/gltf/gltfkit/GLTFImage.h index ce444daff38..fe621ff196b 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFImage.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFImage.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFBufferView.h" +#import "GLTFObject.h" #import @@ -24,13 +24,13 @@ NS_ASSUME_NONNULL_BEGIN @interface GLTFImage : GLTFObject /// A reference to a buffer view containing image data, if url is nil -@property (nonatomic, strong) GLTFBufferView * _Nullable bufferView; +@property (nonatomic, strong) GLTFBufferView *_Nullable bufferView; /// The MIME type of the data contained in this image's buffer view -@property (nonatomic, copy) NSString * _Nullable mimeType; +@property (nonatomic, copy) NSString *_Nullable mimeType; /// A file URL, if the URI was not a decodable data-uri; otherwise nil -@property (nonatomic, copy) NSURL * _Nullable url; +@property (nonatomic, copy) NSURL *_Nullable url; /// A data object containing the data encoded in the image's data-uri, if present; otherwise nil @property (nonatomic, strong) NSData *imageData; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFImage.m b/platform/darwin/src/gltf/gltfkit/GLTFImage.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFImage.m rename to platform/darwin/src/gltf/gltfkit/GLTFImage.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.h b/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.h index 3848b78488b..9139bacf582 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.h @@ -19,10 +19,10 @@ #import typedef NS_ENUM(NSInteger, GLTFKHRLightType) { - GLTFKHRLightTypeAmbient, - GLTFKHRLightTypeDirectional, - GLTFKHRLightTypePoint, - GLTFKHRLightTypeSpot, + GLTFKHRLightTypeAmbient, + GLTFKHRLightTypeDirectional, + GLTFKHRLightTypePoint, + GLTFKHRLightTypeSpot, }; @interface GLTFKHRLight : GLTFObject diff --git a/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.m b/platform/darwin/src/gltf/gltfkit/GLTFKHRLight.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFKHRLight.m rename to platform/darwin/src/gltf/gltfkit/GLTFKHRLight.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.h b/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.h index fe422fe80ec..07abe678380 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.h @@ -14,20 +14,20 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFBuffer.h" -#import "GLTFBufferAllocator.h" #import #import +#import "GLTFBuffer.h" +#import "GLTFBufferAllocator.h" NS_ASSUME_NONNULL_BEGIN -@interface GLTFMTLBuffer : NSObject +@interface GLTFMTLBuffer : NSObject @property (nonatomic, readonly) id buffer; @end -@interface GLTFMTLBufferAllocator : NSObject +@interface GLTFMTLBufferAllocator : NSObject - (instancetype)initWithDevice:(id)device; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLBufferAllocator.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.h b/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.h index 4e35d6a9f47..4c664894ad7 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.h @@ -27,12 +27,13 @@ NS_ASSUME_NONNULL_BEGIN @interface GLTFMTLShaderBuilder : NSObject -- (id)renderPipelineStateForSubmesh:(GLTFSubmesh *)submesh - // lightingEnvironment:(GLTFMTLLightingEnvironment * _Nullable)lightingEnvironment - colorPixelFormat:(MTLPixelFormat)colorPixelFormat - depthStencilPixelFormat:(MTLPixelFormat)depthStencilPixelFormat - sampleCount:(int)sampleCount - device:(id)device; +- (id) + renderPipelineStateForSubmesh:(GLTFSubmesh *)submesh + // lightingEnvironment:(GLTFMTLLightingEnvironment * _Nullable)lightingEnvironment + colorPixelFormat:(MTLPixelFormat)colorPixelFormat + depthStencilPixelFormat:(MTLPixelFormat)depthStencilPixelFormat + sampleCount:(int)sampleCount + device:(id)device; @end diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLShaderBuilder.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.h b/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.h index 48682d2f058..286838dda5f 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.h @@ -14,7 +14,6 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // - #import NS_ASSUME_NONNULL_BEGIN @@ -25,8 +24,12 @@ extern NSString *const GLTFMTLTextureLoaderOptionSRGB; @interface GLTFMTLTextureLoader : NSObject - (instancetype)initWithDevice:(id)device; -- (id _Nullable)newTextureWithContentsOfURL:(NSURL *)url options:(NSDictionary * _Nullable)options error:(NSError **)error; -- (id _Nullable)newTextureWithData:(NSData *)data options:(NSDictionary * _Nullable)options error:(NSError **)error; +- (id _Nullable)newTextureWithContentsOfURL:(NSURL *)url + options:(NSDictionary *_Nullable)options + error:(NSError **)error; +- (id _Nullable)newTextureWithData:(NSData *)data + options:(NSDictionary *_Nullable)options + error:(NSError **)error; @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.mm similarity index 97% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.mm index ba6f8eb1e04..95c113d17c1 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLTextureLoader.mm @@ -77,7 +77,7 @@ vImageConverter_Release(converter); CFRelease(srcData); - return dstPixels; + return (__fp16*)dstPixels; } unsigned char *GLTFMTLConvertImageToRGBA8U(CGImageRef image) @@ -108,7 +108,7 @@ .bitsPerComponent = sizeof(unsigned char) * 8, .bitsPerPixel = sizeof(unsigned char) * 8 * 4, .colorSpace = dstColorSpace, - .bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaLast + .bitmapInfo = (CGBitmapInfo)kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaLast }; vImage_Error error = kvImageNoError; @@ -138,7 +138,7 @@ vImageConverter_Release(converter); CFRelease(srcData); - return dstPixels; + return (unsigned char*)dstPixels; } @interface GLTFMTLTextureLoader () @@ -201,7 +201,7 @@ - (instancetype)initWithDevice:(id)device { height:height mipmapped:mipmapped]; - id texture = [self newTextureWithBytes:dstBytes + id texture = [self newTextureWithBytes:(const unsigned char*)dstBytes bytesPerRow:bytesPerRow descriptor:descriptor options:options diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.h b/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.h index 9764472aafd..774e113d4c5 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.h @@ -25,7 +25,6 @@ NS_ASSUME_NONNULL_BEGIN extern "C" { #endif - extern MTLPrimitiveType GLTFMTLPrimitiveTypeForPrimitiveType(GLTFPrimitiveType gltfType); extern MTLBlendOperation GLTFMTLBlendOperationForBlendFunction(GLTFBlendFunction f); @@ -44,9 +43,11 @@ extern MTLSamplerMipFilter GLTFMTLSamplerMipFilterForSamplingFilter(GLTFSampling extern MTLSamplerAddressMode GLTFMTLSamplerAddressModeForSamplerAddressMode(GLTFAddressMode mode); -extern NSString *GLTFMTLTypeNameForType(GLTFDataType baseType, GLTFDataDimension dimension, BOOL packedIfPossible); +extern NSString *GLTFMTLTypeNameForType(GLTFDataType baseType, GLTFDataDimension dimension, + BOOL packedIfPossible); -extern MTLVertexFormat GLTFMTLVertexFormatForComponentTypeAndDimension(GLTFDataType baseType, GLTFDataDimension dimension); +extern MTLVertexFormat GLTFMTLVertexFormatForComponentTypeAndDimension(GLTFDataType baseType, + GLTFDataDimension dimension); #ifdef __cplusplus } diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.m b/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.mm similarity index 98% rename from platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.m rename to platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.mm index 182067e1b40..1dc446902fb 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFMTLUtilities.mm @@ -29,11 +29,12 @@ MTLPrimitiveType GLTFMTLPrimitiveTypeForPrimitiveType(GLTFPrimitiveType gltfType case GLTFPrimitiveTypeTriangleStrip: return MTLPrimitiveTypeTriangleStrip; - // Not supported; need to duplicate first element and restitch into tri strip, respectively + // Not supported; need to duplicate first element and restitch into tri strip, respectively case GLTFPrimitiveTypeLineLoop: case GLTFPrimitiveTypeTriangleFan: default: - return -1; + NSLog(@"Unsupported primitive type function %d", (int)gltfType); + return MTLPrimitiveTypePoint; } } diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMaterial.h b/platform/darwin/src/gltf/gltfkit/GLTFMaterial.h index 92f1d29b4ff..cc8a889ab82 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMaterial.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFMaterial.h @@ -24,9 +24,9 @@ NS_ASSUME_NONNULL_BEGIN @class GLTFParameter; typedef NS_ENUM(NSInteger, GLTFAlphaMode) { - GLTFAlphaModeOpaque, - GLTFAlphaModeMask, - GLTFAlphaModeBlend, + GLTFAlphaModeOpaque, + GLTFAlphaModeMask, + GLTFAlphaModeBlend, }; @interface GLTFMaterial : GLTFObject @@ -38,23 +38,27 @@ typedef NS_ENUM(NSInteger, GLTFAlphaMode) { @property (nonatomic, assign) float occlusionStrength; @property (nonatomic, assign) simd_float3 emissiveFactor; -@property (nonatomic, assign) float glossinessFactor; // Only used by KHR_materials_pbrSpecularGlossiness extension -@property (nonatomic, assign) simd_float3 specularFactor; // Only used by KHR_materials_pbrSpecularGlossiness extension +@property (nonatomic, assign) + float glossinessFactor; // Only used by KHR_materials_pbrSpecularGlossiness extension +@property (nonatomic, assign) + simd_float3 specularFactor; // Only used by KHR_materials_pbrSpecularGlossiness extension -@property (nonatomic, strong) GLTFTextureInfo * _Nullable baseColorTexture; -@property (nonatomic, strong) GLTFTextureInfo * _Nullable metallicRoughnessTexture; -@property (nonatomic, strong) GLTFTextureInfo * _Nullable normalTexture; -@property (nonatomic, strong) GLTFTextureInfo * _Nullable emissiveTexture; -@property (nonatomic, strong) GLTFTextureInfo * _Nullable occlusionTexture; +@property (nonatomic, strong) GLTFTextureInfo* _Nullable baseColorTexture; +@property (nonatomic, strong) GLTFTextureInfo* _Nullable metallicRoughnessTexture; +@property (nonatomic, strong) GLTFTextureInfo* _Nullable normalTexture; +@property (nonatomic, strong) GLTFTextureInfo* _Nullable emissiveTexture; +@property (nonatomic, strong) GLTFTextureInfo* _Nullable occlusionTexture; -@property (nonatomic, assign) BOOL hasTextureTransforms; // Only used when KHR_texture_transform extension is present +@property (nonatomic, assign) + BOOL hasTextureTransforms; // Only used when KHR_texture_transform extension is present @property (nonatomic, assign, getter=isDoubleSided) BOOL doubleSided; @property (nonatomic, assign) GLTFAlphaMode alphaMode; -@property (nonatomic, assign) float alphaCutoff; // Only used when `alphaMode` == GLTFAlphaModeMask +@property (nonatomic, assign) float alphaCutoff; // Only used when `alphaMode` == GLTFAlphaModeMask -@property (nonatomic, assign, getter=isUnlit) BOOL unlit; // Only used when KHR_materials_unlit extension is present +@property (nonatomic, assign, getter=isUnlit) + BOOL unlit; // Only used when KHR_materials_unlit extension is present @end diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMaterial.m b/platform/darwin/src/gltf/gltfkit/GLTFMaterial.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMaterial.m rename to platform/darwin/src/gltf/gltfkit/GLTFMaterial.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMesh.h b/platform/darwin/src/gltf/gltfkit/GLTFMesh.h index 3bf40f62d25..19d4ea6f9ee 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFMesh.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFMesh.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" NS_ASSUME_NONNULL_BEGIN diff --git a/platform/darwin/src/gltf/gltfkit/GLTFMesh.m b/platform/darwin/src/gltf/gltfkit/GLTFMesh.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFMesh.m rename to platform/darwin/src/gltf/gltfkit/GLTFMesh.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFNode.h b/platform/darwin/src/gltf/gltfkit/GLTFNode.h index 3863bb90913..f370d029909 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFNode.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFNode.h @@ -14,32 +14,32 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // +#import +#import "GLTFNodeVisitor.h" #import "GLTFObject.h" #import "GLTFUtilities.h" -#import "GLTFNodeVisitor.h" -#import NS_ASSUME_NONNULL_BEGIN - @class GLTFCamera, GLTFSkin, GLTFMesh; @class GLTFKHRLight; @interface GLTFNode : GLTFObject -@property (nonatomic, weak) GLTFCamera * _Nullable camera; -@property (nonatomic, weak) GLTFKHRLight * _Nullable light; -@property (nonatomic, weak) GLTFNode * _Nullable parent; +@property (nonatomic, weak) GLTFCamera *_Nullable camera; +@property (nonatomic, weak) GLTFKHRLight *_Nullable light; +@property (nonatomic, weak) GLTFNode *_Nullable parent; @property (nonatomic, copy) NSArray *children; -@property (nonatomic, weak) GLTFSkin * _Nullable skin; -@property (nonatomic, copy) NSString * _Nullable jointName; -@property (nonatomic, weak) GLTFMesh * _Nullable mesh; +@property (nonatomic, weak) GLTFSkin *_Nullable skin; +@property (nonatomic, copy) NSString *_Nullable jointName; +@property (nonatomic, weak) GLTFMesh *_Nullable mesh; @property (nonatomic, copy) NSArray *morphTargetWeights; @property (nonatomic, assign) GLTFQuaternion rotationQuaternion; @property (nonatomic, assign) simd_float3 scale; @property (nonatomic, assign) simd_float3 translation; @property (nonatomic, assign) simd_float4x4 localTransform; @property (nonatomic, readonly, assign) simd_float4x4 globalTransform; -@property (nonatomic, readonly, assign) GLTFBoundingBox approximateBounds; // axis-aligned; in local coordinates +@property (nonatomic, readonly, assign) + GLTFBoundingBox approximateBounds; // axis-aligned; in local coordinates - (void)addChildNode:(GLTFNode *)node; - (void)removeFromParent; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFNode.m b/platform/darwin/src/gltf/gltfkit/GLTFNode.mm similarity index 98% rename from platform/darwin/src/gltf/gltfkit/GLTFNode.m rename to platform/darwin/src/gltf/gltfkit/GLTFNode.mm index 52dd177fde1..2630d49960c 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFNode.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFNode.mm @@ -119,11 +119,11 @@ - (GLTFBoundingBox)approximateBounds { } - (GLTFBoundingBox)_approximateBoundsRecursive:(simd_float4x4)transform { - GLTFBoundingBox bounds = { 0 }; + GLTFBoundingBox bounds = { 0, 0 }; if (self.mesh != nil) { for (GLTFSubmesh *submesh in self.mesh.submeshes) { - GLTFBoundingBox submeshBounds = { 0 }; + GLTFBoundingBox submeshBounds = { 0, 0 }; GLTFAccessor *positionAccessor = submesh.accessorsForAttributes[GLTFAttributeSemanticPosition]; GLTFValueRange positionRange = positionAccessor.valueRange; submeshBounds.minPoint.x = positionRange.minValue[0]; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFNodeVisitor.h b/platform/darwin/src/gltf/gltfkit/GLTFNodeVisitor.h index a3bceddb5e3..ee3ce2b5de4 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFNodeVisitor.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFNodeVisitor.h @@ -20,9 +20,7 @@ NS_ASSUME_NONNULL_BEGIN @class GLTFNode; -typedef NS_ENUM(NSInteger, GLTFVisitationStrategy) { - GLTFVisitationStrategyDepthFirst -}; +typedef NS_ENUM(NSInteger, GLTFVisitationStrategy) { GLTFVisitationStrategyDepthFirst }; typedef void (^GLTFNodeVisitor)(GLTFNode *node, int depth, BOOL *stop); diff --git a/platform/darwin/src/gltf/gltfkit/GLTFObject.h b/platform/darwin/src/gltf/gltfkit/GLTFObject.h index c745d543c20..146d6c82a30 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFObject.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFObject.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol GLTFObject /// The user-defined name of this object. Need not be unique. -@property (nonatomic, copy) NSString * _Nullable name; +@property (nonatomic, copy) NSString *_Nullable name; /// Data specific to any extensions used in this document @property (nonatomic, copy) NSDictionary *extensions; /// Contains application-specific information that is passed through but not parsed @@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN /// A unique identifier for this object @property (nonatomic, readonly) NSUUID *identifier; /// The user-defined name of this object. Need not be unique. -@property (nonatomic, copy) NSString * _Nullable name; +@property (nonatomic, copy) NSString *_Nullable name; /// Data specific to any extensions used in this document @property (nonatomic, copy) NSDictionary *extensions; /// Contains application-specific information that is passed through but not parsed diff --git a/platform/darwin/src/gltf/gltfkit/GLTFObject.m b/platform/darwin/src/gltf/gltfkit/GLTFObject.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFObject.m rename to platform/darwin/src/gltf/gltfkit/GLTFObject.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFScene.h b/platform/darwin/src/gltf/gltfkit/GLTFScene.h index cf5ae848079..6abf39c6c92 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFScene.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFScene.h @@ -14,9 +14,9 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // +#import "GLTFNodeVisitor.h" #import "GLTFObject.h" #import "GLTFUtilities.h" -#import "GLTFNodeVisitor.h" NS_ASSUME_NONNULL_BEGIN @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GLTFScene : GLTFObject @property (nonatomic, copy) NSArray *nodes; -@property (nonatomic, weak) GLTFKHRLight * _Nullable ambientLight; +@property (nonatomic, weak) GLTFKHRLight *_Nullable ambientLight; @property (nonatomic, readonly, assign) GLTFBoundingBox approximateBounds; - (void)addNode:(GLTFNode *)node; diff --git a/platform/darwin/src/gltf/gltfkit/GLTFScene.m b/platform/darwin/src/gltf/gltfkit/GLTFScene.mm similarity index 97% rename from platform/darwin/src/gltf/gltfkit/GLTFScene.m rename to platform/darwin/src/gltf/gltfkit/GLTFScene.mm index 3ec31b78f08..b3f0a690127 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFScene.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFScene.mm @@ -40,7 +40,7 @@ - (void)addNode:(GLTFNode *)node { } - (GLTFBoundingBox)approximateBounds { - GLTFBoundingBox sceneBounds = { 0 }; + GLTFBoundingBox sceneBounds = { 0, 0 }; for (GLTFNode *node in self.nodes) { GLTFBoundingBox nodeBounds = node.approximateBounds; GLTFBoundingBoxUnion(&sceneBounds, nodeBounds); diff --git a/platform/darwin/src/gltf/gltfkit/GLTFSkin.m b/platform/darwin/src/gltf/gltfkit/GLTFSkin.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFSkin.m rename to platform/darwin/src/gltf/gltfkit/GLTFSkin.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFTexture.h b/platform/darwin/src/gltf/gltfkit/GLTFTexture.h index 556ab715cd4..7b7a9f97bb0 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFTexture.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFTexture.h @@ -14,11 +14,10 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" -#import "GLTFEnums.h" -#import "../GLTFMath.hpp" #import - +#import "../GLTFMath.hpp" +#import "GLTFEnums.h" +#import "GLTFObject.h" NS_ASSUME_NONNULL_BEGIN @@ -61,6 +60,4 @@ NS_ASSUME_NONNULL_BEGIN @end - NS_ASSUME_NONNULL_END - diff --git a/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.h b/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.h index a3b37249455..fbe3b026f52 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.h @@ -14,8 +14,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // -#import "GLTFObject.h" #import "GLTFEnums.h" +#import "GLTFObject.h" NS_ASSUME_NONNULL_BEGIN diff --git a/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.m b/platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.m rename to platform/darwin/src/gltf/gltfkit/GLTFTextureSampler.mm diff --git a/platform/darwin/src/gltf/gltfkit/GLTFUtilities.h b/platform/darwin/src/gltf/gltfkit/GLTFUtilities.h index b23bc221102..db7a39064ce 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFUtilities.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFUtilities.h @@ -23,44 +23,37 @@ NS_ASSUME_NONNULL_BEGIN typedef struct __attribute__((packed)) { - float x, y, z; + float x, y, z; } GLTFVector3; typedef struct __attribute__((packed)) { - float x, y, z, w; + float x, y, z, w; } GLTFVector4; typedef struct __attribute__((packed)) { - GLTFVector4 columns[4]; + GLTFVector4 columns[4]; } GLTFMatrix4; typedef simd_quatf GLTFQuaternion; - extern bool GLTFBoundingBoxIsEmpty(GLTFBoundingBox b); extern GLTFBoundingBox *GLTFBoundingBoxUnion(GLTFBoundingBox *a, GLTFBoundingBox b); extern void GLTFBoundingBoxTransform(GLTFBoundingBox *b, simd_float4x4 transform); - extern GLTFQuaternion GLTFQuaternionFromEulerAngles(float pitch, float yaw, float roll); - - - - extern simd_float3x3 GLTFMatrixUpperLeft3x3(simd_float4x4); extern simd_float4x4 GLTFNormalMatrixFromModelMatrix(simd_float4x4); - - extern GLTFDataDimension GLTFDataDimensionForName(NSString *name); extern size_t GLTFSizeOfDataType(GLTFDataType type); -extern size_t GLTFSizeOfComponentTypeWithDimension(GLTFDataType baseType, GLTFDataDimension dimension); +extern size_t GLTFSizeOfComponentTypeWithDimension(GLTFDataType baseType, + GLTFDataDimension dimension); extern NSInteger GLTFComponentCountForDimension(GLTFDataDimension dimension); diff --git a/platform/darwin/src/gltf/gltfkit/GLTFUtilities.m b/platform/darwin/src/gltf/gltfkit/GLTFUtilities.mm similarity index 99% rename from platform/darwin/src/gltf/gltfkit/GLTFUtilities.m rename to platform/darwin/src/gltf/gltfkit/GLTFUtilities.mm index effa58a0669..ecce6e6fc0b 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFUtilities.m +++ b/platform/darwin/src/gltf/gltfkit/GLTFUtilities.mm @@ -15,6 +15,7 @@ // #import "GLTFUtilities.h" +#include "GLTFEnums.h" bool GLTFBoundingBoxIsEmpty(GLTFBoundingBox b) { return (b.minPoint.x == b.maxPoint.x) && (b.minPoint.y == b.maxPoint.y) && (b.minPoint.z == b.maxPoint.z); @@ -115,7 +116,7 @@ GLTFDataDimension GLTFDataDimensionForName(NSString *name) { return GLTFDataDimensionMatrix4x4; } - return -1; + return GLTFDataDimensionUnknown; } size_t GLTFSizeOfDataType(GLTFDataType type) { diff --git a/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.h b/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.h index 4a73f93ef05..beaf2bf9d09 100644 --- a/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.h +++ b/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.h @@ -46,7 +46,7 @@ extern NSString *const GLTFAttributeSemanticMetallic; @property (nonatomic, assign) NSInteger stride; @end -@interface GLTFVertexDescriptor: NSObject +@interface GLTFVertexDescriptor : NSObject @property (nonatomic, copy) NSArray *attributes; @property (nonatomic, copy) NSArray *bufferLayouts; @end diff --git a/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.m b/platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.mm similarity index 100% rename from platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.m rename to platform/darwin/src/gltf/gltfkit/GLTFVertexDescriptor.mm diff --git a/platform/macos/src/MLNMapView+Impl.h b/platform/macos/src/MLNMapView+Impl.h index bb66a2966fb..18868475e27 100644 --- a/platform/macos/src/MLNMapView+Impl.h +++ b/platform/macos/src/MLNMapView+Impl.h @@ -2,6 +2,8 @@ #import #import +#import "MLNBackendResource.h" + @class MLNMapView; typedef struct _CGLContextObject* CGLContextObj; @@ -23,6 +25,8 @@ class MLNMapViewImpl : public mbgl::MapObserver { // Called by the view delegate when it's time to render. void render(); + virtual MLNBackendResource getObject() = 0; + // mbgl::MapObserver implementation void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) override; void onCameraIsChanging() override; diff --git a/platform/macos/src/MLNMapView+Metal.h b/platform/macos/src/MLNMapView+Metal.h index f6d12e66c60..a366e38a1ba 100644 --- a/platform/macos/src/MLNMapView+Metal.h +++ b/platform/macos/src/MLNMapView+Metal.h @@ -37,6 +37,8 @@ class MLNMapViewMetalImpl final : public MLNMapViewImpl, mbgl::PremultipliedImage readStillImage() override; + MLNBackendResource getObject() override; + private: bool presentsWithTransaction = false; }; diff --git a/platform/macos/src/MLNMapView+Metal.mm b/platform/macos/src/MLNMapView+Metal.mm index 6628d85cb28..e0f8abe6c3b 100644 --- a/platform/macos/src/MLNMapView+Metal.mm +++ b/platform/macos/src/MLNMapView+Metal.mm @@ -158,3 +158,14 @@ void swap() override { // return readFramebuffer(mapView.framebufferSize); // TODO: RendererBackend::readFramebuffer return {}; } + +MLNBackendResource MLNMapViewMetalImpl::getObject() { + auto& resource = getResource(); + auto renderPassDescriptor = resource.getRenderPassDescriptor().get(); + return { + resource.mtlView, + resource.mtlView.device, + [MTLRenderPassDescriptor renderPassDescriptor], + resource.commandBuffer + }; +} \ No newline at end of file diff --git a/platform/macos/src/MLNMapView+OpenGL.h b/platform/macos/src/MLNMapView+OpenGL.h index fb882b7072b..2daf3aaab9d 100644 --- a/platform/macos/src/MLNMapView+OpenGL.h +++ b/platform/macos/src/MLNMapView+OpenGL.h @@ -38,4 +38,6 @@ class MLNMapViewOpenGLImpl final : public MLNMapViewImpl, mbgl::PremultipliedImage readStillImage() override; CGLContextObj getCGLContextObj() override; + + MLNBackendResource getObject() override; }; diff --git a/platform/macos/src/MLNMapView+OpenGL.mm b/platform/macos/src/MLNMapView+OpenGL.mm index de747afbcd3..83409e00a35 100644 --- a/platform/macos/src/MLNMapView+OpenGL.mm +++ b/platform/macos/src/MLNMapView+OpenGL.mm @@ -87,3 +87,7 @@ void bind() override { MLNOpenGLLayer* layer = (MLNOpenGLLayer*)mapView.layer; return layer.openGLContext.CGLContextObj; } + +MLNBackendResource MLNMapViewOpenGLImpl::getObject() { + return MLNBackendResource(); +} \ No newline at end of file diff --git a/platform/macos/src/MLNMapView.h b/platform/macos/src/MLNMapView.h index d3db2ea6f98..42f93147f79 100644 --- a/platform/macos/src/MLNMapView.h +++ b/platform/macos/src/MLNMapView.h @@ -2,6 +2,7 @@ #import #import +#import "MLNBackendResource.h" #import "MLNFoundation.h" #import "MLNGeometry.h" #import "MLNStyle.h" @@ -1270,6 +1271,7 @@ around the returned camera object if it were set as the receiver’s camera. */ @property (nonatomic) MLNMapDebugMaskOptions debugMask; +- (MLNBackendResource)backendResource; @end NS_ASSUME_NONNULL_END diff --git a/platform/macos/src/MLNMapView.mm b/platform/macos/src/MLNMapView.mm index c8d54085e18..657b1ec37a4 100644 --- a/platform/macos/src/MLNMapView.mm +++ b/platform/macos/src/MLNMapView.mm @@ -3083,4 +3083,8 @@ - (void)setDebugMask:(MLNMapDebugMaskOptions)debugMask { _mbglMap->setDebug(options); } +- (MLNBackendResource)backendResource { + return _mbglView->getObject(); +} + @end diff --git a/src/mbgl/style/layers/custom_layer_render_parameters.cpp b/src/mbgl/style/layers/custom_layer_render_parameters.cpp index 4541234ad82..789097ee1ea 100644 --- a/src/mbgl/style/layers/custom_layer_render_parameters.cpp +++ b/src/mbgl/style/layers/custom_layer_render_parameters.cpp @@ -18,7 +18,7 @@ CustomLayerRenderParameters::CustomLayerRenderParameters(const mbgl::PaintParame mat4 projMatrix; state.getProjMatrix(projMatrix); projectionMatrix = projMatrix; - + const TransformParameters& params = paintParameters.transformParams; nearClippedProjMatrix = params.nearClippedProjMatrix; }