Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge filament basic render infrastructure #9

Merged
merged 42 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cc3eb54
create engine + createRenderer
hannojg Feb 23, 2024
0f7de42
format cpp
hannojg Feb 23, 2024
87a2ebb
create camera
hannojg Feb 23, 2024
7562bf3
scene + camera + view scaffolding
hannojg Feb 23, 2024
8064705
wip: asset loading
hannojg Feb 23, 2024
84ddaf3
wip: create default light + add entity to scene
hannojg Feb 23, 2024
1f35415
wip
hannojg Feb 23, 2024
7588a0d
use getter camera
hannojg Feb 23, 2024
4be6e4c
Merge branch 'main' of github.com:margelo/react-native-filament into …
hannojg Feb 23, 2024
6e3b6eb
using new reference heuristics
hannojg Feb 23, 2024
6794753
wip: adding missing types
hannojg Feb 23, 2024
2c109ac
setup swap chain
hannojg Feb 23, 2024
88b8a4c
cleanup
hannojg Feb 23, 2024
7b0ca1a
implemented renderer methods
hannojg Feb 23, 2024
628084c
cleanup
hannojg Feb 23, 2024
639249b
implemented camera manipulator
hannojg Feb 23, 2024
7dbbebf
safe guard code + make internal private
hannojg Feb 24, 2024
2026812
cleanup listener
hannojg Feb 26, 2024
23ad358
restructure, create everything in the EngineWrapper
hannojg Feb 27, 2024
f1118e0
new render implementation
hannojg Feb 27, 2024
5ff5f8c
cleanup
hannojg Feb 27, 2024
73ef9f9
remove choreographer listener
hannojg Feb 27, 2024
a62bb78
export the types
hannojg Feb 27, 2024
949656a
fix: Disable source builds for iOS
mrousavy Feb 27, 2024
3bd1f07
Remove `filament` source lib from `ios`
mrousavy Feb 27, 2024
c72e4a1
Update FilamentView.java
mrousavy Feb 27, 2024
13c337c
Merge branch 'main' of github.com:margelo/react-native-filament into …
hannojg Feb 27, 2024
05829a4
check-all
hannojg Feb 27, 2024
4f31f90
Update package/cpp/core/EngineWrapper.cpp
hannojg Feb 27, 2024
fede57d
Update package/cpp/core/RendererWrapper.cpp
hannojg Feb 27, 2024
363c423
Update package/cpp/core/RendererWrapper.cpp
hannojg Feb 27, 2024
e2f46d6
Update package/cpp/core/RendererWrapper.cpp
hannojg Feb 27, 2024
826ba3d
comment manipulator
hannojg Feb 28, 2024
9ca913a
remove todo, add comment
hannojg Feb 28, 2024
b9a40c8
remove empty decl
hannojg Feb 28, 2024
61fa84e
Update package/cpp/core/EngineWrapper.cpp
hannojg Feb 28, 2024
47b637b
clean
hannojg Feb 28, 2024
4c599dd
name values
hannojg Feb 28, 2024
1bad969
remove unnecessary check
hannojg Feb 28, 2024
07ca08e
remove unnecessary check
hannojg Feb 28, 2024
0de95a7
fix swap chain wrapper
hannojg Feb 28, 2024
4b96738
cleanup
hannojg Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# OSX
#
.DS_Store
.vscode
34 changes: 24 additions & 10 deletions package/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ find_library(LOG_LIB log)
add_library(
${PACKAGE_NAME}
SHARED

# Shared C++
../cpp/FilamentView.cpp
../cpp/FilamentProxy.cpp
Expand All @@ -26,8 +27,20 @@ add_library(
../cpp/Listener.cpp
../cpp/jsi/HybridObject.cpp
../cpp/jsi/Promise.cpp
../cpp/core/EngineWrapper.cpp
../cpp/test/TestHybridObject.cpp

# Filament Core
../cpp/core/EngineWrapper.cpp
../cpp/core/RendererWrapper.cpp
../cpp/core/SceneWrapper.cpp
../cpp/core/CameraWrapper.cpp
../cpp/core/ViewWrapper.cpp
../cpp/core/SwapChainWrapper.cpp

# Filament Utils
../cpp/core/utils/EntityWrapper.cpp
../cpp/core/utils/ManipulatorWrapper.cpp

# Java JNI
src/main/cpp/AndroidFilamentProxy.cpp
src/main/cpp/AndroidSurface.cpp
Expand Down Expand Up @@ -56,19 +69,20 @@ target_include_directories(
# Link everything together
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB} # <-- Logcat logger
android # <-- Android JNI core
ReactAndroid::jsi # <-- RN: JSI
ReactAndroid::reactnativejni # <-- RN: React Native JNI bindings
fbjni::fbjni # <-- fbjni
GLESv3 # <-- OpenGL (Core)
EGL # <-- OpenGL (EGL)
${LOG_LIB} # <-- Logcat logger
android # <-- Android JNI core
ReactAndroid::jsi # <-- RN: JSI
ReactAndroid::reactnativejni # <-- RN: React Native JNI bindings
fbjni::fbjni # <-- fbjni
GLESv3 # <-- OpenGL (Core)
EGL # <-- OpenGL (EGL)
)

# Filament (local CMake project as a git submodule)
message("RN Filament: Adding pre-compiled libraries in ${FILAMENT_DIR}...")
file(GLOB FILAMENT_LIBRARIES "${FILAMENT_DIR}/lib/${ANDROID_ABI}/*.a")

foreach(file ${FILAMENT_LIBRARIES})
message("RN Filament: Linking ${file}...")
target_link_libraries(${PACKAGE_NAME} ${file})
message("RN Filament: Linking ${file}...")
target_link_libraries(${PACKAGE_NAME} ${file})
endforeach()
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;
import android.util.AttributeSet;

import android.view.Choreographer;
import android.view.SurfaceView;
import android.view.View;

Expand All @@ -22,16 +23,26 @@ public class FilamentView extends SurfaceView {
public FilamentView(Context context) {
super(context);
mHybridData = initHybrid(new SurfaceProvider(getHolder()));
setupView();
}

public FilamentView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mHybridData = initHybrid(new SurfaceProvider(getHolder()));
setupView();
}

public FilamentView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mHybridData = initHybrid(new SurfaceProvider(getHolder()));
setupView();
}

public void setupView() {
// Support transparent background
this.setZOrderOnTop(true);
// Disable overflow
this.setClipToOutline(true);
}

private native HybridData initHybrid(SurfaceProvider surfaceProvider);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.margelo.filament;

import android.graphics.PixelFormat;
import android.view.Choreographer;
import android.view.SurfaceHolder;

import androidx.annotation.Keep;
Expand All @@ -17,6 +19,8 @@ public class SurfaceProvider {

SurfaceProvider(SurfaceHolder holder) {
mHybridData = initHybrid();
// Support transparent background
holder.setFormat(PixelFormat.TRANSLUCENT);
holder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
Expand Down
13 changes: 9 additions & 4 deletions package/cpp/FilamentProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ namespace margelo {

using namespace facebook;

std::shared_ptr<TestHybridObject> FilamentProxy::createTestObject() {
return std::make_shared<TestHybridObject>();
}

void FilamentProxy::loadHybridMethods() {
registerHybridMethod("loadModel", &FilamentProxy::loadModel, this);
registerHybridMethod("findFilamentView", &FilamentProxy::findFilamentView, this);
registerHybridMethod("createTestObject", &FilamentProxy::createTestObject, this);
registerHybridMethod("createEngine", &FilamentProxy::createEngine, this);
registerHybridMethod("createChoreographer", &FilamentProxy::createChoreographer, this);
}

std::shared_ptr<TestHybridObject> FilamentProxy::createTestObject() {
return std::make_shared<TestHybridObject>();
}

std::shared_ptr<EngineWrapper> FilamentProxy::createEngine() {
return std::make_shared<EngineWrapper>(createChoreographer());
hannojg marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace margelo
7 changes: 7 additions & 0 deletions package/cpp/FilamentProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#pragma once

#include <jsi/jsi.h>

#include <core/EngineWrapper.h>
#include <string>
#include <vector>

Expand All @@ -24,8 +27,12 @@ class FilamentProxy : public HybridObject {
virtual std::shared_ptr<FilamentView> findFilamentView(int id) = 0;
virtual std::shared_ptr<Choreographer> createChoreographer() = 0;

// For testing
std::shared_ptr<TestHybridObject> createTestObject();

// Public API
std::shared_ptr<EngineWrapper> createEngine();

public:
virtual jsi::Runtime& getRuntime() = 0;
virtual std::shared_ptr<react::CallInvoker> getCallInvoker() = 0;
Expand Down
1 change: 1 addition & 0 deletions package/cpp/SurfaceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SurfaceProvider : public HybridObject {
void onSurfaceCreated(std::shared_ptr<Surface> surface);
void onSurfaceChanged(std::shared_ptr<Surface> surface, int width, int height);
void onSurfaceDestroyed(std::shared_ptr<Surface> surface);
void render(float frameTimeNanos);

private:
ListenerManager<Callback> _listeners;
Expand Down
15 changes: 15 additions & 0 deletions package/cpp/core/CameraWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "CameraWrapper.h"

void margelo::CameraWrapper::loadHybridMethods() {
registerHybridMethod("lookAt", &CameraWrapper::lookAt, this);
}

void margelo::CameraWrapper::lookAt(std::shared_ptr<ManipulatorWrapper> cameraManipulator) {
if (!cameraManipulator) {
throw std::invalid_argument("CameraManipulator is null");
}

math::float3 eye, center, up;
cameraManipulator->getManipulator()->getLookAt(&eye, &center, &up);
_camera->lookAt({eye[0], eye[1], eye[2]}, {center[0], center[1], center[2]}, {up[0], up[1], up[2]});
}
28 changes: 28 additions & 0 deletions package/cpp/core/CameraWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "jsi/HybridObject.h"

#include "utils/ManipulatorWrapper.h"
#include <filament/Camera.h>

namespace margelo {
using namespace filament;

class CameraWrapper : public HybridObject {
public:
explicit CameraWrapper(const std::shared_ptr<Camera>& camera) : _camera(std::move(camera)) {}

void loadHybridMethods() override;

const std::shared_ptr<Camera>& getCamera() {
return _camera;
}

private:
std::shared_ptr<Camera> _camera;

private:
// Convenience methods
void lookAt(std::shared_ptr<ManipulatorWrapper> cameraManipulator);
};
} // namespace margelo
Loading