From 2f61810ebfea4e621a27d63ba5e7dde940894a18 Mon Sep 17 00:00:00 2001 From: feiy Date: Thu, 21 Dec 2023 11:11:33 +0800 Subject: [PATCH] Restructured V8 bindings. --- QGameDev/XMLEditor.cpp | 4 +- QGamePlayer/PlayerWindow.cpp | 4 +- Test.V8/Test.V8.vcxproj | 31 +- Test.V8/Test.V8.vcxproj.filters | 6 +- Test.V8/main.cpp | 2 +- Three.V8.sln | 52 +- Three.V8/DefaultModule.cpp | 302 +++++++++ Three.V8/DefaultModule.h | 6 + Three.V8/GamePlayer.cpp | 132 ++-- Three.V8/GamePlayer.h | 10 +- Three.V8/Three.V8.vcxproj | 264 +++++--- Three.V8/Three.V8.vcxproj.filters | 589 +++++++++++++----- Three.V8/Three.V8.vcxproj.user | 2 +- .../{GamePlayer.hpp => WrapperGamePlayer.cpp} | 71 ++- Three.V8/WrapperGamePlayer.h | 30 + Three.V8/WrapperUtils.hpp | 53 +- Three.V8/backgrounds/Background.hpp | 255 -------- Three.V8/backgrounds/WrapperBackground.cpp | 195 ++++++ Three.V8/backgrounds/WrapperBackground.h | 54 ++ ...ndScene.hpp => WrapperBackgroundScene.cpp} | 58 +- Three.V8/backgrounds/WrapperBackgroundScene.h | 25 + Three.V8/binding.cpp | 553 ++++++---------- Three.V8/binding.h | 74 +-- Three.V8/cameras/Camera.hpp | 98 --- Three.V8/cameras/WrapperCamera.cpp | 87 +++ Three.V8/cameras/WrapperCamera.h | 23 + ...amera.hpp => WrapperPerspectiveCamera.cpp} | 66 +- Three.V8/cameras/WrapperPerspectiveCamera.h | 28 + .../{Reflector.hpp => WrapperReflector.cpp} | 67 +- Three.V8/cameras/WrapperReflector.h | 24 + ...hpp => WrapperBoundingVolumeHierarchy.cpp} | 102 ++- .../core/WrapperBoundingVolumeHierarchy.h | 27 + .../{Object3D.hpp => WrapperObject3D.cpp} | 292 +++------ Three.V8/core/WrapperObject3D.h | 93 +++ Three.V8/definitions.hpp | 62 ++ Three.V8/gui/UIBlock.hpp | 96 --- Three.V8/gui/UIPanel.hpp | 64 -- .../{UI3DViewer.hpp => WrapperUI3DViewer.cpp} | 133 ++-- Three.V8/gui/WrapperUI3DViewer.h | 53 ++ .../gui/{UIArea.hpp => WrapperUIArea.cpp} | 103 +-- Three.V8/gui/WrapperUIArea.h | 37 ++ Three.V8/gui/WrapperUIBlock.cpp | 89 +++ Three.V8/gui/WrapperUIBlock.h | 19 + .../gui/{UIButton.hpp => WrapperUIButton.cpp} | 71 +-- Three.V8/gui/WrapperUIButton.h | 23 + ...UIDraggable.hpp => WrapperUIDraggable.cpp} | 102 ++- Three.V8/gui/WrapperUIDraggable.h | 35 ++ .../{UIElement.hpp => WrapperUIElement.cpp} | 70 +-- Three.V8/gui/WrapperUIElement.h | 30 + .../gui/{UIImage.hpp => WrapperUIImage.cpp} | 63 +- Three.V8/gui/WrapperUIImage.h | 21 + .../{UILineEdit.hpp => WrapperUILineEdit.cpp} | 65 +- Three.V8/gui/WrapperUILineEdit.h | 22 + .../{UIManager.hpp => WrapperUIManager.cpp} | 49 +- Three.V8/gui/WrapperUIManager.h | 18 + Three.V8/gui/WrapperUIPanel.cpp | 55 ++ Three.V8/gui/WrapperUIPanel.h | 15 + ...llViewer.hpp => WrapperUIScrollViewer.cpp} | 79 +-- Three.V8/gui/WrapperUIScrollViewer.h | 32 + .../gui/{UIText.hpp => WrapperUIText.cpp} | 50 +- Three.V8/gui/WrapperUIText.h | 15 + ...UITextBlock.hpp => WrapperUITextBlock.cpp} | 45 +- Three.V8/gui/WrapperUITextBlock.h | 15 + Three.V8/lights/AmbientLight.hpp | 91 --- Three.V8/lights/WrapperAmbientLight.cpp | 78 +++ Three.V8/lights/WrapperAmbientLight.h | 21 + ...lLight.hpp => WrapperDirectionalLight.cpp} | 77 +-- Three.V8/lights/WrapperDirectionalLight.h | 28 + ...nmentMap.hpp => WrapperEnvironmentMap.cpp} | 36 +- Three.V8/lights/WrapperEnvironmentMap.h | 16 + ...r.hpp => WrapperEnvironmentMapCreator.cpp} | 47 +- .../lights/WrapperEnvironmentMapCreator.h | 18 + ...reLight.hpp => WrapperHemisphereLight.cpp} | 62 +- Three.V8/lights/WrapperHemisphereLight.h | 26 + ...rectLight.hpp => WrapperIndirectLight.cpp} | 62 +- Three.V8/lights/WrapperIndirectLight.h | 35 ++ ...DProbeGrid.hpp => WrapperLODProbeGrid.cpp} | 101 +-- Three.V8/lights/WrapperLODProbeGrid.h | 41 ++ ...dget.hpp => WrapperLODProbeGridWidget.cpp} | 75 +-- Three.V8/lights/WrapperLODProbeGridWidget.h | 29 + .../lights/{Light.hpp => WrapperLight.cpp} | 76 +-- Three.V8/lights/WrapperLight.h | 35 ++ .../{ProbeGrid.hpp => WrapperProbeGrid.cpp} | 96 +-- Three.V8/lights/WrapperProbeGrid.h | 40 ++ ...dWidget.hpp => WrapperProbeGridWidget.cpp} | 76 +-- Three.V8/lights/WrapperProbeGridWidget.h | 27 + ...geLoader.hpp => WrapperDDSImageLoader.cpp} | 25 +- Three.V8/loaders/WrapperDDSImageLoader.h | 15 + .../{FileLoader.hpp => WrapperFileLoader.cpp} | 27 +- Three.V8/loaders/WrapperFileLoader.h | 16 + .../{GLTFLoader.hpp => WrapperGLTFLoader.cpp} | 36 +- Three.V8/loaders/WrapperGLTFLoader.h | 16 + ...geLoader.hpp => WrapperHDRImageLoader.cpp} | 57 +- Three.V8/loaders/WrapperHDRImageLoader.h | 17 + ...ImageLoader.hpp => WrapperImageLoader.cpp} | 48 +- Three.V8/loaders/WrapperImageLoader.h | 17 + ...ader.hpp => WrapperLODProbeGridLoader.cpp} | 24 +- Three.V8/loaders/WrapperLODProbeGridLoader.h | 15 + ...dLoader.hpp => WrapperProbeGridLoader.cpp} | 26 +- Three.V8/loaders/WrapperProbeGridLoader.h | 13 + Three.V8/models/HeightField.hpp | 60 -- ...ionMixer.hpp => WrapperAnimationMixer.cpp} | 81 +-- Three.V8/models/WrapperAnimationMixer.h | 31 + .../{GLTFModel.hpp => WrapperGLTFModel.cpp} | 134 ++-- Three.V8/models/WrapperGLTFModel.h | 44 ++ Three.V8/models/WrapperHeightField.cpp | 41 ++ Three.V8/models/WrapperHeightField.h | 18 + ...SimpleModel.hpp => WrapperSimpleModel.cpp} | 86 +-- Three.V8/models/WrapperSimpleModel.h | 31 + Three.V8/multimedia/AVCPlayer.hpp | 81 --- Three.V8/multimedia/MMCamera.hpp | 71 --- Three.V8/multimedia/MMLazyVideo.hpp | 147 ----- Three.V8/multimedia/OpusPlayer.hpp | 59 -- Three.V8/multimedia/WrapperAVCPlayer.cpp | 70 +++ Three.V8/multimedia/WrapperAVCPlayer.h | 22 + ...AVCRecorder.hpp => WrapperAVCRecorder.cpp} | 69 +- Three.V8/multimedia/WrapperAVCRecorder.h | 19 + .../{MMAudio.hpp => WrapperMMAudio.cpp} | 78 +-- Three.V8/multimedia/WrapperMMAudio.h | 27 + Three.V8/multimedia/WrapperMMCamera.cpp | 64 ++ Three.V8/multimedia/WrapperMMCamera.h | 20 + Three.V8/multimedia/WrapperMMLazyVideo.cpp | 127 ++++ Three.V8/multimedia/WrapperMMLazyVideo.h | 28 + .../{MMVideo.hpp => WrapperMMVideo.cpp} | 83 ++- Three.V8/multimedia/WrapperMMVideo.h | 28 + Three.V8/multimedia/WrapperOpusPlayer.cpp | 47 ++ Three.V8/multimedia/WrapperOpusPlayer.h | 17 + ...usRecorder.hpp => WrapperOpusRecorder.cpp} | 73 +-- Three.V8/multimedia/WrapperOpusRecorder.h | 19 + .../{HttpClient.hpp => WrapperHttpClient.cpp} | 45 +- Three.V8/network/WrapperHttpClient.h | 16 + .../{WSClient.hpp => WrapperWSClient.cpp} | 81 +-- Three.V8/network/WrapperWSClient.h | 24 + Three.V8/renderers/CubeRenderTarget.hpp | 66 -- Three.V8/renderers/GLRenderTarget.hpp | 73 --- .../renderers/WrapperCubeRenderTarget.cpp | 54 ++ Three.V8/renderers/WrapperCubeRenderTarget.h | 19 + Three.V8/renderers/WrapperGLRenderTarget.cpp | 60 ++ Three.V8/renderers/WrapperGLRenderTarget.h | 18 + .../{GLRenderer.hpp => WrapperGLRenderer.cpp} | 94 +-- Three.V8/renderers/WrapperGLRenderer.h | 33 + .../{FileSaver.hpp => WrapperFileSaver.cpp} | 26 +- Three.V8/savers/WrapperFileSaver.h | 14 + ...mageSaver.hpp => WrapperHDRImageSaver.cpp} | 27 +- Three.V8/savers/WrapperHDRImageSaver.h | 14 + .../{ImageSaver.hpp => WrapperImageSaver.cpp} | 31 +- Three.V8/savers/WrapperImageSaver.h | 13 + ...Saver.hpp => WrapperLODProbeGridSaver.cpp} | 22 +- Three.V8/savers/WrapperLODProbeGridSaver.h | 12 + ...ridSaver.hpp => WrapperProbeGridSaver.cpp} | 22 +- Three.V8/savers/WrapperProbeGridSaver.h | 13 + Three.V8/scenes/Fog.hpp | 136 ---- Three.V8/scenes/WrapperFog.cpp | 108 ++++ Three.V8/scenes/WrapperFog.h | 31 + .../scenes/{Scene.hpp => WrapperScene.cpp} | 84 +-- Three.V8/scenes/WrapperScene.h | 30 + Three.V8/utils/DDSImage.hpp | 53 -- Three.V8/utils/HDRImage.hpp | 115 ---- Three.V8/utils/Image.hpp | 116 ---- Three.V8/utils/WrapperDDSImage.cpp | 40 ++ Three.V8/utils/WrapperDDSImage.h | 20 + Three.V8/utils/WrapperHDRImage.cpp | 88 +++ Three.V8/utils/WrapperHDRImage.h | 31 + Three.V8/utils/WrapperImage.cpp | 88 +++ Three.V8/utils/WrapperImage.h | 32 + Three.V8/utils/{Text.hpp => WrapperText.cpp} | 26 +- Three.V8/utils/WrapperText.h | 15 + Three.V8/volume/VolumeData.hpp | 89 --- Three.V8/volume/WrapperVolumeData.cpp | 68 ++ Three.V8/volume/WrapperVolumeData.h | 22 + ...Loader.hpp => WrapperVolumeDataLoader.cpp} | 24 +- Three.V8/volume/WrapperVolumeDataLoader.h | 14 + ...l.hpp => WrapperVolumeIsosurfaceModel.cpp} | 61 +- .../volume/WrapperVolumeIsosurfaceModel.h | 25 + ThreeEngine/ThreeEngine.vcxproj | 2 + ThreeEngine/ThreeEngine.vcxproj.filters | 6 + 176 files changed, 5748 insertions(+), 4783 deletions(-) create mode 100644 Three.V8/DefaultModule.cpp create mode 100644 Three.V8/DefaultModule.h rename Three.V8/{GamePlayer.hpp => WrapperGamePlayer.cpp} (65%) create mode 100644 Three.V8/WrapperGamePlayer.h delete mode 100644 Three.V8/backgrounds/Background.hpp create mode 100644 Three.V8/backgrounds/WrapperBackground.cpp create mode 100644 Three.V8/backgrounds/WrapperBackground.h rename Three.V8/backgrounds/{BackgroundScene.hpp => WrapperBackgroundScene.cpp} (53%) create mode 100644 Three.V8/backgrounds/WrapperBackgroundScene.h delete mode 100644 Three.V8/cameras/Camera.hpp create mode 100644 Three.V8/cameras/WrapperCamera.cpp create mode 100644 Three.V8/cameras/WrapperCamera.h rename Three.V8/cameras/{PerspectiveCamera.hpp => WrapperPerspectiveCamera.cpp} (51%) create mode 100644 Three.V8/cameras/WrapperPerspectiveCamera.h rename Three.V8/cameras/{Reflector.hpp => WrapperReflector.cpp} (57%) create mode 100644 Three.V8/cameras/WrapperReflector.h rename Three.V8/core/{BoundingVolumeHierarchy.hpp => WrapperBoundingVolumeHierarchy.cpp} (66%) create mode 100644 Three.V8/core/WrapperBoundingVolumeHierarchy.h rename Three.V8/core/{Object3D.hpp => WrapperObject3D.cpp} (61%) create mode 100644 Three.V8/core/WrapperObject3D.h create mode 100644 Three.V8/definitions.hpp delete mode 100644 Three.V8/gui/UIBlock.hpp delete mode 100644 Three.V8/gui/UIPanel.hpp rename Three.V8/gui/{UI3DViewer.hpp => WrapperUI3DViewer.cpp} (72%) create mode 100644 Three.V8/gui/WrapperUI3DViewer.h rename Three.V8/gui/{UIArea.hpp => WrapperUIArea.cpp} (63%) create mode 100644 Three.V8/gui/WrapperUIArea.h create mode 100644 Three.V8/gui/WrapperUIBlock.cpp create mode 100644 Three.V8/gui/WrapperUIBlock.h rename Three.V8/gui/{UIButton.hpp => WrapperUIButton.cpp} (69%) create mode 100644 Three.V8/gui/WrapperUIButton.h rename Three.V8/gui/{UIDraggable.hpp => WrapperUIDraggable.cpp} (61%) create mode 100644 Three.V8/gui/WrapperUIDraggable.h rename Three.V8/gui/{UIElement.hpp => WrapperUIElement.cpp} (69%) create mode 100644 Three.V8/gui/WrapperUIElement.h rename Three.V8/gui/{UIImage.hpp => WrapperUIImage.cpp} (52%) create mode 100644 Three.V8/gui/WrapperUIImage.h rename Three.V8/gui/{UILineEdit.hpp => WrapperUILineEdit.cpp} (57%) create mode 100644 Three.V8/gui/WrapperUILineEdit.h rename Three.V8/gui/{UIManager.hpp => WrapperUIManager.cpp} (68%) create mode 100644 Three.V8/gui/WrapperUIManager.h create mode 100644 Three.V8/gui/WrapperUIPanel.cpp create mode 100644 Three.V8/gui/WrapperUIPanel.h rename Three.V8/gui/{UIScrollViewer.hpp => WrapperUIScrollViewer.cpp} (59%) create mode 100644 Three.V8/gui/WrapperUIScrollViewer.h rename Three.V8/gui/{UIText.hpp => WrapperUIText.cpp} (52%) create mode 100644 Three.V8/gui/WrapperUIText.h rename Three.V8/gui/{UITextBlock.hpp => WrapperUITextBlock.cpp} (59%) create mode 100644 Three.V8/gui/WrapperUITextBlock.h delete mode 100644 Three.V8/lights/AmbientLight.hpp create mode 100644 Three.V8/lights/WrapperAmbientLight.cpp create mode 100644 Three.V8/lights/WrapperAmbientLight.h rename Three.V8/lights/{DirectionalLight.hpp => WrapperDirectionalLight.cpp} (61%) create mode 100644 Three.V8/lights/WrapperDirectionalLight.h rename Three.V8/lights/{EnvironmentMap.hpp => WrapperEnvironmentMap.cpp} (53%) create mode 100644 Three.V8/lights/WrapperEnvironmentMap.h rename Three.V8/lights/{EnvironmentMapCreator.hpp => WrapperEnvironmentMapCreator.cpp} (55%) create mode 100644 Three.V8/lights/WrapperEnvironmentMapCreator.h rename Three.V8/lights/{HemisphereLight.hpp => WrapperHemisphereLight.cpp} (53%) create mode 100644 Three.V8/lights/WrapperHemisphereLight.h rename Three.V8/lights/{IndirectLight.hpp => WrapperIndirectLight.cpp} (55%) create mode 100644 Three.V8/lights/WrapperIndirectLight.h rename Three.V8/lights/{LODProbeGrid.hpp => WrapperLODProbeGrid.cpp} (56%) create mode 100644 Three.V8/lights/WrapperLODProbeGrid.h rename Three.V8/lights/{LODProbeGridWidget.hpp => WrapperLODProbeGridWidget.cpp} (56%) create mode 100644 Three.V8/lights/WrapperLODProbeGridWidget.h rename Three.V8/lights/{Light.hpp => WrapperLight.cpp} (53%) create mode 100644 Three.V8/lights/WrapperLight.h rename Three.V8/lights/{ProbeGrid.hpp => WrapperProbeGrid.cpp} (56%) create mode 100644 Three.V8/lights/WrapperProbeGrid.h rename Three.V8/lights/{ProbeGridWidget.hpp => WrapperProbeGridWidget.cpp} (55%) create mode 100644 Three.V8/lights/WrapperProbeGridWidget.h rename Three.V8/loaders/{DDSImageLoader.hpp => WrapperDDSImageLoader.cpp} (60%) create mode 100644 Three.V8/loaders/WrapperDDSImageLoader.h rename Three.V8/loaders/{FileLoader.hpp => WrapperFileLoader.cpp} (62%) create mode 100644 Three.V8/loaders/WrapperFileLoader.h rename Three.V8/loaders/{GLTFLoader.hpp => WrapperGLTFLoader.cpp} (68%) create mode 100644 Three.V8/loaders/WrapperGLTFLoader.h rename Three.V8/loaders/{HDRImageLoader.hpp => WrapperHDRImageLoader.cpp} (75%) create mode 100644 Three.V8/loaders/WrapperHDRImageLoader.h rename Three.V8/loaders/{ImageLoader.hpp => WrapperImageLoader.cpp} (67%) create mode 100644 Three.V8/loaders/WrapperImageLoader.h rename Three.V8/loaders/{LODProbeGridLoader.hpp => WrapperLODProbeGridLoader.cpp} (61%) create mode 100644 Three.V8/loaders/WrapperLODProbeGridLoader.h rename Three.V8/loaders/{ProbeGridLoader.hpp => WrapperProbeGridLoader.cpp} (61%) create mode 100644 Three.V8/loaders/WrapperProbeGridLoader.h delete mode 100644 Three.V8/models/HeightField.hpp rename Three.V8/models/{AnimationMixer.hpp => WrapperAnimationMixer.cpp} (63%) create mode 100644 Three.V8/models/WrapperAnimationMixer.h rename Three.V8/models/{GLTFModel.hpp => WrapperGLTFModel.cpp} (67%) create mode 100644 Three.V8/models/WrapperGLTFModel.h create mode 100644 Three.V8/models/WrapperHeightField.cpp create mode 100644 Three.V8/models/WrapperHeightField.h rename Three.V8/models/{SimpleModel.hpp => WrapperSimpleModel.cpp} (62%) create mode 100644 Three.V8/models/WrapperSimpleModel.h delete mode 100644 Three.V8/multimedia/AVCPlayer.hpp delete mode 100644 Three.V8/multimedia/MMCamera.hpp delete mode 100644 Three.V8/multimedia/MMLazyVideo.hpp delete mode 100644 Three.V8/multimedia/OpusPlayer.hpp create mode 100644 Three.V8/multimedia/WrapperAVCPlayer.cpp create mode 100644 Three.V8/multimedia/WrapperAVCPlayer.h rename Three.V8/multimedia/{AVCRecorder.hpp => WrapperAVCRecorder.cpp} (61%) create mode 100644 Three.V8/multimedia/WrapperAVCRecorder.h rename Three.V8/multimedia/{MMAudio.hpp => WrapperMMAudio.cpp} (50%) create mode 100644 Three.V8/multimedia/WrapperMMAudio.h create mode 100644 Three.V8/multimedia/WrapperMMCamera.cpp create mode 100644 Three.V8/multimedia/WrapperMMCamera.h create mode 100644 Three.V8/multimedia/WrapperMMLazyVideo.cpp create mode 100644 Three.V8/multimedia/WrapperMMLazyVideo.h rename Three.V8/multimedia/{MMVideo.hpp => WrapperMMVideo.cpp} (52%) create mode 100644 Three.V8/multimedia/WrapperMMVideo.h create mode 100644 Three.V8/multimedia/WrapperOpusPlayer.cpp create mode 100644 Three.V8/multimedia/WrapperOpusPlayer.h rename Three.V8/multimedia/{OpusRecorder.hpp => WrapperOpusRecorder.cpp} (61%) create mode 100644 Three.V8/multimedia/WrapperOpusRecorder.h rename Three.V8/network/{HttpClient.hpp => WrapperHttpClient.cpp} (72%) create mode 100644 Three.V8/network/WrapperHttpClient.h rename Three.V8/network/{WSClient.hpp => WrapperWSClient.cpp} (70%) create mode 100644 Three.V8/network/WrapperWSClient.h delete mode 100644 Three.V8/renderers/CubeRenderTarget.hpp delete mode 100644 Three.V8/renderers/GLRenderTarget.hpp create mode 100644 Three.V8/renderers/WrapperCubeRenderTarget.cpp create mode 100644 Three.V8/renderers/WrapperCubeRenderTarget.h create mode 100644 Three.V8/renderers/WrapperGLRenderTarget.cpp create mode 100644 Three.V8/renderers/WrapperGLRenderTarget.h rename Three.V8/renderers/{GLRenderer.hpp => WrapperGLRenderer.cpp} (73%) create mode 100644 Three.V8/renderers/WrapperGLRenderer.h rename Three.V8/savers/{FileSaver.hpp => WrapperFileSaver.cpp} (59%) create mode 100644 Three.V8/savers/WrapperFileSaver.h rename Three.V8/savers/{HDRImageSaver.hpp => WrapperHDRImageSaver.cpp} (67%) create mode 100644 Three.V8/savers/WrapperHDRImageSaver.h rename Three.V8/savers/{ImageSaver.hpp => WrapperImageSaver.cpp} (63%) create mode 100644 Three.V8/savers/WrapperImageSaver.h rename Three.V8/savers/{LODProbeGridSaver.hpp => WrapperLODProbeGridSaver.cpp} (54%) create mode 100644 Three.V8/savers/WrapperLODProbeGridSaver.h rename Three.V8/savers/{ProbeGridSaver.hpp => WrapperProbeGridSaver.cpp} (54%) create mode 100644 Three.V8/savers/WrapperProbeGridSaver.h delete mode 100644 Three.V8/scenes/Fog.hpp create mode 100644 Three.V8/scenes/WrapperFog.cpp create mode 100644 Three.V8/scenes/WrapperFog.h rename Three.V8/scenes/{Scene.hpp => WrapperScene.cpp} (62%) create mode 100644 Three.V8/scenes/WrapperScene.h delete mode 100644 Three.V8/utils/DDSImage.hpp delete mode 100644 Three.V8/utils/HDRImage.hpp delete mode 100644 Three.V8/utils/Image.hpp create mode 100644 Three.V8/utils/WrapperDDSImage.cpp create mode 100644 Three.V8/utils/WrapperDDSImage.h create mode 100644 Three.V8/utils/WrapperHDRImage.cpp create mode 100644 Three.V8/utils/WrapperHDRImage.h create mode 100644 Three.V8/utils/WrapperImage.cpp create mode 100644 Three.V8/utils/WrapperImage.h rename Three.V8/utils/{Text.hpp => WrapperText.cpp} (55%) create mode 100644 Three.V8/utils/WrapperText.h delete mode 100644 Three.V8/volume/VolumeData.hpp create mode 100644 Three.V8/volume/WrapperVolumeData.cpp create mode 100644 Three.V8/volume/WrapperVolumeData.h rename Three.V8/volume/{VolumeDataLoader.hpp => WrapperVolumeDataLoader.cpp} (60%) create mode 100644 Three.V8/volume/WrapperVolumeDataLoader.h rename Three.V8/volume/{VolumeIsosurfaceModel.hpp => WrapperVolumeIsosurfaceModel.cpp} (56%) create mode 100644 Three.V8/volume/WrapperVolumeIsosurfaceModel.h diff --git a/QGameDev/XMLEditor.cpp b/QGameDev/XMLEditor.cpp index 79a4b6c9..f994a6c9 100644 --- a/QGameDev/XMLEditor.cpp +++ b/QGameDev/XMLEditor.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "XMLEditor.h" #include "JsonUtils.h" #include "FogTuner.h" @@ -215,8 +216,9 @@ void XMLEditor::OnInit() QString path = QCoreApplication::applicationFilePath(); std::string cpath = path.toLocal8Bit().toStdString(); m_game_player = std::unique_ptr(new GamePlayer(cpath.c_str(), width, height)); - m_game_player->SetPrintCallbacks(this, print_std, err_std); m_game_player->SetUserMessageCallback(this, user_message_callback); + + Logging::SetPrintCallbacks(this, print_std, err_std); QString local_path = QCoreApplication::applicationDirPath(); QString script_filename = local_path + "\\xmleditor\\bundle_index.js"; diff --git a/QGamePlayer/PlayerWindow.cpp b/QGamePlayer/PlayerWindow.cpp index 59ddb974..0200fa06 100644 --- a/QGamePlayer/PlayerWindow.cpp +++ b/QGamePlayer/PlayerWindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "PlayerWindow.h" PlayerWindow::PlayerWindow(const char* path_proj, int idx) @@ -100,8 +101,7 @@ void PlayerWindow::OnInit() QString path = QCoreApplication::applicationFilePath(); std::string cpath = path.toLocal8Bit().toStdString(); m_game_player = std::unique_ptr(new GamePlayer(cpath.c_str(), width, height)); - m_game_player->SetPrintCallbacks(this, print_std, err_std); - + Logging::SetPrintCallbacks(this, print_std, err_std); LoadScript(m_script_path); } diff --git a/Test.V8/Test.V8.vcxproj b/Test.V8/Test.V8.vcxproj index f23e25a3..b959d5aa 100644 --- a/Test.V8/Test.V8.vcxproj +++ b/Test.V8/Test.V8.vcxproj @@ -23,7 +23,7 @@ 16.0 Win32Proj - {67d5cd91-a728-4719-8e9c-8610cf661ceb} + {6b0a2bfb-78bb-4361-ab30-47873ab0b9dd} TestV8 10.0 @@ -72,18 +72,6 @@ - - true - - - false - - - true - - - false - Level3 @@ -132,8 +120,7 @@ true _CRT_SECURE_NO_WARNINGS; GLEW_STATIC=1;%(PreprocessorDefinitions) true - ../thirdparty;../ThreeEngine; ../thirdparty/glew/include; ../thirdparty/glm/glm; ../Three.V8;%(AdditionalIncludeDirectories) - stdcpp17 + ../thirdparty;../ThreeEngine;../thirdparty/glew/include;../thirdparty/glm/glm;../Three.V8;%(AdditionalIncludeDirectories) Console @@ -145,35 +132,35 @@ - - + - {ccbe3960-dad2-49af-952f-a8a86d75f190} + {9123b047-fce7-4474-9826-c6bbbe4fe4c7} {030c6452-10bf-48a4-b80f-0d4a996b83ae} - + + - + - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + diff --git a/Test.V8/Test.V8.vcxproj.filters b/Test.V8/Test.V8.vcxproj.filters index 92657eb3..f19d3cb1 100644 --- a/Test.V8/Test.V8.vcxproj.filters +++ b/Test.V8/Test.V8.vcxproj.filters @@ -14,6 +14,9 @@ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + Source Files @@ -27,7 +30,4 @@ Header Files - - - \ No newline at end of file diff --git a/Test.V8/main.cpp b/Test.V8/main.cpp index c8016134..061895b2 100644 --- a/Test.V8/main.cpp +++ b/Test.V8/main.cpp @@ -90,7 +90,7 @@ class AppMain : private GLMain int main(int argc, const char* argv[]) { AppMain app(argv[0]); - app.LoadScript("../game", "bundle_http_test.js"); + app.LoadScript("../game", "bundle_game.js"); app.MainLoop(); return 0; } diff --git a/Three.V8.sln b/Three.V8.sln index 61464cdd..e39be3ec 100644 --- a/Three.V8.sln +++ b/Three.V8.sln @@ -5,18 +5,18 @@ VisualStudioVersion = 17.3.32901.215 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ThreeEngine", "ThreeEngine\ThreeEngine.vcxproj", "{030C6452-10BF-48A4-B80F-0D4A996B83AE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Three.V8", "Three.V8\Three.V8.vcxproj", "{CCBE3960-DAD2-49AF-952F-A8A86D75F190}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test.Cpp", "Test.Cpp\Test.Cpp.vcxproj", "{3F00C726-809A-4269-9281-33B6AACE99F9}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test.V8", "Test.V8\Test.V8.vcxproj", "{67D5CD91-A728-4719-8E9C-8610CF661CEB}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ThreeMM", "ThreeMM\ThreeMM.vcxproj", "{7F3BB2FF-13E9-45A0-B8E3-F663FC651EFD}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lightmapper", "Lightmapper\Lightmapper.vcxproj", "{CD28457C-63C3-43E9-8C91-A015D91B7B49}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LightmapCompressor", "LightmapCompressor\LightmapCompressor.vcxproj", "{BE12DD92-F55E-4138-8755-A62107C35182}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Three.V8", "Three.V8\Three.V8.vcxproj", "{9123B047-FCE7-4474-9826-C6BBBE4FE4C7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test.V8", "Test.V8\Test.V8.vcxproj", "{6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,16 +37,6 @@ Global {030C6452-10BF-48A4-B80F-0D4A996B83AE}.Release|x64.Build.0 = Release|x64 {030C6452-10BF-48A4-B80F-0D4A996B83AE}.Release|x86.ActiveCfg = Release|Win32 {030C6452-10BF-48A4-B80F-0D4A996B83AE}.Release|x86.Build.0 = Release|Win32 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Debug|x64.ActiveCfg = Debug|x64 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Debug|x64.Build.0 = Debug|x64 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Debug|x86.ActiveCfg = Debug|Win32 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Debug|x86.Build.0 = Debug|Win32 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Release|Any CPU.ActiveCfg = Release|Win32 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Release|x64.ActiveCfg = Release|x64 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Release|x64.Build.0 = Release|x64 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Release|x86.ActiveCfg = Release|Win32 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190}.Release|x86.Build.0 = Release|Win32 {3F00C726-809A-4269-9281-33B6AACE99F9}.Debug|Any CPU.ActiveCfg = Debug|Win32 {3F00C726-809A-4269-9281-33B6AACE99F9}.Debug|x64.ActiveCfg = Debug|x64 {3F00C726-809A-4269-9281-33B6AACE99F9}.Debug|x64.Build.0 = Debug|x64 @@ -57,16 +47,6 @@ Global {3F00C726-809A-4269-9281-33B6AACE99F9}.Release|x64.Build.0 = Release|x64 {3F00C726-809A-4269-9281-33B6AACE99F9}.Release|x86.ActiveCfg = Release|Win32 {3F00C726-809A-4269-9281-33B6AACE99F9}.Release|x86.Build.0 = Release|Win32 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Debug|x64.ActiveCfg = Debug|x64 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Debug|x64.Build.0 = Debug|x64 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Debug|x86.ActiveCfg = Debug|Win32 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Debug|x86.Build.0 = Debug|Win32 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Release|Any CPU.ActiveCfg = Release|Win32 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Release|x64.ActiveCfg = Release|x64 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Release|x64.Build.0 = Release|x64 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Release|x86.ActiveCfg = Release|Win32 - {67D5CD91-A728-4719-8E9C-8610CF661CEB}.Release|x86.Build.0 = Release|Win32 {7F3BB2FF-13E9-45A0-B8E3-F663FC651EFD}.Debug|Any CPU.ActiveCfg = Debug|x64 {7F3BB2FF-13E9-45A0-B8E3-F663FC651EFD}.Debug|Any CPU.Build.0 = Debug|x64 {7F3BB2FF-13E9-45A0-B8E3-F663FC651EFD}.Debug|x64.ActiveCfg = Debug|x64 @@ -103,6 +83,30 @@ Global {BE12DD92-F55E-4138-8755-A62107C35182}.Release|x64.Build.0 = Release|x64 {BE12DD92-F55E-4138-8755-A62107C35182}.Release|x86.ActiveCfg = Release|Win32 {BE12DD92-F55E-4138-8755-A62107C35182}.Release|x86.Build.0 = Release|Win32 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Debug|Any CPU.ActiveCfg = Debug|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Debug|Any CPU.Build.0 = Debug|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Debug|x64.ActiveCfg = Debug|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Debug|x64.Build.0 = Debug|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Debug|x86.ActiveCfg = Debug|Win32 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Debug|x86.Build.0 = Debug|Win32 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Release|Any CPU.ActiveCfg = Release|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Release|Any CPU.Build.0 = Release|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Release|x64.ActiveCfg = Release|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Release|x64.Build.0 = Release|x64 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Release|x86.ActiveCfg = Release|Win32 + {9123B047-FCE7-4474-9826-C6BBBE4FE4C7}.Release|x86.Build.0 = Release|Win32 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Debug|Any CPU.Build.0 = Debug|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Debug|x64.ActiveCfg = Debug|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Debug|x64.Build.0 = Debug|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Debug|x86.ActiveCfg = Debug|Win32 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Debug|x86.Build.0 = Debug|Win32 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Release|Any CPU.ActiveCfg = Release|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Release|Any CPU.Build.0 = Release|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Release|x64.ActiveCfg = Release|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Release|x64.Build.0 = Release|x64 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Release|x86.ActiveCfg = Release|Win32 + {6B0A2BFB-78BB-4361-AB30-47873AB0B9DD}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Three.V8/DefaultModule.cpp b/Three.V8/DefaultModule.cpp new file mode 100644 index 00000000..1e5bc544 --- /dev/null +++ b/Three.V8/DefaultModule.cpp @@ -0,0 +1,302 @@ +#include +#include +#include +#include "DefaultModule.h" +#include "binding.h" +#include "WrapperUtils.hpp" + +inline const char* ToCString(const v8::String::Utf8Value& value) { + return *value ? *value : ""; +} + + +static void Print(const v8::FunctionCallbackInfo& args) +{ + std::string line = ""; + bool first = true; + for (int i = 0; i < args.Length(); i++) { + v8::HandleScope handle_scope(args.GetIsolate()); + if (first) { + first = false; + } + else + { + line += " "; + } + v8::String::Utf8Value str(args.GetIsolate(), args[i]); + const char* cstr = ToCString(str); + line += cstr; + } + + Logging::print_std(line.c_str()); + +} + + +static void Now(const v8::FunctionCallbackInfo& args) +{ + LocalContext lctx(args); + double now = time_sec() * 1000.0; + args.GetReturnValue().Set(lctx.num_to_jnum(now)); +} + + +static void GetGLError(const v8::FunctionCallbackInfo& args) +{ + LocalContext lctx(args); + unsigned err = glGetError(); + args.GetReturnValue().Set(lctx.num_to_jnum(err)); +} + + +#if THREE_MM +#include +#include + +static void GetListOfCameras(const v8::FunctionCallbackInfo& args) +{ + LocalContext lctx(args); + const std::vector& lst = MMCamera::s_get_list_devices(); + + v8::Local ret = v8::Array::New(lctx.isolate); + for (size_t i = 0; i < lst.size(); i++) + { + v8::Local name = lctx.str_to_jstr(lst[i].c_str()); + ret->Set(lctx.context, (unsigned)i, name); + } + args.GetReturnValue().Set(ret); +} + +static void GetListOfAudioDevices(const v8::FunctionCallbackInfo& args) +{ + LocalContext lctx(args); + const std::vector& lst = GetNamesAudioDevices(false); + + v8::Local ret = v8::Array::New(lctx.isolate); + for (size_t i = 0; i < lst.size(); i++) + { + v8::Local name = lctx.str_to_jstr(lst[i].c_str()); + ret->Set(lctx.context, (unsigned)i, name); + } + args.GetReturnValue().Set(ret); +} +#endif + + +#ifdef _WIN32 +#include +#include +#endif + +static void GeneralCall(const v8::FunctionCallbackInfo& args) +{ + LocalContext lctx(args); + v8::Local ret; + std::string cmd = lctx.jstr_to_str(args[0]); + +#ifdef _WIN32 + if (cmd == "OpenFile") + { + v8::String::Value filter_name(lctx.isolate, args[1]); + v8::String::Value filter_ext(lctx.isolate, args[2]); + + wchar_t filter[1024]; + wsprintf(filter, L"%s", (wchar_t*)(*filter_name)); + + int pos = lstrlenW(filter); + wsprintf(filter + pos + 1, L"%s", (wchar_t*)(*filter_ext)); + + int pos2 = lstrlenW(filter + pos + 1); + filter[pos + 1 + pos2 + 1] = 0; + + + wchar_t buffer[1024]; + OPENFILENAMEW ofn{ 0 }; + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = NULL; + ofn.lpstrFile = buffer; + ofn.lpstrFile[0] = 0; + ofn.nMaxFile = 1024; + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + ::GetOpenFileName(&ofn); + + ret = v8::String::NewFromTwoByte(lctx.isolate, (uint16_t*)buffer).ToLocalChecked(); + } +#endif + + args.GetReturnValue().Set(ret); +} + +#include "WrapperGamePlayer.h" +#include "gui/WrapperUIManager.h" +#include "network/WrapperHttpClient.h" +#include "loaders/WrapperFileLoader.h" +#include "loaders/WrapperImageLoader.h" +#include "loaders/WrapperHDRImageLoader.h" +#include "loaders/WrapperDDSImageLoader.h" +#include "loaders/WrapperGLTFLoader.h" +#include "loaders/WrapperProbeGridLoader.h" +#include "loaders/WrapperLODProbeGridLoader.h" +#include "savers/WrapperFileSaver.h" +#include "savers/WrapperImageSaver.h" +#include "savers/WrapperHDRImageSaver.h" +#include "savers/WrapperProbeGridSaver.h" +#include "savers/WrapperLODProbeGridSaver.h" +#include "volume/WrapperVolumeDataLoader.h" +#include "utils/WrapperText.h" + +#include "core/WrapperObject3D.h" +#include "cameras/WrapperCamera.h" +#include "cameras/WrapperPerspectiveCamera.h" +#include "cameras/WrapperReflector.h" +#include "backgrounds/WrapperBackground.h" +#include "backgrounds/WrapperBackgroundScene.h" +#include "scenes/WrapperScene.h" +#include "scenes/WrapperFog.h" +#include "renderers/WrapperGLRenderer.h" +#include "renderers/WrapperGLRenderTarget.h" +#include "renderers/WrapperCubeRenderTarget.h" +#include "models/WrapperSimpleModel.h" +#include "models/WrapperGLTFModel.h" +#include "models/WrapperAnimationMixer.h" +#include "utils/WrapperImage.h" +#include "utils/WrapperHDRImage.h" +#include "utils/WrapperDDSImage.h" +#include "lights/WrapperDirectionalLight.h" +#include "lights/WrapperEnvironmentMap.h" +#include "lights/WrapperProbeGrid.h" +#include "lights/WrapperLODProbeGrid.h" +#include "lights/WrapperEnvironmentMapCreator.h" +#include "lights/WrapperAmbientLight.h" +#include "lights/WrapperHemisphereLight.h" +#include "lights/WrapperProbeGridWidget.h" +#include "lights/WrapperLODProbeGridWidget.h" +#include "core/WrapperBoundingVolumeHierarchy.h" +#include "gui/WrapperUIArea.h" +#include "gui/WrapperUIBlock.h" +#include "gui/WrapperUIPanel.h" +#include "gui/WrapperUIButton.h" +#include "gui/WrapperUIScrollViewer.h" +#include "gui/WrapperUILineEdit.h" +#include "gui/WrapperUIText.h" +#include "gui/WrapperUITextBlock.h" +#include "gui/WrapperUIImage.h" +#include "gui/WrapperUI3DViewer.h" +#include "gui/WrapperUIDraggable.h" + +#if THREE_MM +#include "multimedia/WrapperMMCamera.h" +#include "multimedia/WrapperMMLazyVideo.h" +#include "multimedia/WrapperMMAudio.h" +#include "multimedia/WrapperMMVideo.h" +#include "multimedia/WrapperOpusRecorder.h" +#include "multimedia/WrapperOpusPlayer.h" +#include "multimedia/WrapperAVCRecorder.h" +#include "multimedia/WrapperAVCPlayer.h" +#endif + +#include "volume/WrapperVolumeData.h" +#include "volume/WrapperVolumeIsosurfaceModel.h" +#include "network/WrapperWSClient.h" +#include "models/WrapperHeightField.h" + +void GetDefaultModule(ModuleDefinition& module) +{ + module.functions = { + { "print", Print}, + { "setCallback", GameContext::SetCallback}, + { "now", Now}, + {"getGLError", GetGLError}, +#if THREE_MM + {"getListOfCameras", GetListOfCameras}, + {"getListOfAudioDevices", GetListOfAudioDevices}, +#endif + {"generalCall", GeneralCall}, + }; + + module.objects = { + WrapperGamePlayer::define, + WrapperUIManager::define, + WrapperHttpClient::define, + WrapperFileLoader::define, + WrapperImageLoader::define, + WrapperHDRImageLoader::define, + WrapperDDSImageLoader::define, + WrapperGLTFLoader::define, + WrapperProbeGridLoader::define, + WrapperLODProbeGridLoader::define, + WrapperFileSaver::define, + WrapperImageSaver::define, + WrapperHDRImageSaver::define, + WrapperProbeGridSaver::define, + WrapperLODProbeGridSaver::define, + WrapperVolumeDataLoader::define, + WrapperText::define + }; + + module.classes = { + WrapperObject3D::define, + WrapperCamera::define, + WrapperPerspectiveCamera::define, + WrapperReflector::define, + WrapperColorBackground::define, + WrapperCubeBackground::define, + WrapperHemisphereBackground::define, + WrapperBackgroundScene::define, + WrapperScene::define, + WrapperFog::define, + WrapperGLRenderer::define, + WrapperGLRenderTarget::define, + WrapperCubeRenderTarget::define, + WrapperSimpleModel::define, + WrapperGLTFModel::define, + WrapperAnimationMixer::define, + WrapperImage::define, + WrapperCubeImage::define, + WrapperHDRImage::define, + WrapperHDRCubeImage::define, + WrapperDDSImage::define, + WrapperDirectionalLight::define, + WrapperEnvironmentMap::define, + WrapperProbeGrid::define, + WrapperLODProbeGrid::define, + WrapperEnvironmentMapCreator::define, + WrapperAmbientLight::define, + WrapperHemisphereLight::define, + WrapperProbeGridWidget::define, + WrapperLODProbeGridWidget::define, + WrapperBoundingVolumeHierarchy::define, + WrapperUIArea::define, + WrapperUIBlock::define, + WrapperUIPanel::define, + WrapperUIButton::define, + WrapperUIScrollViewer::define, + WrapperUILineEdit::define, + WrapperUIText::define, + WrapperUITextBlock::define, + WrapperUIImage::define, + WrapperUI3DViewer::define, + WrapperUIDraggable::define, +#if THREE_MM + WrapperMMCamera::define, + WrapperMMLazyVideo::define, + WrapperMMAudio::define, + WrapperMMVideo::define, + WrapperOpusRecorder::define, + WrapperOpusPlayer::define, + WrapperAVCRecorder::define, + WrapperAVCPlayer::define, +#endif + WrapperVolumeData::define, + WrapperVolumeIsosurfaceModel::define, + WrapperWSClient::define, + WrapperHeightField::define + + }; +} + diff --git a/Three.V8/DefaultModule.h b/Three.V8/DefaultModule.h new file mode 100644 index 00000000..3f0108d5 --- /dev/null +++ b/Three.V8/DefaultModule.h @@ -0,0 +1,6 @@ +#pragma once + +#include "definitions.hpp" + +void GetDefaultModule(ModuleDefinition& module); + diff --git a/Three.V8/GamePlayer.cpp b/Three.V8/GamePlayer.cpp index 920622ef..073b7bcb 100644 --- a/Three.V8/GamePlayer.cpp +++ b/Three.V8/GamePlayer.cpp @@ -4,6 +4,9 @@ #include #include #include "GamePlayer.h" +#include "DefaultModule.h" +#include "WrapperUtils.hpp" +#include "WrapperGamePlayer.h" #define ENABLE_MSAA 1 @@ -28,6 +31,9 @@ GamePlayer::GamePlayer(const char* exec_path, int width, int height) glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); srand(time(nullptr)); + + WrapperGamePlayer::s_game_player = this; + GetDefaultModule(m_world_definition.default_module); } GamePlayer::~GamePlayer() @@ -35,22 +41,27 @@ GamePlayer::~GamePlayer() UnloadScript(); } +void GamePlayer::AddModule(ModuleDefinition&& mod) +{ + m_world_definition.modules.emplace_back(mod); +} + void GamePlayer::LoadScript(const char* dir, const char* filename) { UnloadScript(); std::filesystem::current_path(dir); - m_context = std::unique_ptr(new GameContext(&m_v8vm, this, filename)); - m_context->SetPrintCallbacks(m_print_callback_data, m_print_callback, m_error_callback); + m_context = std::unique_ptr(new GameContext(&m_v8vm, m_world_definition, filename)); v8::Isolate* isolate = m_v8vm.m_isolate; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); v8::Function* callback_init = m_context->GetCallback("init"); if (callback_init != nullptr) { std::vector> args(2); - args[0] = v8::Number::New(isolate, (double)m_render_target.m_width); - args[1] = v8::Number::New(isolate, (double)m_render_target.m_height); + args[0] = lctx.num_to_jnum(m_render_target.m_width); + args[1] = lctx.num_to_jnum(m_render_target.m_height); m_context->InvokeCallback(callback_init, args); } } @@ -95,37 +106,37 @@ void GamePlayer::Draw(int width, int height) v8::Isolate* isolate = m_v8vm.m_isolate; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Function* callback = m_context->GetCallback("render"); if (callback != nullptr) { std::vector> args(3); - args[0] = v8::Number::New(isolate, (double)width); - args[1] = v8::Number::New(isolate, (double)height); + args[0] = lctx.num_to_jnum(width); + args[1] = lctx.num_to_jnum(height); args[2] = v8::Boolean::New(isolate, size_changed); m_context->InvokeCallback(callback, args); } - } - #if !ENABLE_MSAA - m_render_target.blit_buffer(width, height, 0); -#endif + m_render_target.blit_buffer(width, height, 0); +#endif + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); - if (m_context != nullptr) - { // render UI - m_ui_renderer.render(*m_context->GetUIManager(), width, height, cur_fbo); + m_ui_renderer.render(*ui_manager, width, height, cur_fbo); } glBindFramebuffer(GL_FRAMEBUFFER, cur_fbo); } -inline v8::Local g_CreateMouseEvent(v8::Isolate* isolate, v8::Local context, int button, int clicks, int delta, int x, int y) +inline v8::Local g_CreateMouseEvent(LocalContext* lctx, int button, int clicks, int delta, int x, int y) { - v8::Local e = v8::Object::New(isolate); - e->Set(context, v8::String::NewFromUtf8(isolate, "button").ToLocalChecked(), v8::Number::New(isolate, (double)button)); - e->Set(context, v8::String::NewFromUtf8(isolate, "clicks").ToLocalChecked(), v8::Number::New(isolate, (double)clicks)); - e->Set(context, v8::String::NewFromUtf8(isolate, "delta").ToLocalChecked(), v8::Number::New(isolate, (double)delta)); - e->Set(context, v8::String::NewFromUtf8(isolate, "x").ToLocalChecked(), v8::Number::New(isolate, (double)x + 0.5)); - e->Set(context, v8::String::NewFromUtf8(isolate, "y").ToLocalChecked(), v8::Number::New(isolate, (double)y + 0.5)); + v8::Local e = v8::Object::New(lctx->isolate); + lctx->set_property(e, "button", lctx->num_to_jnum(button)); + lctx->set_property(e, "clicks", lctx->num_to_jnum(clicks)); + lctx->set_property(e, "delta", lctx->num_to_jnum(delta)); + lctx->set_property(e, "x", lctx->num_to_jnum((double)x + 0.5)); + lctx->set_property(e, "y", lctx->num_to_jnum((double)y + 0.5)); return e; } @@ -133,18 +144,20 @@ void GamePlayer::OnMouseDown(int button, int clicks, int delta, int x, int y) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); - bool hit = ui_manager->MouseDown(button, clicks, delta, x, y); - if (hit) return; - v8::Isolate* isolate = m_v8vm.m_isolate; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); + bool hit = ui_manager->MouseDown(button, clicks, delta, x, y); + if (hit) return; + v8::Function* callback = m_context->GetCallback("OnMouseDown"); if (callback != nullptr) { std::vector> args(1); - args[0] = g_CreateMouseEvent(isolate, m_context->m_context.Get(isolate), button, clicks, delta, x, y); + args[0] = g_CreateMouseEvent(&lctx, button, clicks, delta, x, y); m_context->InvokeCallback(callback, args); } } @@ -154,18 +167,20 @@ void GamePlayer::OnMouseUp(int button, int clicks, int delta, int x, int y) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); - bool hit = ui_manager->MouseUp(button, clicks, delta, x, y); - if (hit) return; - v8::Isolate* isolate = m_v8vm.m_isolate; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); + bool hit = ui_manager->MouseUp(button, clicks, delta, x, y); + if (hit) return; + v8::Function* callback = m_context->GetCallback("OnMouseUp"); if (callback != nullptr) { std::vector> args(1); - args[0] = g_CreateMouseEvent(isolate, m_context->m_context.Get(isolate), button, clicks, delta, x, y); + args[0] = g_CreateMouseEvent(&lctx, button, clicks, delta, x, y); m_context->InvokeCallback(callback, args); } } @@ -175,18 +190,20 @@ void GamePlayer::OnMouseMove(int button, int clicks, int delta, int x, int y) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); - bool hit = ui_manager->MouseMove(button, clicks, delta, x, y); - if (hit) return; - v8::Isolate* isolate = m_v8vm.m_isolate; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); + bool hit = ui_manager->MouseMove(button, clicks, delta, x, y); + if (hit) return; + v8::Function* callback = m_context->GetCallback("OnMouseMove"); if (callback != nullptr) { std::vector> args(1); - args[0] = g_CreateMouseEvent(isolate, m_context->m_context.Get(isolate), button, clicks, delta, x, y); + args[0] = g_CreateMouseEvent(&lctx, button, clicks, delta, x, y); m_context->InvokeCallback(callback, args); } } @@ -196,18 +213,20 @@ void GamePlayer::OnMouseWheel(int button, int clicks, int delta, int x, int y) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); - bool hit = ui_manager->MouseWheel(button, clicks, delta, x, y); - if (hit) return; - v8::Isolate* isolate = m_v8vm.m_isolate; v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); + bool hit = ui_manager->MouseWheel(button, clicks, delta, x, y); + if (hit) return; + v8::Function* callback = m_context->GetCallback("OnMouseWheel"); if (callback != nullptr) { std::vector> args(1); - args[0] = g_CreateMouseEvent(isolate, m_context->m_context.Get(isolate), button, clicks, delta, x, y); + args[0] = g_CreateMouseEvent(&lctx, button, clicks, delta, x, y); m_context->InvokeCallback(callback, args); } } @@ -218,7 +237,12 @@ void GamePlayer::OnLongPress(int x, int y) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); + v8::Isolate* isolate = m_v8vm.m_isolate; + v8::HandleScope handle_scope(isolate); + v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); bool hit = ui_manager->LongPress((float)x + 0.5f, (float)y + 0.5f); if (hit) return; } @@ -228,7 +252,12 @@ void GamePlayer::OnChar(int keyChar) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); + v8::Isolate* isolate = m_v8vm.m_isolate; + v8::HandleScope handle_scope(isolate); + v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); bool handled = ui_manager->KeyChar(keyChar); if (handled) return; } @@ -238,7 +267,12 @@ void GamePlayer::OnControlKey(unsigned code) { if (m_context != nullptr) { - UIManager* ui_manager = m_context->GetUIManager(); + v8::Isolate* isolate = m_v8vm.m_isolate; + v8::HandleScope handle_scope(isolate); + v8::Context::Scope context_scope(m_context->m_context.Get(isolate)); + LocalContext lctx(isolate); + v8::Local value = lctx.get_global("UIManager"); + UIManager* ui_manager = lctx.jobj_to_obj(value); bool handled = ui_manager->ControlKey(code); if (handled) return; } @@ -293,15 +327,3 @@ void GamePlayer::SetPicking(bool picking) } } - -void GamePlayer::SetPrintCallbacks(void* ptr, GameContext::PrintCallback print_callback, GameContext::PrintCallback error_callback) -{ - m_print_callback_data = ptr; - m_print_callback = print_callback; - m_error_callback = error_callback; - - if (m_context != nullptr) - { - m_context->SetPrintCallbacks(ptr, print_callback, error_callback); - } -} \ No newline at end of file diff --git a/Three.V8/GamePlayer.h b/Three.V8/GamePlayer.h index 9765ecd7..74f0076c 100644 --- a/Three.V8/GamePlayer.h +++ b/Three.V8/GamePlayer.h @@ -6,6 +6,7 @@ #include #include #include "binding.h" +#include "definitions.hpp" struct MsgHandler { @@ -19,6 +20,8 @@ class GamePlayer GamePlayer(const char* exec_path, int width, int height); ~GamePlayer(); + void AddModule(ModuleDefinition&& mod); + int width() const { return m_render_target.m_width; } int height() const { return m_render_target.m_height; } @@ -57,8 +60,6 @@ class GamePlayer return m_pick_target.get(); } - void SetPrintCallbacks(void* ptr, GameContext::PrintCallback print_callback, GameContext::PrintCallback error_callback); - private: static V8VM& s_get_vm(const char* exec_path); V8VM& m_v8vm; @@ -66,11 +67,8 @@ class GamePlayer GLRenderTarget m_render_target; std::unique_ptr m_pick_target; GLUIRenderer m_ui_renderer; - - void* m_print_callback_data = nullptr; - GameContext::PrintCallback m_print_callback = nullptr; - GameContext::PrintCallback m_error_callback = nullptr; + WorldDefinition m_world_definition; std::unique_ptr m_context; void* m_user_message_callback_data = nullptr; diff --git a/Three.V8/Three.V8.vcxproj b/Three.V8/Three.V8.vcxproj index dc9cc42b..8bc2581b 100644 --- a/Three.V8/Three.V8.vcxproj +++ b/Three.V8/Three.V8.vcxproj @@ -1,5 +1,5 @@ - + @@ -21,8 +21,9 @@ - 15.0 - {CCBE3960-DAD2-49AF-952F-A8A86D75F190} + 16.0 + Win32Proj + {9123b047-fce7-4474-9826-c6bbbe4fe4c7} ThreeV8 10.0 @@ -31,20 +32,20 @@ Application true v143 - MultiByte + Unicode Application false v143 true - MultiByte + Unicode Application true v143 - MultiByte + Unicode StaticLibrary @@ -71,143 +72,218 @@ - - + Level3 - MaxSpeed - true - true true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - _CRT_SECURE_NO_WARNINGS; GLEW_STATIC=1; THREE_MM=1;%(PreprocessorDefinitions) - .;../ThreeEngine;../thirdparty/glew/include;../thirdparty/glm/glm;../thirdparty/bvh/include;$(MSBuildThisFileDirectory)..\..\include;../ThreeMM;%(AdditionalIncludeDirectories) - stdcpp17 Console - true - true + true - + Level3 - Disabled + true + true true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true Console + true + true + true Level3 - Disabled true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true Console + true - + Level3 - MaxSpeed true true true + _CRT_SECURE_NO_WARNINGS; GLEW_STATIC=1; THREE_MM=1;%(PreprocessorDefinitions) true + .;../ThreeEngine;../thirdparty/glew/include;../thirdparty/glm/glm;../thirdparty/bvh/include;$(MSBuildThisFileDirectory)..\..\include;../ThreeMM;%(AdditionalIncludeDirectories) + stdcpp17 Console true true + true - - + + + + + - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + diff --git a/Three.V8/Three.V8.vcxproj.filters b/Three.V8/Three.V8.vcxproj.filters index d9741199..263a4cab 100644 --- a/Three.V8/Three.V8.vcxproj.filters +++ b/Three.V8/Three.V8.vcxproj.filters @@ -3,277 +3,328 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {eda61861-8be6-480f-a881-bd5a23fc500a} + + + {f6390c96-b4e2-489a-b208-100a9d082c01} + + + {8d8eb548-17be-448e-9b58-92a123c45be9} + + + {3ca43ba3-ddd7-4344-a1fa-4f05b9020195} + + + {cbda160f-1f10-48c6-b3e0-e2fd529b5284} + + + {8b9f6ba5-9d99-4768-ad2a-3711ebde21ed} + + + {0651a47e-142e-4f5c-8fda-b375fb006957} + + + {e46f6c1b-a5a0-48ed-aaeb-e0e3b01c7923} + + + {193c9a4a-adad-4642-b04e-4adfaabaa13a} + + + {3ba6db48-743f-4649-bb18-0137ca7f5c22} + + + {487cf5ac-7e50-434a-a98b-100c3567e9db} + + + {96ab2e8c-de4d-43bd-bc2a-957f0106a8db} + - {3625f829-255c-44ba-a16c-0152ccc68ad6} + {8e8bbda2-b5c6-40fe-9097-1c65bbaef6a7} - - {418473b9-e1fb-4195-94ae-9610caa28d04} + + {e5445832-ecb4-4103-bff7-07cf9dcd4e4d} - - {e4817e5a-5a0c-4f11-babd-73cf54549be8} + + {be0f53d9-10f9-4ab0-a17d-6176c2623fc3} - - {0dd48f1c-a387-492a-bf49-84f511765586} + + {1e51d858-8000-4c9b-ac0b-f9caaf695479} - {50a1a037-db8a-4ac9-9a25-38b9466f974a} + {4cc77055-5fd2-4fa5-9ffe-211eca3e233e} - - {6d55a7a6-5bed-4718-938e-4b9aa1fbcd9e} + + {60e0f71c-b6fa-40f0-a0a8-8f921fbfbc21} - - {8bd7890d-738f-476c-877c-e9c4d97c956d} + + {f7c4fe8d-9152-42fc-a53c-a847f846146a} - - {1542d9cc-7fea-47e2-baa7-80c096bee73e} + + {fe9c6fdc-7c73-4148-a733-96715b51e26a} - - {4b909431-bbe2-4b48-abf0-551cd781942c} + + {6ad63c41-84a2-4852-9811-673451de24b6} - - {5e578ec3-e02b-41b1-86db-11e380e1605e} + + {169dd858-5bd6-4954-a06e-2903020ca8e7} - - {debe0751-5683-49a1-a6b0-bb98c72394c7} + + {8b1a67d5-a394-48c4-b0dc-0e723ddf0c29} - - {c9dfb990-4516-487e-8425-013a8fc32b35} + + {0bac12e0-dc84-487f-b924-db56701fcf6e} + + + {fe413a53-cc79-4b31-af8b-06916744fcf6} + + + {467ad761-3cac-476e-ba56-f7607d9c36da} - {59402ca3-1e45-4b01-a06b-b5d17912aad3} + {d45e3e66-aa34-4ba9-bcb8-3abae7202158} - - {c7800e1b-60e2-411d-97f7-591644d8cccc} + + {d4dcc198-0726-4a03-a43f-7ffa11b98c6c} + + + + + Header Files + Header Files - - Header Files\core + + Header Files - + + Header Files + + Header Files - + + Header Files\loaders + + + Header Files + + + Header Files\gui + + + Header Files\loaders + + + Header Files\loaders + + + Header Files\loaders + + + Header Files\loaders + + + Header Files\loaders + + + Header Files\network + + + Header Files\loaders + + + Header Files\savers + + + Header Files\savers + + + Header Files\savers + + + Header Files\savers + + + Header Files\savers + + + Header Files\volume + + + Header Files\utils + + + Header Files\core + + + Header Files\cameras + + Header Files\cameras - + Header Files\cameras - + Header Files\backgrounds - - Header Files\scenes + + Header Files\backgrounds + + + Header Files\scene - + + Header Files\scene + + Header Files\renderers - - Header Files\models + + Header Files\renderers - - Header Files\utils + + Header Files\renderers - - Header Files + + Header Files\models - - Header Files + + Header Files\models - - Header Files\loaders + + Header Files\models - - Header Files\loaders + + Header Files\utils + + + Header Files\utils - + Header Files\models - - Header Files\loaders + + Header Files\lights - + Header Files\lights - + Header Files\lights - + Header Files\lights - + Header Files\lights - + Header Files\lights - + Header Files\lights - - Header Files\core + + Header Files\lights - + Header Files\lights - - Header Files\network + + Header Files\lights - - Header Files\gui + + Header Files\lights - - Header Files\gui + + Header Files\core - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - + Header Files\gui - - Header Files\savers - - - Header Files\renderers - - - Header Files\renderers + + Header Files\gui - - Header Files\scenes + + Header Files\gui - + Header Files\multimedia - + Header Files\multimedia - + Header Files\multimedia - + Header Files\multimedia - - Header Files\gui - - - Header Files\volume - - - Header Files\volume - - - Header Files\volume - - - Header Files\network - - - Header Files\utils - - - Header Files\models - - + Header Files\multimedia - + Header Files\multimedia - + Header Files\multimedia - + Header Files\multimedia - - Header Files\backgrounds - - - Header Files\lights - - - Header Files\loaders - - - Header Files\savers - - - Header Files\lights - - - Header Files\savers - - - Header Files\lights - - - Header Files\lights - - - Header Files\loaders - - - Header Files\savers - - - Header Files\utils - - - Header Files\loaders - - - Header Files\savers - - - Header Files\utils + + Header Files\volume - - Header Files\loaders + + Header Files\volume - - Header Files\cameras + + Header Files\network - + Header Files\models @@ -284,8 +335,218 @@ Source Files - - - + + Source Files + + + Source Files\loaders + + + Source Files + + + Source Files\gui + + + Source Files\loaders + + + Source Files\loaders + + + Source Files\loaders + + + Source Files\loaders + + + Source Files\loaders + + + Source Files\network + + + Source Files\loaders + + + Source Files\savers + + + Source Files\savers + + + Source Files\savers + + + Source Files\savers + + + Source Files\savers + + + Source Files\volume + + + Source Files\utils + + + Source Files\core + + + Source Files\cameras + + + Source Files\cameras + + + Source Files\cameras + + + Source Files\backgrounds + + + Source Files\backgrounds + + + Source Files\scene + + + Source Files\scene + + + Source Files\renderers + + + Source Files\renderers + + + Source Files\renderers + + + Source Files\models + + + Source Files\models + + + Source Files\models + + + Source Files\utils + + + Source Files\utils + + + Source Files\models + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\lights + + + Source Files\core + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\gui + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\multimedia + + + Source Files\volume + + + Source Files\volume + + + Source Files\network + + + Source Files\models + \ No newline at end of file diff --git a/Three.V8/Three.V8.vcxproj.user b/Three.V8/Three.V8.vcxproj.user index be250787..88a55094 100644 --- a/Three.V8/Three.V8.vcxproj.user +++ b/Three.V8/Three.V8.vcxproj.user @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Three.V8/GamePlayer.hpp b/Three.V8/WrapperGamePlayer.cpp similarity index 65% rename from Three.V8/GamePlayer.hpp rename to Three.V8/WrapperGamePlayer.cpp index 7c501036..f5ada4f0 100644 --- a/Three.V8/GamePlayer.hpp +++ b/Three.V8/WrapperGamePlayer.cpp @@ -1,51 +1,49 @@ -#pragma once #include "WrapperUtils.hpp" #include "GamePlayer.h" #include "models/SimpleModel.h" #include "models/GLTFModel.h" -class WrapperGamePlayer -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void Message(const v8::FunctionCallbackInfo& info); +#include "WrapperGamePlayer.h" - static void HasFont(const v8::FunctionCallbackInfo& info); - static void CreateFontFromFile(const v8::FunctionCallbackInfo& info); - static void CreateFontFromMemory(const v8::FunctionCallbackInfo& info); +GamePlayer* WrapperGamePlayer::s_game_player = nullptr; - static void GetPicking(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetPicking(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +void WrapperGamePlayer::define(ObjectDefinition& object) +{ + object.name = "gamePlayer"; + object.ctor = ctor; + object.dtor = dtor; + object.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + { "picking", GetPicking, SetPicking } + }; + + object.methods = { + { "message", Message }, + { "hasFont", HasFont }, + { "createFontFromFile", CreateFontFromFile }, + { "createFontFromMemory", CreateFontFromMemory }, + { "pickObject", PickObject }, + }; - static void PickObject(const v8::FunctionCallbackInfo& info); -}; +} +void* WrapperGamePlayer::ctor() +{ + return s_game_player; +} -v8::Local WrapperGamePlayer::create_template(v8::Isolate* isolate) +void WrapperGamePlayer::dtor(void* ptr, GameContext* ctx) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->SetInternalFieldCount(1); - templ->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - templ->Set(isolate, "message", v8::FunctionTemplate::New(isolate, Message)); - templ->Set(isolate, "hasFont", v8::FunctionTemplate::New(isolate, HasFont)); - templ->Set(isolate, "createFontFromFile", v8::FunctionTemplate::New(isolate, CreateFontFromFile)); - templ->Set(isolate, "createFontFromMemory", v8::FunctionTemplate::New(isolate, CreateFontFromMemory)); - templ->SetAccessor(v8::String::NewFromUtf8(isolate, "picking").ToLocalChecked(), GetPicking, SetPicking); - templ->Set(isolate, "pickObject", v8::FunctionTemplate::New(isolate, PickObject)); - return templ; + } + void WrapperGamePlayer::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - GamePlayer* self = lctx.self(); + GamePlayer* self = lctx.self(); info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); } @@ -57,7 +55,7 @@ void WrapperGamePlayer::GetHeight(v8::Local property, const v8::Prop } void WrapperGamePlayer::Message(const v8::FunctionCallbackInfo& info) -{ +{ LocalContext lctx(info); GamePlayer* self = lctx.self(); std::string name = lctx.jstr_to_str(info[0]); @@ -88,7 +86,7 @@ void WrapperGamePlayer::CreateFontFromMemory(const v8::FunctionCallbackInfo(); - std::string name = lctx.jstr_to_str(info[0]); + std::string name = lctx.jstr_to_str(info[0]); v8::Local data = info[1].As(); self->UIRenderer().CreateFont(name.c_str(), (unsigned char*)data->GetBackingStore()->Data(), data->ByteLength()); } @@ -128,7 +126,7 @@ void WrapperGamePlayer::PickObject(const v8::FunctionCallbackInfo& in lctx.set_property(ret, "name", name); lctx.set_property(ret, "uuid", uuid); - if (idxInfo.primitive_idx==0) + if (idxInfo.primitive_idx == 0) { lctx.set_property(ret, "mesh_id", lctx.num_to_jnum(0)); lctx.set_property(ret, "prim_id", lctx.num_to_jnum(0)); @@ -152,7 +150,7 @@ void WrapperGamePlayer::PickObject(const v8::FunctionCallbackInfo& in if (prim_idx == idxInfo.primitive_idx) break; } } - + info.GetReturnValue().Set(ret); } else @@ -160,4 +158,5 @@ void WrapperGamePlayer::PickObject(const v8::FunctionCallbackInfo& in info.GetReturnValue().SetNull(); } -} \ No newline at end of file +} + diff --git a/Three.V8/WrapperGamePlayer.h b/Three.V8/WrapperGamePlayer.h new file mode 100644 index 00000000..12b9a646 --- /dev/null +++ b/Three.V8/WrapperGamePlayer.h @@ -0,0 +1,30 @@ +#pragma once + +#include "definitions.hpp" + +class GamePlayer; +class WrapperGamePlayer +{ +public: + static GamePlayer* s_game_player; + static void define(ObjectDefinition& object); + +private: + static void* ctor(); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void Message(const v8::FunctionCallbackInfo& info); + + static void HasFont(const v8::FunctionCallbackInfo& info); + static void CreateFontFromFile(const v8::FunctionCallbackInfo& info); + static void CreateFontFromMemory(const v8::FunctionCallbackInfo& info); + + static void GetPicking(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetPicking(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void PickObject(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/WrapperUtils.hpp b/Three.V8/WrapperUtils.hpp index 2bc31f9b..c81af609 100644 --- a/Three.V8/WrapperUtils.hpp +++ b/Three.V8/WrapperUtils.hpp @@ -35,6 +35,40 @@ class LocalContext } + inline v8::Local get_global(const char* path) + { + std::string s_path = path; + v8::Local value = context->Global(); + + size_t start = 0; + size_t end = s_path.find('.', start); + if (end == std::string::npos) + { + end = s_path.length(); + } + while (end>start) + { + std::string key = s_path.substr(start, end - start); + value = get_property(value.As(), key.c_str()); + if (end < s_path.length()) + { + start = end + 1; + end = s_path.find('.', start); + if (end == std::string::npos) + { + end = s_path.length(); + } + } + else + { + start = end; + } + } + + return value; + + } + inline GameContext* ctx() { v8::Local global = context->Global(); @@ -44,8 +78,8 @@ class LocalContext inline GamePlayer* player() { - GameContext* _ctx = ctx(); - return _ctx->GetGamePlayer(); + v8::Local value = get_global("gamePlayer"); + return jobj_to_obj(value); } inline void* get_self() @@ -67,8 +101,8 @@ class LocalContext v8::Local instantiate(const char* cls_name) { - v8::Local global = context->Global(); - v8::Local ctor = get_property(global, cls_name).As(); + v8::Local value = get_global(cls_name); + v8::Local ctor = value.As(); return ctor->CallAsConstructor(context, 0, nullptr).ToLocalChecked().As(); } @@ -658,14 +692,6 @@ class LocalContext } }; -void GeneralDispose(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - GameContext* ctx = lctx.ctx(); - void* self = lctx.get_self(); - ctx->remove_object(self); -} - inline std::vector SplitWithCharacters(const std::string& str, int splitLength) { int NumSubstrings = str.length() / splitLength; @@ -701,4 +727,5 @@ inline void string_to_color(const char* str, glm::u8vec4& color) color.g = (uint8_t)stoi(colori[2], nullptr, 16); color.b = (uint8_t)stoi(colori[3], nullptr, 16); -} \ No newline at end of file +} + diff --git a/Three.V8/backgrounds/Background.hpp b/Three.V8/backgrounds/Background.hpp deleted file mode 100644 index d7fbbf85..00000000 --- a/Three.V8/backgrounds/Background.hpp +++ /dev/null @@ -1,255 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include -#include - -class WrapperColorBackground -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetColor(const v8::FunctionCallbackInfo& info); - static void SetColor(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperColorBackground::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "color").ToLocalChecked(), GetColor, 0); - templ->InstanceTemplate()->Set(isolate, "getColor", v8::FunctionTemplate::New(isolate, GetColor)); - templ->InstanceTemplate()->Set(isolate, "setColor", v8::FunctionTemplate::New(isolate, SetColor)); - - return templ; -} - -void WrapperColorBackground::dtor(void* ptr, GameContext* ctx) -{ - delete (ColorBackground*)ptr; -} - - -void WrapperColorBackground::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - ColorBackground* self = new ColorBackground(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - -void WrapperColorBackground::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - ColorBackground* self = lctx.self(); - v8::Local position = v8::Object::New(lctx.isolate); - lctx.vec3_to_jvec3(self->color, position); - info.GetReturnValue().Set(position); -} - -void WrapperColorBackground::GetColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - ColorBackground* self = lctx.self(); - lctx.vec3_to_jvec3(self->color, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperColorBackground::SetColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - ColorBackground* self = lctx.self(); - if (info[0]->IsNumber()) - { - lctx.jnum_to_num(info[0], self->color.x); - lctx.jnum_to_num(info[1], self->color.y); - lctx.jnum_to_num(info[2], self->color.z); - } - else - { - lctx.jvec3_to_vec3(info[0], self->color); - } -} - - -class WrapperCubeBackground -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void SetCubemap(const v8::FunctionCallbackInfo& info); - -}; - - -v8::Local WrapperCubeBackground::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "setCubemap", v8::FunctionTemplate::New(isolate, SetCubemap)); - return templ; -} - - -void WrapperCubeBackground::dtor(void* ptr, GameContext* ctx) -{ - delete (CubeBackground*)ptr; -} - - -void WrapperCubeBackground::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - CubeBackground* self = new CubeBackground(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - -void WrapperCubeBackground::SetCubemap(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - CubeBackground* self = lctx.self(); - - if (info[0]->IsNull()) - { - self->cubemap.unload(); - } - else - { - CubeImage* image = lctx.jobj_to_obj(info[0]); - self->cubemap.load_memory_rgba(image->images[0].width(), image->images[0].height(), - image->images[0].data(), image->images[1].data(), image->images[2].data(), image->images[3].data(), image->images[4].data(), image->images[5].data()); - } -} - -class WrapperHemisphereBackground -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSkyColor(const v8::FunctionCallbackInfo& info); - static void SetSkyColor(const v8::FunctionCallbackInfo& info); - - static void GetGroundColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetGroundColor(const v8::FunctionCallbackInfo& info); - static void SetGroundColor(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperHemisphereBackground::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "skyColor").ToLocalChecked(), GetSkyColor, 0); - templ->InstanceTemplate()->Set(isolate, "getSkyColor", v8::FunctionTemplate::New(isolate, GetSkyColor)); - templ->InstanceTemplate()->Set(isolate, "setSkyColor", v8::FunctionTemplate::New(isolate, SetSkyColor)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "groundColor").ToLocalChecked(), GetGroundColor, 0); - templ->InstanceTemplate()->Set(isolate, "getGroundColor", v8::FunctionTemplate::New(isolate, GetGroundColor)); - templ->InstanceTemplate()->Set(isolate, "setGroundColor", v8::FunctionTemplate::New(isolate, SetGroundColor)); - - return templ; -} - - -void WrapperHemisphereBackground::dtor(void* ptr, GameContext* ctx) -{ - delete (HemisphereBackground*)ptr; -} - -void WrapperHemisphereBackground::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = new HemisphereBackground(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperHemisphereBackground::GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = new HemisphereBackground(); - v8::Local position = v8::Object::New(lctx.isolate); - lctx.vec3_to_jvec3(self->skyColor, position); - info.GetReturnValue().Set(position); -} - -void WrapperHemisphereBackground::GetSkyColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = new HemisphereBackground(); - lctx.vec3_to_jvec3(self->skyColor, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperHemisphereBackground::SetSkyColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = lctx.self(); - if (info[0]->IsNumber()) - { - lctx.jnum_to_num(info[0], self->skyColor.x); - lctx.jnum_to_num(info[1], self->skyColor.y); - lctx.jnum_to_num(info[2], self->skyColor.z); - } - else - { - lctx.jvec3_to_vec3(info[0], self->skyColor); - } -} - - -void WrapperHemisphereBackground::GetGroundColor(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = new HemisphereBackground(); - v8::Local position = v8::Object::New(lctx.isolate); - lctx.vec3_to_jvec3(self->groundColor, position); - info.GetReturnValue().Set(position); -} - -void WrapperHemisphereBackground::GetGroundColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = new HemisphereBackground(); - lctx.vec3_to_jvec3(self->groundColor, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperHemisphereBackground::SetGroundColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HemisphereBackground* self = lctx.self(); - if (info[0]->IsNumber()) - { - lctx.jnum_to_num(info[0], self->groundColor.x); - lctx.jnum_to_num(info[1], self->groundColor.y); - lctx.jnum_to_num(info[2], self->groundColor.z); - } - else - { - lctx.jvec3_to_vec3(info[0], self->groundColor); - } -} diff --git a/Three.V8/backgrounds/WrapperBackground.cpp b/Three.V8/backgrounds/WrapperBackground.cpp new file mode 100644 index 00000000..f2508827 --- /dev/null +++ b/Three.V8/backgrounds/WrapperBackground.cpp @@ -0,0 +1,195 @@ +#include "WrapperUtils.hpp" +#include +#include + +#include "WrapperBackground.h" + +void WrapperColorBackground::define(ClassDefinition& cls) +{ + cls.name = "ColorBackground"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "color", GetColor }, + }; + cls.methods = { + {"getColor", GetColor }, + {"setColor", SetColor }, + }; +} + +void* WrapperColorBackground::ctor(const v8::FunctionCallbackInfo& info) +{ + return new ColorBackground; +} + +void WrapperColorBackground::dtor(void* ptr, GameContext* ctx) +{ + delete (ColorBackground*)ptr; +} + +void WrapperColorBackground::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + ColorBackground* self = lctx.self(); + v8::Local position = v8::Object::New(lctx.isolate); + lctx.vec3_to_jvec3(self->color, position); + info.GetReturnValue().Set(position); +} + +void WrapperColorBackground::GetColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + ColorBackground* self = lctx.self(); + lctx.vec3_to_jvec3(self->color, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperColorBackground::SetColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + ColorBackground* self = lctx.self(); + if (info[0]->IsNumber()) + { + lctx.jnum_to_num(info[0], self->color.x); + lctx.jnum_to_num(info[1], self->color.y); + lctx.jnum_to_num(info[2], self->color.z); + } + else + { + lctx.jvec3_to_vec3(info[0], self->color); + } +} + + +void WrapperCubeBackground::define(ClassDefinition& cls) +{ + cls.name = "CubeBackground"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"setCubemap", SetCubemap }, + }; +} + +void* WrapperCubeBackground::ctor(const v8::FunctionCallbackInfo& info) +{ + return new CubeBackground; +} + +void WrapperCubeBackground::dtor(void* ptr, GameContext* ctx) +{ + delete (CubeBackground*)ptr; +} + +void WrapperCubeBackground::SetCubemap(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + CubeBackground* self = lctx.self(); + + if (info[0]->IsNull()) + { + self->cubemap.unload(); + } + else + { + CubeImage* image = lctx.jobj_to_obj(info[0]); + self->cubemap.load_memory_rgba(image->images[0].width(), image->images[0].height(), + image->images[0].data(), image->images[1].data(), image->images[2].data(), image->images[3].data(), image->images[4].data(), image->images[5].data()); + } +} + +void WrapperHemisphereBackground::define(ClassDefinition& cls) +{ + cls.name = "HemisphereBackground"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "skyColor", GetSkyColor }, + { "groundColor", GetGroundColor }, + }; + cls.methods = { + { "getSkyColor", GetSkyColor }, + { "setSkyColor", SetSkyColor }, + { "getGroundColor", GetGroundColor }, + { "setGroundColor", SetGroundColor }, + }; +} + +void* WrapperHemisphereBackground::ctor(const v8::FunctionCallbackInfo& info) +{ + return new HemisphereBackground; +} + +void WrapperHemisphereBackground::dtor(void* ptr, GameContext* ctx) +{ + delete (HemisphereBackground*)ptr; +} + + +void WrapperHemisphereBackground::GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + HemisphereBackground* self = new HemisphereBackground(); + v8::Local position = v8::Object::New(lctx.isolate); + lctx.vec3_to_jvec3(self->skyColor, position); + info.GetReturnValue().Set(position); +} + +void WrapperHemisphereBackground::GetSkyColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + HemisphereBackground* self = new HemisphereBackground(); + lctx.vec3_to_jvec3(self->skyColor, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperHemisphereBackground::SetSkyColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + HemisphereBackground* self = lctx.self(); + if (info[0]->IsNumber()) + { + lctx.jnum_to_num(info[0], self->skyColor.x); + lctx.jnum_to_num(info[1], self->skyColor.y); + lctx.jnum_to_num(info[2], self->skyColor.z); + } + else + { + lctx.jvec3_to_vec3(info[0], self->skyColor); + } +} + + +void WrapperHemisphereBackground::GetGroundColor(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + HemisphereBackground* self = new HemisphereBackground(); + v8::Local position = v8::Object::New(lctx.isolate); + lctx.vec3_to_jvec3(self->groundColor, position); + info.GetReturnValue().Set(position); +} + +void WrapperHemisphereBackground::GetGroundColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + HemisphereBackground* self = new HemisphereBackground(); + lctx.vec3_to_jvec3(self->groundColor, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperHemisphereBackground::SetGroundColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + HemisphereBackground* self = lctx.self(); + if (info[0]->IsNumber()) + { + lctx.jnum_to_num(info[0], self->groundColor.x); + lctx.jnum_to_num(info[1], self->groundColor.y); + lctx.jnum_to_num(info[2], self->groundColor.z); + } + else + { + lctx.jvec3_to_vec3(info[0], self->groundColor); + } +} diff --git a/Three.V8/backgrounds/WrapperBackground.h b/Three.V8/backgrounds/WrapperBackground.h new file mode 100644 index 00000000..75d7a494 --- /dev/null +++ b/Three.V8/backgrounds/WrapperBackground.h @@ -0,0 +1,54 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + + +class WrapperColorBackground +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetColor(const v8::FunctionCallbackInfo& info); + static void SetColor(const v8::FunctionCallbackInfo& info); +}; + +class WrapperCubeBackground +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void SetCubemap(const v8::FunctionCallbackInfo& info); +}; + + +class WrapperHemisphereBackground +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSkyColor(const v8::FunctionCallbackInfo& info); + static void SetSkyColor(const v8::FunctionCallbackInfo& info); + + static void GetGroundColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetGroundColor(const v8::FunctionCallbackInfo& info); + static void SetGroundColor(const v8::FunctionCallbackInfo& info); + +}; + + diff --git a/Three.V8/backgrounds/BackgroundScene.hpp b/Three.V8/backgrounds/WrapperBackgroundScene.cpp similarity index 53% rename from Three.V8/backgrounds/BackgroundScene.hpp rename to Three.V8/backgrounds/WrapperBackgroundScene.cpp index 453a1168..bac8cd90 100644 --- a/Three.V8/backgrounds/BackgroundScene.hpp +++ b/Three.V8/backgrounds/WrapperBackgroundScene.cpp @@ -1,50 +1,26 @@ -#pragma once - #include "WrapperUtils.hpp" #include -class WrapperBackgroundScene -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void GetScene(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetScene(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetNear(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetNear(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +#include "WrapperBackgroundScene.h" - static void GetFar(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetFar(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperBackgroundScene::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scene").ToLocalChecked(), GetScene, SetScene); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "near").ToLocalChecked(), GetNear, SetNear); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "far").ToLocalChecked(), GetFar, SetFar); - return templ; -} -void WrapperBackgroundScene::dtor(void* ptr, GameContext* ctx) +void WrapperBackgroundScene::define(ClassDefinition& cls) { - delete (BackgroundScene*)ptr; + cls.name = "BackgroundScene"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "scene", GetScene, SetScene }, + { "near", GetNear, SetNear }, + { "far", GetFar, SetFar }, + }; } - -void WrapperBackgroundScene::New(const v8::FunctionCallbackInfo& info) +void* WrapperBackgroundScene::ctor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); Scene* scene = nullptr; - float z_near = 10.0f; + float z_near = 10.0f; float z_far = 10000.0f; if (info.Length() > 0) @@ -65,11 +41,15 @@ void WrapperBackgroundScene::New(const v8::FunctionCallbackInfo& info } } } - BackgroundScene* self = new BackgroundScene(scene, z_near, z_far); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + return new BackgroundScene(scene, z_near, z_far); } +void WrapperBackgroundScene::dtor(void* ptr, GameContext* ctx) +{ + delete (BackgroundScene*)ptr; +} + + void WrapperBackgroundScene::GetScene(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); diff --git a/Three.V8/backgrounds/WrapperBackgroundScene.h b/Three.V8/backgrounds/WrapperBackgroundScene.h new file mode 100644 index 00000000..296f3945 --- /dev/null +++ b/Three.V8/backgrounds/WrapperBackgroundScene.h @@ -0,0 +1,25 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperBackgroundScene +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetScene(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetScene(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetNear(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetNear(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetFar(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetFar(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; + diff --git a/Three.V8/binding.cpp b/Three.V8/binding.cpp index 7113905c..a7efe3cb 100644 --- a/Three.V8/binding.cpp +++ b/Three.V8/binding.cpp @@ -1,6 +1,8 @@ #include -#include +#include +#include #include "binding.h" +#include "WrapperUtils.hpp" V8VM::V8VM(const char* exec_path) { @@ -28,193 +30,9 @@ V8VM::~V8VM() delete m_array_buffer_allocator; } - -#include "utils/Image.hpp" -#include "utils/HDRImage.hpp" -#include "utils/DDSImage.hpp" - -#include "core/Object3D.hpp" - -#include "cameras/Camera.hpp" -#include "cameras/PerspectiveCamera.hpp" -#include "cameras/Reflector.hpp" - -#include "backgrounds/Background.hpp" -#include "backgrounds/BackgroundScene.hpp" -#include "lights/DirectionalLight.hpp" -#include "lights/EnvironmentMap.hpp" -#include "lights/ProbeGrid.hpp" -#include "lights/LODProbeGrid.hpp" -#include "lights/EnvironmentMapCreator.hpp" -#include "lights/AmbientLight.hpp" -#include "lights/HemisphereLight.hpp" -#include "lights/ProbeGridWidget.hpp" -#include "lights/LODProbeGridWidget.hpp" - -#include "models/SimpleModel.hpp" -#include "models/GLTFModel.hpp" -#include "models/AnimationMixer.hpp" - -#include "scenes/Scene.hpp" -#include "scenes/Fog.hpp" - -#include "renderers/GLRenderer.hpp" -#include "renderers/GLRenderTarget.hpp" -#include "renderers/CubeRenderTarget.hpp" - -#include "core/BoundingVolumeHierarchy.hpp" - -#include "GamePlayer.hpp" -#include "network/HttpClient.hpp" -#include "network/WSClient.hpp" -#include "loaders/FileLoader.hpp" -#include "loaders/ImageLoader.hpp" -#include "loaders/HDRImageLoader.hpp" -#include "loaders/DDSImageLoader.hpp" -#include "loaders/GLTFLoader.hpp" -#include "loaders/ProbeGridLoader.hpp" -#include "loaders/LODProbeGridLoader.hpp" -#include "savers/FileSaver.hpp" -#include "savers/ImageSaver.hpp" -#include "savers/HDRImageSaver.hpp" -#include "savers/ProbeGridSaver.hpp" -#include "savers/LODProbeGridSaver.hpp" - -#include "gui/UIManager.hpp" -#include "gui/UIArea.hpp" -#include "gui/UIBlock.hpp" -#include "gui/UIPanel.hpp" -#include "gui/UIButton.hpp" -#include "gui/UIScrollViewer.hpp" -#include "gui/UILineEdit.hpp" -#include "gui/UIText.hpp" -#include "gui/UITextBlock.hpp" -#include "gui/UIImage.hpp" -#include "gui/UI3DViewer.hpp" -#include "gui/UIDraggable.hpp" - -#if THREE_MM -#include "multimedia/MMCamera.hpp" -#include "multimedia/MMLazyVideo.hpp" -#include "multimedia/MMAudio.hpp" -#include "multimedia/MMVideo.hpp" -#include "multimedia/OpusRecorder.hpp" -#include "multimedia/OpusPlayer.hpp" -#include "multimedia/AVCRecorder.hpp" -#include "multimedia/AVCPlayer.hpp" -#endif - -#include "volume/VolumeData.hpp" -#include "volume/VolumeIsosurfaceModel.hpp" -#include "volume/VolumeDataLoader.hpp" - -#include "models/HeightField.hpp" - -#include "utils/Text.hpp" - -GlobalDefinitions GameContext::s_globals = +GameContext::GameContext(V8VM* vm, const WorldDefinition& world_definition, const char* filename): m_vm(vm) { - { - {"print", GameContext::Print}, - {"setCallback", GameContext::SetCallback}, - {"now", GameContext::Now}, - {"getGLError", GameContext::GetGLError}, -#if THREE_MM - {"getListOfCameras", GameContext::GetListOfCameras}, - {"getListOfAudioDevices", GameContext::GetListOfAudioDevices}, -#endif - {"generalCall", GameContext::GeneralCall}, - }, - { - { "Object3D", WrapperObject3D::New, WrapperObject3D::create_template }, - { "Camera", WrapperCamera::New, WrapperCamera::create_template }, - { "PerspectiveCamera", WrapperPerspectiveCamera::New, WrapperPerspectiveCamera::create_template }, - { "Reflector", WrapperReflector::New, WrapperReflector::create_template }, - { "ColorBackground", WrapperColorBackground::New, WrapperColorBackground::create_template }, - { "CubeBackground", WrapperCubeBackground::New, WrapperCubeBackground::create_template }, - { "HemisphereBackground", WrapperHemisphereBackground::New, WrapperHemisphereBackground::create_template }, - { "BackgroundScene", WrapperBackgroundScene::New, WrapperBackgroundScene::create_template }, - { "Scene", WrapperScene::New, WrapperScene::create_template }, - { "Fog", WrapperFog::New, WrapperFog::create_template }, - { "GLRenderer", WrapperGLRenderer::New, WrapperGLRenderer::create_template }, - { "GLRenderTarget", WrapperGLRenderTarget::New, WrapperGLRenderTarget::create_template }, - { "CubeRenderTarget", WrapperCubeRenderTarget::New, WrapperCubeRenderTarget::create_template }, - { "SimpleModel", WrapperSimpleModel::New, WrapperSimpleModel::create_template }, - { "GLTFModel", WrapperGLTFModel::New, WrapperGLTFModel::create_template }, - { "AnimationMixer", WrapperAnimationMixer::New, WrapperAnimationMixer::create_template }, - { "Image", WrapperImage::New, WrapperImage::create_template }, - { "CubeImage", WrapperCubeImage::New, WrapperCubeImage::create_template }, - { "HDRImage", WrapperHDRImage::New, WrapperHDRImage::create_template }, - { "HDRCubeImage", WrapperHDRCubeImage::New, WrapperHDRCubeImage::create_template }, - { "DDSImage", WrapperDDSImage::New, WrapperDDSImage::create_template }, - { "DirectionalLight", WrapperDirectionalLight::New, WrapperDirectionalLight::create_template }, - { "EnvironmentMap", WrapperEnvironmentMap::New, WrapperEnvironmentMap::create_template }, - { "ProbeGrid", WrapperProbeGrid::New, WrapperProbeGrid::create_template }, - { "LODProbeGrid", WrapperLODProbeGrid::New, WrapperLODProbeGrid::create_template }, - { "EnvironmentMapCreator", WrapperEnvironmentMapCreator::New, WrapperEnvironmentMapCreator::create_template}, - { "AmbientLight", WrapperAmbientLight::New, WrapperAmbientLight::create_template}, - { "HemisphereLight", WrapperHemisphereLight::New, WrapperHemisphereLight::create_template}, - { "ProbeGridWidget", WrapperProbeGridWidget::New, WrapperProbeGridWidget::create_template}, - { "LODProbeGridWidget", WrapperLODProbeGridWidget::New, WrapperLODProbeGridWidget::create_template}, - { "BoundingVolumeHierarchy", WrappeBoundingVolumeHierarchy::New, WrappeBoundingVolumeHierarchy::create_template}, - - { "UIArea", WrapperUIArea::New, WrapperUIArea::create_template}, - { "UIBlock", WrapperUIBlock::New, WrapperUIBlock::create_template}, - { "UIPanel", WrapperUIPanel::New, WrapperUIPanel::create_template}, - { "UIButton", WrapperUIButton::New, WrapperUIButton::create_template}, - { "UIScrollViewer", WrapperUIScrollViewer::New, WrapperUIScrollViewer::create_template}, - { "UILineEdit", WrapperUILineEdit::New, WrapperUILineEdit::create_template}, - { "UIText", WrapperUIText::New, WrapperUIText::create_template}, - { "UITextBlock", WrapperUITextBlock::New, WrapperUITextBlock::create_template}, - { "UIImage", WrapperUIImage::New, WrapperUIImage::create_template}, - { "UI3DViewer", WrapperUI3DViewer::New, WrapperUI3DViewer::create_template}, - { "UIDraggable", WrapperUIDraggable::New, WrapperUIDraggable::create_template}, - -#if THREE_MM - { "MMCamera", WrapperMMCamera::New, WrapperMMCamera::create_template}, - { "MMLazyVideo", WrapperMMLazyVideo::New, WrapperMMLazyVideo::create_template}, - { "MMAudio", WrapperMMAudio::New, WrapperMMAudio::create_template}, - { "MMVideo", WrapperMMVideo::New, WrapperMMVideo::create_template}, - { "OpusRecorder", WrapperOpusRecorder::New, WrapperOpusRecorder::create_template}, - { "OpusPlayer", WrapperOpusPlayer::New, WrapperOpusPlayer::create_template}, - { "AVCRecorder", WrapperAVCRecorder::New, WrapperAVCRecorder::create_template}, - { "AVCPlayer", WrapperAVCPlayer::New, WrapperAVCPlayer::create_template}, -#endif - { "VolumeData", WrapperVolumeData::New, WrapperVolumeData::create_template}, - { "VolumeIsosurfaceModel", WrapperVolumeIsosurfaceModel::New, WrapperVolumeIsosurfaceModel::create_template}, - - { "WSClient", WrapperWSClient::New, WrapperWSClient::create_template}, - - { "HeightField", WrapperHeightField::New, WrapperHeightField::create_template}, - - }, - { - { "fileLoader", WrapperFileLoader::create_template }, - { "imageLoader", WrapperImageLoader::create_template}, - { "HDRImageLoader", WrapperHDRImageLoader::create_template}, - { "DDSImageLoader", WrapperDDSImageLoader::create_template}, - { "gltfLoader", WrapperGLTFLoader::create_template}, - { "probeGridLoader", WrapperProbeGridLoader::create_template}, - { "LODProbeGridLoader", WrapperLODProbeGridLoader::create_template}, - { "fileSaver", WrapperFileSaver::create_template}, - { "imageSaver", WrapperImageSaver::create_template}, - { "HDRImageSaver", WrapperHDRImageSaver::create_template}, - { "probeGridSaver", WrapperProbeGridSaver::create_template}, - { "LODProbeGridSaver", WrapperLODProbeGridSaver::create_template}, - - { "volumeDataLoader", WrapperVolumeDataLoader::create_template}, - - { "text", WrapperText::create_template}, - } -}; - -GameContext::GameContext(V8VM* vm, GamePlayer* gamePlayer, const char* filename) - : m_vm(vm) - , m_gamePlayer(gamePlayer) - , m_http(new HttpClient) - , m_ui_manager(new UIManager) -{ - _create_context(); + _create_context(world_definition); v8::HandleScope handle_scope(m_vm->m_isolate); v8::Context::Scope context_scope(m_context.Get(m_vm->m_isolate)); _run_script(filename); @@ -232,7 +50,26 @@ GameContext::~GameContext() } } -void GameContext::_create_context() +void GameContext::GeneralNew(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + int idx_ctor_dtor; + lctx.jnum_to_num(info.Data(), idx_ctor_dtor); + CtorDtor ctor_dtor = lctx.ctx()->m_cls_ctor_dtor[idx_ctor_dtor]; + void* ptr = ctor_dtor.ctor(info); + info.This()->SetAlignedPointerInInternalField(0, ptr); + lctx.ctx()->regiter_object(info.This(), ctor_dtor.dtor); +} + +void GameContext::GeneralDispose(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + GameContext* ctx = lctx.ctx(); + void* self = lctx.get_self(); + ctx->remove_object(self); +} + +void GameContext::_create_context(const WorldDefinition& world_definition) { v8::Isolate* isolate = m_vm->m_isolate; v8::HandleScope handle_scope(isolate); @@ -240,52 +77,167 @@ void GameContext::_create_context() v8::Local global_tmpl = v8::ObjectTemplate::New(isolate); global_tmpl->SetInternalFieldCount(1); - for (size_t i = 0; i < s_globals.funcs.size(); i++) + const ModuleDefinition& default_module = world_definition.default_module; + + // functions + const std::vector& functions = default_module.functions; + for (size_t i = 0; i < functions.size(); i++) { - const FunctionDefinition& func = s_globals.funcs[i]; + const FunctionDefinition& func = functions[i]; global_tmpl->Set(isolate, func.name.c_str(), v8::FunctionTemplate::New(isolate, func.func)); } - for (size_t i = 0; i < s_globals.classes.size(); i++) + // classes + const std::vector& classes = default_module.classes; + for (size_t i = 0; i < classes.size(); i++) { - const ClassDefinition& cls = s_globals.classes[i]; - global_tmpl->Set(isolate, cls.name.c_str(), cls.creator(isolate, cls.constructor)); + const ClassDefiner& cls_define = classes[i]; + ClassDefinition def; + cls_define(def); + + int idx_ctor_dtor = (int)m_cls_ctor_dtor.size(); + m_cls_ctor_dtor.push_back({ def.ctor, def.dtor }); + v8::Local templ = v8::FunctionTemplate::New(isolate, GeneralNew, v8::Number::New(isolate, idx_ctor_dtor)); + templ->InstanceTemplate()->SetInternalFieldCount(2); + templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); + + for (size_t j = 0; j < def.properties.size(); j++) + { + const AccessorDefinition& property = def.properties[j]; + templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, property.name.c_str()).ToLocalChecked(), property.get, property.set); + } + + for (size_t j = 0; j < def.methods.size(); j++) + { + const FunctionDefinition& method = def.methods[j]; + templ->InstanceTemplate()->Set(isolate, method.name.c_str(), v8::FunctionTemplate::New(isolate, method.func)); + } + + global_tmpl->Set(isolate, def.name.c_str(), templ); } - + v8::Local context = v8::Context::New(isolate, NULL, global_tmpl); v8::Local global_obj = context->Global(); global_obj->SetAlignedPointerInInternalField(0, this); - // gamePlayer + // global objects + const std::vector& objects = default_module.objects; + for (size_t i = 0; i < objects.size(); i++) { - v8::Local templ = WrapperGamePlayer::create_template(isolate); - v8::Local obj = templ->NewInstance(context).ToLocalChecked(); - obj->SetAlignedPointerInInternalField(0, m_gamePlayer); - global_obj->Set(context, v8::String::NewFromUtf8(isolate, "gamePlayer").ToLocalChecked(), obj); - } + const ObjectDefiner& obj_define = objects[i]; + ObjectDefinition def; + obj_define(def); - // http - { - v8::Local templ = WrapperHttpClient::create_template(isolate); - v8::Local obj = templ->NewInstance(context).ToLocalChecked(); - obj->SetAlignedPointerInInternalField(0, m_http.get()); - global_obj->Set(context, v8::String::NewFromUtf8(isolate, "http").ToLocalChecked(), obj); - } + v8::Local templ = v8::ObjectTemplate::New(isolate); + if (def.ctor != nullptr) + { + templ->SetInternalFieldCount(2); + } + + for (size_t j = 0; j < def.properties.size(); j++) + { + const AccessorDefinition& property = def.properties[j]; + templ->SetAccessor(v8::String::NewFromUtf8(isolate, property.name.c_str()).ToLocalChecked(), property.get, property.set); + } + + for (size_t j = 0; j < def.methods.size(); j++) + { + const FunctionDefinition& method = def.methods[j]; + templ->Set(isolate, method.name.c_str(), v8::FunctionTemplate::New(isolate, method.func)); + } - // ui-manager - { - v8::Local templ = WrapperUIManager::create_template(isolate); v8::Local obj = templ->NewInstance(context).ToLocalChecked(); - obj->SetAlignedPointerInInternalField(0, m_ui_manager.get()); - global_obj->Set(context, v8::String::NewFromUtf8(isolate, "UIManager").ToLocalChecked(), obj); + if (def.ctor != nullptr) + { + obj->SetAlignedPointerInInternalField(0, def.ctor()); + regiter_object(obj, def.dtor); + } + global_obj->Set(context, v8::String::NewFromUtf8(isolate, def.name.c_str()).ToLocalChecked(), obj); } - - for (size_t i = 0; i < s_globals.objects.size(); i++) + + // additional modules + const std::vector& modules = world_definition.modules; + for (size_t m = 0; m < modules.size(); m++) { - const ObjectDefinition& d_obj = s_globals.objects[i]; - v8::Local templ = d_obj.creator(isolate); - v8::Local obj = templ->NewInstance(context).ToLocalChecked(); - global_obj->Set(context, v8::String::NewFromUtf8(isolate, d_obj.name.c_str()).ToLocalChecked(), obj); + const ModuleDefinition& mod = modules[m]; + + v8::Local mod_tmpl = v8::ObjectTemplate::New(isolate); + + // functions + const std::vector& functions = mod.functions; + for (size_t i = 0; i < functions.size(); i++) + { + const FunctionDefinition& func = functions[i]; + mod_tmpl->Set(isolate, func.name.c_str(), v8::FunctionTemplate::New(isolate, func.func)); + } + + // classes + const std::vector& classes = mod.classes; + for (size_t i = 0; i < classes.size(); i++) + { + const ClassDefiner& cls_define = classes[i]; + ClassDefinition def; + cls_define(def); + + int idx_ctor_dtor = (int)m_cls_ctor_dtor.size(); + m_cls_ctor_dtor.push_back({ def.ctor, def.dtor }); + v8::Local templ = v8::FunctionTemplate::New(isolate, GeneralNew, v8::Number::New(isolate, idx_ctor_dtor)); + templ->InstanceTemplate()->SetInternalFieldCount(2); + templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); + + for (size_t j = 0; j < def.properties.size(); j++) + { + const AccessorDefinition& property = def.properties[j]; + templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, property.name.c_str()).ToLocalChecked(), property.get, property.set); + } + + for (size_t j = 0; j < def.methods.size(); j++) + { + const FunctionDefinition& method = def.methods[j]; + templ->InstanceTemplate()->Set(isolate, method.name.c_str(), v8::FunctionTemplate::New(isolate, method.func)); + } + + mod_tmpl->Set(isolate, def.name.c_str(), templ); + } + + v8::Local obj_mod = mod_tmpl->NewInstance(context).ToLocalChecked(); + + // objects + const std::vector& objects = mod.objects; + for (size_t i = 0; i < objects.size(); i++) + { + const ObjectDefiner& obj_define = objects[i]; + ObjectDefinition def; + obj_define(def); + + v8::Local templ = v8::ObjectTemplate::New(isolate); + if (def.ctor != nullptr) + { + templ->SetInternalFieldCount(2); + } + + for (size_t j = 0; j < def.properties.size(); j++) + { + const AccessorDefinition& property = def.properties[j]; + templ->SetAccessor(v8::String::NewFromUtf8(isolate, property.name.c_str()).ToLocalChecked(), property.get, property.set); + } + + for (size_t j = 0; j < def.methods.size(); j++) + { + const FunctionDefinition& method = def.methods[j]; + templ->Set(isolate, method.name.c_str(), v8::FunctionTemplate::New(isolate, method.func)); + } + + v8::Local obj = templ->NewInstance(context).ToLocalChecked(); + if (def.ctor != nullptr) + { + obj->SetAlignedPointerInInternalField(0, def.ctor()); + regiter_object(obj, def.dtor); + } + obj_mod->Set(context, v8::String::NewFromUtf8(isolate, def.name.c_str()).ToLocalChecked(), obj); + } + + global_obj->Set(context, v8::String::NewFromUtf8(isolate, mod.name.c_str()).ToLocalChecked(), obj_mod); } //context->AllowCodeGenerationFromStrings(false); @@ -294,7 +246,7 @@ void GameContext::_create_context() } // Extracts a C string from a V8 Utf8Value. -const char* ToCString(const v8::String::Utf8Value& value) { +inline const char* ToCString(const v8::String::Utf8Value& value) { return *value ? *value : ""; } @@ -307,7 +259,7 @@ void GameContext::_report_exception(v8::TryCatch* try_catch) if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // print the exception. - print_err(exception_string); + Logging::print_err(exception_string); } else { // Print (filename):(line number): (message). @@ -319,13 +271,13 @@ void GameContext::_report_exception(v8::TryCatch* try_catch) { char line[1024]; sprintf(line, "%s:%i: %s", filename_string, linenum, exception_string); - print_err(line); + Logging::print_err(line); } // Print line of source code. v8::String::Utf8Value sourceline( m_vm->m_isolate, message->GetSourceLine(context).ToLocalChecked()); const char* sourceline_string = ToCString(sourceline); - print_err(sourceline_string); + Logging::print_err(sourceline_string); { std::string line = ""; @@ -340,7 +292,7 @@ void GameContext::_report_exception(v8::TryCatch* try_catch) { line += "^"; } - print_err(line.c_str()); + Logging::print_err(line.c_str()); } v8::Local stack_trace_string; if (try_catch->StackTrace(context).ToLocal(&stack_trace_string) && @@ -348,7 +300,7 @@ void GameContext::_report_exception(v8::TryCatch* try_catch) stack_trace_string.As()->Length() > 0) { v8::String::Utf8Value stack_trace(m_vm->m_isolate, stack_trace_string); const char* err = ToCString(stack_trace); - print_err(err); + Logging::print_err(err); } } } @@ -384,7 +336,7 @@ bool GameContext::_execute_string(v8::Local source, v8::Localm_isolate, result); const char* cstr = ToCString(str); - print_std(cstr); + Logging::print_std(cstr); } return true; } @@ -408,31 +360,6 @@ void GameContext::_run_script(const char* filename) _execute_string(source, file_name, false, true); } - -void GameContext::Print(const v8::FunctionCallbackInfo& args) -{ - std::string line = ""; - bool first = true; - for (int i = 0; i < args.Length(); i++) { - v8::HandleScope handle_scope(args.GetIsolate()); - if (first) { - first = false; - } - else - { - line += " "; - } - v8::String::Utf8Value str(args.GetIsolate(), args[i]); - const char* cstr = ToCString(str); - line += cstr; - } - - LocalContext lctx(args); - GameContext* self = lctx.ctx(); - self->print_std(line.c_str()); - -} - void GameContext::SetCallback(const v8::FunctionCallbackInfo& args) { LocalContext lctx(args); @@ -464,100 +391,6 @@ v8::MaybeLocal GameContext::InvokeCallback(v8::Function* callback, co return ret; } -void GameContext::Now(const v8::FunctionCallbackInfo& args) -{ - LocalContext lctx(args); - double now = time_sec() * 1000.0; - args.GetReturnValue().Set(lctx.num_to_jnum(now)); -} - -#include - -void GameContext::GetGLError(const v8::FunctionCallbackInfo& args) -{ - LocalContext lctx(args); - unsigned err = glGetError(); - args.GetReturnValue().Set(lctx.num_to_jnum(err)); -} - -#if THREE_MM -void GameContext::GetListOfCameras(const v8::FunctionCallbackInfo& args) -{ - LocalContext lctx(args); - const std::vector& lst = MMCamera::s_get_list_devices(); - - v8::Local ret = v8::Array::New(lctx.isolate); - for (size_t i = 0; i < lst.size(); i++) - { - v8::Local name = lctx.str_to_jstr(lst[i].c_str()); - ret->Set(lctx.context, (unsigned)i, name); - } - args.GetReturnValue().Set(ret); -} - -void GameContext::GetListOfAudioDevices(const v8::FunctionCallbackInfo& args) -{ - LocalContext lctx(args); - const std::vector& lst = GetNamesAudioDevices(false); - - v8::Local ret = v8::Array::New(lctx.isolate); - for (size_t i = 0; i < lst.size(); i++) - { - v8::Local name = lctx.str_to_jstr(lst[i].c_str()); - ret->Set(lctx.context, (unsigned)i, name); - } - args.GetReturnValue().Set(ret); -} -#endif - -#ifdef _WIN32 -#include -#endif - -void GameContext::GeneralCall(const v8::FunctionCallbackInfo& args) -{ - LocalContext lctx(args); - v8::Local ret; - std::string cmd = lctx.jstr_to_str(args[0]); - -#ifdef _WIN32 - if (cmd == "OpenFile") - { - v8::String::Value filter_name(lctx.isolate, args[1]); - v8::String::Value filter_ext(lctx.isolate, args[2]); - - wchar_t filter[1024]; - wsprintf(filter, L"%s", (wchar_t*)(*filter_name)); - - int pos = lstrlenW(filter); - wsprintf(filter+pos+1, L"%s", (wchar_t*)(*filter_ext)); - - int pos2 = lstrlenW(filter + pos + 1); - filter[pos + 1 + pos2 + 1] = 0; - - - wchar_t buffer[1024]; - OPENFILENAMEW ofn{0}; - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = NULL; - ofn.lpstrFile = buffer; - ofn.lpstrFile[0] = 0; - ofn.nMaxFile = 1024; - ofn.lpstrFilter = filter; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - ::GetOpenFileName(&ofn); - - ret = v8::String::NewFromTwoByte(lctx.isolate, (uint16_t*)buffer).ToLocalChecked(); - } -#endif - - args.GetReturnValue().Set(ret); -} - void GameContext::WeakCallback(v8::WeakCallbackInfo const& data) { void* self = data.GetInternalField(0); @@ -582,35 +415,3 @@ void GameContext::remove_object(void* ptr) m_objects[ptr].first.Reset(); m_objects.erase(ptr); } - -void GameContext::SetPrintCallbacks(void* ptr, PrintCallback print_callback, PrintCallback error_callback) -{ - m_print_callback_data = ptr; - m_print_callback = print_callback; - m_error_callback = error_callback; -} - -void GameContext::print_std(const char* str) -{ - if (m_print_callback != nullptr) - { - m_print_callback(m_print_callback_data, str); - } - else - { - printf("%s\n", str); - } -} - -void GameContext::print_err(const char* str) -{ - if (m_error_callback != nullptr) - { - m_error_callback(m_print_callback_data, str); - } - else - { - fprintf(stderr, "%s\n", str); - } - -} diff --git a/Three.V8/binding.h b/Three.V8/binding.h index 38d11272..16817359 100644 --- a/Three.V8/binding.h +++ b/Three.V8/binding.h @@ -5,10 +5,11 @@ #include #include #include -#include #include #include +#include "definitions.hpp" + class V8VM { public: @@ -22,39 +23,10 @@ class V8VM v8::ArrayBuffer::Allocator* m_array_buffer_allocator; }; -struct FunctionDefinition -{ - std::string name; - v8::FunctionCallback func; -}; - -struct ClassDefinition -{ - std::string name; - v8::FunctionCallback constructor; - v8::Local(*creator)(v8::Isolate* isolate, v8::FunctionCallback constructor); -}; - -struct ObjectDefinition -{ - std::string name; - v8::Local(*creator)(v8::Isolate* isolate); -}; - -struct GlobalDefinitions -{ - std::vector funcs; - std::vector classes; - std::vector objects; -}; - -class GamePlayer; -class HttpClient; -class UIManager; class GameContext { public: - GameContext(V8VM* vm, GamePlayer* gamePlayer, const char* filename); + GameContext(V8VM* vm, const WorldDefinition& world_definition, const char* filename); ~GameContext(); V8VM* m_vm; @@ -62,10 +34,7 @@ class GameContext typedef v8::Persistent> ContextT; ContextT m_context; - GamePlayer* GetGamePlayer() const { return m_gamePlayer; } - HttpClient* GetHttpClient() const { return m_http.get(); } - UIManager* GetUIManager() const { return m_ui_manager.get(); } - + static void SetCallback(const v8::FunctionCallbackInfo& args); v8::Function* GetCallback(const char* name); v8::MaybeLocal InvokeCallback(v8::Function* callback, const std::vector>& args); @@ -73,15 +42,8 @@ class GameContext void regiter_object(v8::Local obj, Dtor dtor); void remove_object(void* ptr); - typedef void (*PrintCallback)(void* ptr, const char* str); - void SetPrintCallbacks(void* ptr, PrintCallback print_callback, PrintCallback error_callback); - private: - GamePlayer* m_gamePlayer; - std::unique_ptr m_http; - std::unique_ptr m_ui_manager; - static GlobalDefinitions s_globals; - void _create_context(); + void _create_context(const WorldDefinition& world_definition); void _report_exception(v8::TryCatch* handler); bool _execute_string(v8::Local source, v8::Local name, bool print_result, bool report_exceptions); @@ -93,24 +55,16 @@ class GameContext typedef v8::Global ObjectT; std::unordered_map> m_objects; - void* m_print_callback_data = nullptr; - PrintCallback m_print_callback = nullptr; - PrintCallback m_error_callback = nullptr; - - void print_std(const char* str); - void print_err(const char* str); - - static void Print(const v8::FunctionCallbackInfo& args); - static void SetCallback(const v8::FunctionCallbackInfo& args); - static void Now(const v8::FunctionCallbackInfo& args); - static void GetGLError(const v8::FunctionCallbackInfo& args); + static void WeakCallback(v8::WeakCallbackInfo const& data); -#if THREE_MM - static void GetListOfCameras(const v8::FunctionCallbackInfo& args); - static void GetListOfAudioDevices(const v8::FunctionCallbackInfo& args); -#endif + struct CtorDtor + { + Constructor ctor; + Destructor dtor; + }; + std::vector m_cls_ctor_dtor; - static void GeneralCall(const v8::FunctionCallbackInfo& args); + static void GeneralNew(const v8::FunctionCallbackInfo& info); + static void GeneralDispose(const v8::FunctionCallbackInfo& info); - static void WeakCallback(v8::WeakCallbackInfo const& data); }; \ No newline at end of file diff --git a/Three.V8/cameras/Camera.hpp b/Three.V8/cameras/Camera.hpp deleted file mode 100644 index 70a3b447..00000000 --- a/Three.V8/cameras/Camera.hpp +++ /dev/null @@ -1,98 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include "core/Object3D.hpp" -#include - -class WrapperCamera -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetMatrixWorldInverse(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetMatrixWorldInverse(const v8::FunctionCallbackInfo& info); - - static void GetProjectionMatrix(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetProjectionMatrix(const v8::FunctionCallbackInfo& info); - - static void GetProjectionMatrixInverse(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetProjectionMatrixInverse(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperCamera::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "matrixWorldInverse").ToLocalChecked(), GetMatrixWorldInverse, 0); - templ->InstanceTemplate()->Set(isolate, "getMatrixWorldInverse", v8::FunctionTemplate::New(isolate, GetMatrixWorldInverse)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "projectionMatrix").ToLocalChecked(), GetProjectionMatrix, 0); - templ->InstanceTemplate()->Set(isolate, "getProjectionMatrix", v8::FunctionTemplate::New(isolate, GetProjectionMatrix)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "projectionMatrixInverse").ToLocalChecked(), GetProjectionMatrixInverse, 0); - templ->InstanceTemplate()->Set(isolate, "getProjectionMatrixInverse", v8::FunctionTemplate::New(isolate, GetProjectionMatrixInverse)); - return templ; -} - -void WrapperCamera::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = new Camera(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); -} - - -void WrapperCamera::GetMatrixWorldInverse(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = lctx.self(); - v8::Local matrix = v8::Object::New(lctx.isolate); - lctx.mat4_to_jmat4(self->matrixWorldInverse, matrix); - info.GetReturnValue().Set(matrix); -} - - -void WrapperCamera::GetMatrixWorldInverse(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = lctx.self(); - lctx.mat4_to_jmat4(self->matrixWorldInverse, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperCamera::GetProjectionMatrix(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = lctx.self(); - v8::Local matrix = v8::Object::New(lctx.isolate); - lctx.mat4_to_jmat4(self->projectionMatrix, matrix); - info.GetReturnValue().Set(matrix); -} - - -void WrapperCamera::GetProjectionMatrix(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = lctx.self(); - lctx.mat4_to_jmat4(self->projectionMatrix, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperCamera::GetProjectionMatrixInverse(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = lctx.self(); - v8::Local matrix = v8::Object::New(lctx.isolate); - lctx.mat4_to_jmat4(self->projectionMatrixInverse, matrix); - info.GetReturnValue().Set(matrix); -} - - -void WrapperCamera::GetProjectionMatrixInverse(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Camera* self = lctx.self(); - lctx.mat4_to_jmat4(self->projectionMatrixInverse, info[0]); - info.GetReturnValue().Set(info[0]); -} diff --git a/Three.V8/cameras/WrapperCamera.cpp b/Three.V8/cameras/WrapperCamera.cpp new file mode 100644 index 00000000..542cbeaa --- /dev/null +++ b/Three.V8/cameras/WrapperCamera.cpp @@ -0,0 +1,87 @@ +#include "WrapperUtils.hpp" +#include "core/WrapperObject3D.h" +#include + +#include "WrapperCamera.h" + +void WrapperCamera::define(ClassDefinition& cls) +{ + WrapperObject3D::define(cls); + cls.name = "Camera"; + cls.ctor = ctor; + + std::vector props = { + { "matrixWorldInverse", GetMatrixWorldInverse }, + { "projectionMatrix", GetProjectionMatrix }, + { "projectionMatrixInverse", GetProjectionMatrixInverse }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getMatrixWorldInverse", GetMatrixWorldInverse }, + {"getProjectionMatrix", GetProjectionMatrix }, + {"getProjectionMatrixInverse", GetProjectionMatrixInverse }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); +} + + +void* WrapperCamera::ctor(const v8::FunctionCallbackInfo& info) +{ + return new Camera; +} + +void WrapperCamera::GetMatrixWorldInverse(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Camera* self = lctx.self(); + v8::Local matrix = v8::Object::New(lctx.isolate); + lctx.mat4_to_jmat4(self->matrixWorldInverse, matrix); + info.GetReturnValue().Set(matrix); +} + + +void WrapperCamera::GetMatrixWorldInverse(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + Camera* self = lctx.self(); + lctx.mat4_to_jmat4(self->matrixWorldInverse, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperCamera::GetProjectionMatrix(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Camera* self = lctx.self(); + v8::Local matrix = v8::Object::New(lctx.isolate); + lctx.mat4_to_jmat4(self->projectionMatrix, matrix); + info.GetReturnValue().Set(matrix); +} + + +void WrapperCamera::GetProjectionMatrix(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + Camera* self = lctx.self(); + lctx.mat4_to_jmat4(self->projectionMatrix, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperCamera::GetProjectionMatrixInverse(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Camera* self = lctx.self(); + v8::Local matrix = v8::Object::New(lctx.isolate); + lctx.mat4_to_jmat4(self->projectionMatrixInverse, matrix); + info.GetReturnValue().Set(matrix); +} + + +void WrapperCamera::GetProjectionMatrixInverse(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + Camera* self = lctx.self(); + lctx.mat4_to_jmat4(self->projectionMatrixInverse, info[0]); + info.GetReturnValue().Set(info[0]); +} + diff --git a/Three.V8/cameras/WrapperCamera.h b/Three.V8/cameras/WrapperCamera.h new file mode 100644 index 00000000..b89d0503 --- /dev/null +++ b/Three.V8/cameras/WrapperCamera.h @@ -0,0 +1,23 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperCamera +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetMatrixWorldInverse(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetMatrixWorldInverse(const v8::FunctionCallbackInfo& info); + + static void GetProjectionMatrix(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetProjectionMatrix(const v8::FunctionCallbackInfo& info); + + static void GetProjectionMatrixInverse(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetProjectionMatrixInverse(const v8::FunctionCallbackInfo& info); + +}; + diff --git a/Three.V8/cameras/PerspectiveCamera.hpp b/Three.V8/cameras/WrapperPerspectiveCamera.cpp similarity index 51% rename from Three.V8/cameras/PerspectiveCamera.hpp rename to Three.V8/cameras/WrapperPerspectiveCamera.cpp index 54e69a3c..97ee599d 100644 --- a/Three.V8/cameras/PerspectiveCamera.hpp +++ b/Three.V8/cameras/WrapperPerspectiveCamera.cpp @@ -1,48 +1,33 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "cameras/Camera.hpp" +#include "WrapperCamera.h" #include -class WrapperPerspectiveCamera -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetIsPerspectiveCamera(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void GetFov(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetFov(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetAspect(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetAspect(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +#include "WrapperPerspectiveCamera.h" - static void GetNear(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetNear(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetFar(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetFar(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +void WrapperPerspectiveCamera::define(ClassDefinition& cls) +{ + WrapperCamera::define(cls); - static void UpdateProjectionMatrix(const v8::FunctionCallbackInfo& info); + cls.name = "PerspectiveCamera"; + cls.ctor = ctor; -}; + std::vector props = { + { "isPerspectiveCamera", GetIsPerspectiveCamera }, + { "fov", GetFov, SetFov }, + { "aspect", GetAspect, SetAspect }, + { "near", GetFar, SetNear }, + { "far", GetFar, SetFar }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + std::vector methods = { + {"updateProjectionMatrix", UpdateProjectionMatrix }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); -v8::Local WrapperPerspectiveCamera::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperCamera::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isPerspectiveCamera").ToLocalChecked(), GetIsPerspectiveCamera, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "fov").ToLocalChecked(), GetFov, SetFov); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "aspect").ToLocalChecked(), GetAspect, SetAspect); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "near").ToLocalChecked(), GetNear, SetNear); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "far").ToLocalChecked(), GetFar, SetFar); - templ->InstanceTemplate()->Set(isolate, "updateProjectionMatrix", v8::FunctionTemplate::New(isolate, UpdateProjectionMatrix)); - return templ; } -void WrapperPerspectiveCamera::New(const v8::FunctionCallbackInfo& info) +void* WrapperPerspectiveCamera::ctor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); @@ -53,7 +38,7 @@ void WrapperPerspectiveCamera::New(const v8::FunctionCallbackInfo& in if (info.Length() > 0) { - lctx.jnum_to_num(info[0], fov); + lctx.jnum_to_num(info[0], fov); if (info.Length() > 1) { lctx.jnum_to_num(info[1], aspect); @@ -67,9 +52,7 @@ void WrapperPerspectiveCamera::New(const v8::FunctionCallbackInfo& in } } } - PerspectiveCamera* self = new PerspectiveCamera(fov, aspect, z_near, z_far); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new PerspectiveCamera(fov, aspect, z_near, z_far); } void WrapperPerspectiveCamera::GetIsPerspectiveCamera(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -82,7 +65,7 @@ void WrapperPerspectiveCamera::GetIsPerspectiveCamera(v8::Local prop void WrapperPerspectiveCamera::GetFov(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - PerspectiveCamera* self = lctx.self(); + PerspectiveCamera* self = lctx.self(); info.GetReturnValue().Set(lctx.num_to_jnum(self->fov)); } @@ -98,7 +81,7 @@ void WrapperPerspectiveCamera::GetAspect(v8::Local property, const v { LocalContext lctx(info); PerspectiveCamera* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->aspect)); + info.GetReturnValue().Set(lctx.num_to_jnum(self->aspect)); } void WrapperPerspectiveCamera::SetAspect(v8::Local property, v8::Local value, @@ -145,3 +128,4 @@ void WrapperPerspectiveCamera::UpdateProjectionMatrix(const v8::FunctionCallback PerspectiveCamera* self = lctx.self(); self->updateProjectionMatrix(); } + diff --git a/Three.V8/cameras/WrapperPerspectiveCamera.h b/Three.V8/cameras/WrapperPerspectiveCamera.h new file mode 100644 index 00000000..694174cd --- /dev/null +++ b/Three.V8/cameras/WrapperPerspectiveCamera.h @@ -0,0 +1,28 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperPerspectiveCamera +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetIsPerspectiveCamera(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void GetFov(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetFov(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetAspect(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetAspect(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetNear(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetNear(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetFar(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetFar(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void UpdateProjectionMatrix(const v8::FunctionCallbackInfo& info); +}; \ No newline at end of file diff --git a/Three.V8/cameras/Reflector.hpp b/Three.V8/cameras/WrapperReflector.cpp similarity index 57% rename from Three.V8/cameras/Reflector.hpp rename to Three.V8/cameras/WrapperReflector.cpp index 2b7e6843..7a8315c8 100644 --- a/Three.V8/cameras/Reflector.hpp +++ b/Three.V8/cameras/WrapperReflector.cpp @@ -1,46 +1,33 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include +#include "WrapperReflector.h" -class WrapperReflector -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetWidth(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetHeight(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetPrimitiveReferences(v8::Local property, const v8::PropertyCallbackInfo& info); - static void AddPrimitiveReference(const v8::FunctionCallbackInfo& info); - static void ClearPrimitiveReferences(const v8::FunctionCallbackInfo& info); - -}; -v8::Local WrapperReflector::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperReflector::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, SetWidth); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, SetHeight); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "prim_refs").ToLocalChecked(), GetPrimitiveReferences, 0); - templ->InstanceTemplate()->Set(isolate, "addPrimitiveReference", v8::FunctionTemplate::New(isolate, AddPrimitiveReference)); - templ->InstanceTemplate()->Set(isolate, "clearPrimitiveReferences", v8::FunctionTemplate::New(isolate, ClearPrimitiveReferences)); - return templ; + WrapperObject3D::define(cls); + cls.name = "Reflector"; + cls.ctor = ctor; + + std::vector props = { + { "width", GetWidth, SetWidth }, + { "height", GetHeight, SetHeight }, + { "prim_refs", GetPrimitiveReferences }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"addPrimitiveReference", AddPrimitiveReference }, + {"clearPrimitiveReferences", ClearPrimitiveReferences }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperReflector::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Reflector* self = new Reflector(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); +void* WrapperReflector::ctor(const v8::FunctionCallbackInfo& info) +{ + return new Reflector; } void WrapperReflector::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -55,7 +42,7 @@ void WrapperReflector::SetWidth(v8::Local property, v8::Local(); - lctx.jnum_to_num(value, self->width); + lctx.jnum_to_num(value, self->width); } @@ -105,7 +92,7 @@ void WrapperReflector::AddPrimitiveReference(const v8::FunctionCallbackInfom_prim_refs.push_back({ object,mesh_id,prim_id }); v8::Local holder = info.Holder(); - v8::Local prim_ref = v8::Object::New(lctx.isolate); + v8::Local prim_ref = v8::Object::New(lctx.isolate); lctx.set_property(prim_ref, "model", info[0]); if (info.Length() > 1) { @@ -114,7 +101,7 @@ void WrapperReflector::AddPrimitiveReference(const v8::FunctionCallbackInfo prim_refs = lctx.get_property(holder, "prim_refs").As(); prim_refs->Set(lctx.context, prim_refs->Length(), prim_ref); } @@ -130,7 +117,7 @@ void WrapperReflector::ClearPrimitiveReferences(const v8::FunctionCallbackInfoLength(); i++) { - v8::Local obj_i = prim_refs->Get(lctx.context, i).ToLocalChecked().As(); + v8::Local obj_i = prim_refs->Get(lctx.context, i).ToLocalChecked().As(); prim_refs->Delete(lctx.context, i); } lctx.set_property(prim_refs, "length", lctx.num_to_jnum(0)); @@ -138,3 +125,5 @@ void WrapperReflector::ClearPrimitiveReferences(const v8::FunctionCallbackInfo& info); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetWidth(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetHeight(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetPrimitiveReferences(v8::Local property, const v8::PropertyCallbackInfo& info); + static void AddPrimitiveReference(const v8::FunctionCallbackInfo& info); + static void ClearPrimitiveReferences(const v8::FunctionCallbackInfo& info); + +}; + diff --git a/Three.V8/core/BoundingVolumeHierarchy.hpp b/Three.V8/core/WrapperBoundingVolumeHierarchy.cpp similarity index 66% rename from Three.V8/core/BoundingVolumeHierarchy.hpp rename to Three.V8/core/WrapperBoundingVolumeHierarchy.cpp index ad2df993..13ea2383 100644 --- a/Three.V8/core/BoundingVolumeHierarchy.hpp +++ b/Three.V8/core/WrapperBoundingVolumeHierarchy.cpp @@ -1,56 +1,25 @@ -#pragma once - #define ENABLE_TEST 0 #include "WrapperUtils.hpp" #include #include +#include "WrapperBoundingVolumeHierarchy.h" -class WrappeBoundingVolumeHierarchy +void WrapperBoundingVolumeHierarchy::define(ClassDefinition& cls) { -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void Update(const v8::FunctionCallbackInfo& info); - static void Remove(const v8::FunctionCallbackInfo& info); - static void Intersect(const v8::FunctionCallbackInfo& info); - static void Collide(const v8::FunctionCallbackInfo& info); - static void SaveFile(const v8::FunctionCallbackInfo& info); - -#if ENABLE_TEST - static void Test(const v8::FunctionCallbackInfo& info); -#endif - -}; - -v8::Local WrappeBoundingVolumeHierarchy::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "update", v8::FunctionTemplate::New(isolate, Update)); - templ->InstanceTemplate()->Set(isolate, "remove", v8::FunctionTemplate::New(isolate, Remove)); - templ->InstanceTemplate()->Set(isolate, "intersect", v8::FunctionTemplate::New(isolate, Intersect)); - templ->InstanceTemplate()->Set(isolate, "collide", v8::FunctionTemplate::New(isolate, Collide)); - templ->InstanceTemplate()->Set(isolate, "saveFile", v8::FunctionTemplate::New(isolate, SaveFile)); - -#if ENABLE_TEST - templ->InstanceTemplate()->Set(isolate, "test", v8::FunctionTemplate::New(isolate, Test)); -#endif - - return templ; -} - - -void WrappeBoundingVolumeHierarchy::dtor(void* ptr, GameContext* ctx) -{ - delete (BoundingVolumeHierarchy*)ptr; + cls.name = "BoundingVolumeHierarchy"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"update", Update }, + {"remove", Remove }, + {"intersect", Intersect }, + {"collide", Collide }, + {"saveFile", SaveFile }, + }; } -void WrappeBoundingVolumeHierarchy::New(const v8::FunctionCallbackInfo& info) +void* WrapperBoundingVolumeHierarchy::ctor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); @@ -68,8 +37,7 @@ void WrappeBoundingVolumeHierarchy::New(const v8::FunctionCallbackInfoSetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + return self; } else if (info[0]->IsString()) { @@ -77,12 +45,16 @@ void WrappeBoundingVolumeHierarchy::New(const v8::FunctionCallbackInfoSetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + return self; } } -void WrappeBoundingVolumeHierarchy::Update(const v8::FunctionCallbackInfo& info) +void WrapperBoundingVolumeHierarchy::dtor(void* ptr, GameContext* ctx) +{ + delete (BoundingVolumeHierarchy*)ptr; +} + +void WrapperBoundingVolumeHierarchy::Update(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); BoundingVolumeHierarchy* self = lctx.self(); @@ -92,7 +64,7 @@ void WrappeBoundingVolumeHierarchy::Update(const v8::FunctionCallbackInfoupdate(obj); } -void WrappeBoundingVolumeHierarchy::Remove(const v8::FunctionCallbackInfo& info) +void WrapperBoundingVolumeHierarchy::Remove(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); BoundingVolumeHierarchy* self = lctx.self(); @@ -102,14 +74,14 @@ void WrappeBoundingVolumeHierarchy::Remove(const v8::FunctionCallbackInforemove(obj); } -void WrappeBoundingVolumeHierarchy::Intersect(const v8::FunctionCallbackInfo& info) +void WrapperBoundingVolumeHierarchy::Intersect(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); BoundingVolumeHierarchy* self = lctx.self(); - + v8::Local ray = info[0].As(); v8::Local jorigin = lctx.get_property(ray, "origin"); - v8::Local jdirection = lctx.get_property(ray, "direction"); + v8::Local jdirection = lctx.get_property(ray, "direction"); glm::vec3 origin, direction; lctx.jvec3_to_vec3(jorigin, origin); lctx.jvec3_to_vec3(jdirection, direction); @@ -132,26 +104,26 @@ void WrappeBoundingVolumeHierarchy::Intersect(const v8::FunctionCallbackInfointersect(bvh_ray); - + if (intersection.has_value()) - { + { v8::Local ret = v8::Object::New(lctx.isolate); v8::Local name = lctx.str_to_jstr(intersection->object->name.c_str()); v8::Local uuid = lctx.str_to_jstr(intersection->object->uuid.c_str()); lctx.set_property(ret, "name", name); lctx.set_property(ret, "uuid", uuid); lctx.set_property(ret, "distance", lctx.num_to_jnum(intersection->distance())); - info.GetReturnValue().Set(ret); + info.GetReturnValue().Set(ret); } else { info.GetReturnValue().SetNull(); } - + } #if ENABLE_TEST -void WrappeBoundingVolumeHierarchy::Test(const v8::FunctionCallbackInfo& info) +void WrapperBoundingVolumeHierarchy::Test(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); BoundingVolumeHierarchy* self = lctx.self(); @@ -168,18 +140,18 @@ void WrappeBoundingVolumeHierarchy::Test(const v8::FunctionCallbackInfoprojectionMatrixInverse * glm::vec4(fx, fy, 0.0f, 1.0f); - view_pos /= view_pos.w; + view_pos /= view_pos.w; glm::vec3 world_pos = camera->localToWorld(view_pos); - glm::vec3 direction = glm::normalize(world_pos - origin); + glm::vec3 direction = glm::normalize(world_pos - origin); bvh::Ray bvh_ray = bvh::Ray( bvh::Vector3(origin.x, origin.y, origin.z), - bvh::Vector3(direction.x, direction.y, direction.z) + bvh::Vector3(direction.x, direction.y, direction.z) ); float d = 1.0f; @@ -206,7 +178,7 @@ void WrappeBoundingVolumeHierarchy::Test(const v8::FunctionCallbackInfo& info) +void WrapperBoundingVolumeHierarchy::Collide(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); BoundingVolumeHierarchy* self = lctx.self(); @@ -219,7 +191,7 @@ void WrappeBoundingVolumeHierarchy::Collide(const v8::FunctionCallbackInfo sphere = { bvh::Vector3(origin.x, origin.y, origin.z), radius @@ -247,7 +219,7 @@ void WrappeBoundingVolumeHierarchy::Collide(const v8::FunctionCallbackInfo& info) +void WrapperBoundingVolumeHierarchy::SaveFile(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); BoundingVolumeHierarchy* self = lctx.self(); diff --git a/Three.V8/core/WrapperBoundingVolumeHierarchy.h b/Three.V8/core/WrapperBoundingVolumeHierarchy.h new file mode 100644 index 00000000..3b6bd653 --- /dev/null +++ b/Three.V8/core/WrapperBoundingVolumeHierarchy.h @@ -0,0 +1,27 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperBoundingVolumeHierarchy +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void Update(const v8::FunctionCallbackInfo& info); + static void Remove(const v8::FunctionCallbackInfo& info); + static void Intersect(const v8::FunctionCallbackInfo& info); + static void Collide(const v8::FunctionCallbackInfo& info); + static void SaveFile(const v8::FunctionCallbackInfo& info); + +#if ENABLE_TEST + static void Test(const v8::FunctionCallbackInfo& info); +#endif + +}; + diff --git a/Three.V8/core/Object3D.hpp b/Three.V8/core/WrapperObject3D.cpp similarity index 61% rename from Three.V8/core/Object3D.hpp rename to Three.V8/core/WrapperObject3D.cpp index 4bce2fdc..7a821088 100644 --- a/Three.V8/core/Object3D.hpp +++ b/Three.V8/core/WrapperObject3D.cpp @@ -1,201 +1,99 @@ -#pragma once - #include "WrapperUtils.hpp" #include -class WrapperObject3D -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetName(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetName(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetUuid(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetUuid(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetIsBuilding(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetIsBuilding(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetMoved(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetMoved(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetParent(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetParent(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetChildren(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void GetUp(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetUp(const v8::FunctionCallbackInfo& info); - static void SetUp(const v8::FunctionCallbackInfo& info); - - static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetPosition(const v8::FunctionCallbackInfo& info); - static void SetPosition(const v8::FunctionCallbackInfo& info); - - static void GetRotation(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetRotation(const v8::FunctionCallbackInfo& info); - static void SetRotation(const v8::FunctionCallbackInfo& info); - - static void GetQuaternion(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetQuaternion(const v8::FunctionCallbackInfo& info); - static void SetQuaternion(const v8::FunctionCallbackInfo& info); - - static void GetScale(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetScale(const v8::FunctionCallbackInfo& info); - static void SetScale(const v8::FunctionCallbackInfo& info); - - static void GetMatrix(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetMatrix(const v8::FunctionCallbackInfo& info); - - static void GetMatrixWorld(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetMatrixWorld(const v8::FunctionCallbackInfo& info); - - static void UpdateMatrix(const v8::FunctionCallbackInfo& info); - static void UpdateMatrixWorld(const v8::FunctionCallbackInfo& info); - static void UpdateWorldMatrix(const v8::FunctionCallbackInfo& info); - - static void ApplyMatrix4(const v8::FunctionCallbackInfo& info); - static void ApplyQuaternion(const v8::FunctionCallbackInfo& info); - static void SetRotationFromAxisAngle(const v8::FunctionCallbackInfo& info); - static void SetRotationFromMatrix(const v8::FunctionCallbackInfo& info); - static void RotateOnAxis(const v8::FunctionCallbackInfo& info); - static void RotateOnWorldAxis(const v8::FunctionCallbackInfo& info); - static void RotateX(const v8::FunctionCallbackInfo& info); - static void RotateY(const v8::FunctionCallbackInfo& info); - static void RotateZ(const v8::FunctionCallbackInfo& info); - static void TranslateOnAxis(const v8::FunctionCallbackInfo& info); - static void TranslateX(const v8::FunctionCallbackInfo& info); - static void TranslateY(const v8::FunctionCallbackInfo& info); - static void TranslateZ(const v8::FunctionCallbackInfo& info); - static void LocalToWorld(const v8::FunctionCallbackInfo& info); - static void WorldToLocal(const v8::FunctionCallbackInfo& info); - static void GetWorldPosition(const v8::FunctionCallbackInfo& info); - static void GetWorldQuaternion(const v8::FunctionCallbackInfo& info); - static void GetWorldScale(const v8::FunctionCallbackInfo& info); - static void GetWorldDirection(const v8::FunctionCallbackInfo& info); - - static void LookAt(const v8::FunctionCallbackInfo& info); - - static void Add(const v8::FunctionCallbackInfo& info); - static void Remove(const v8::FunctionCallbackInfo& info); - static void RemoveFromParent(const v8::FunctionCallbackInfo& info); - static void Clear(const v8::FunctionCallbackInfo& info); - - static void GetObjectByName(const v8::FunctionCallbackInfo& info); - static void Traverse(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperObject3D::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "name").ToLocalChecked(), GetName, SetName); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "uuid").ToLocalChecked(), GetUuid, SetUuid); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isBuilding").ToLocalChecked(), GetIsBuilding, SetIsBuilding); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "moved").ToLocalChecked(), GetMoved, SetMoved); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "parent").ToLocalChecked(), GetParent, SetParent); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "children").ToLocalChecked(), GetChildren, 0); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "up").ToLocalChecked(), GetUp, 0); - templ->InstanceTemplate()->Set(isolate, "getUp", v8::FunctionTemplate::New(isolate, GetUp)); - templ->InstanceTemplate()->Set(isolate, "setUp", v8::FunctionTemplate::New(isolate, SetUp)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "position").ToLocalChecked(), GetPosition, 0); - templ->InstanceTemplate()->Set(isolate, "getPosition", v8::FunctionTemplate::New(isolate, GetPosition)); - templ->InstanceTemplate()->Set(isolate, "setPosition", v8::FunctionTemplate::New(isolate, SetPosition)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "rotation").ToLocalChecked(), GetRotation, 0); - templ->InstanceTemplate()->Set(isolate, "getRotation", v8::FunctionTemplate::New(isolate, GetRotation)); - templ->InstanceTemplate()->Set(isolate, "setRotation", v8::FunctionTemplate::New(isolate, SetRotation)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "quaternion").ToLocalChecked(), GetQuaternion, 0); - templ->InstanceTemplate()->Set(isolate, "getQuaternion", v8::FunctionTemplate::New(isolate, GetQuaternion)); - templ->InstanceTemplate()->Set(isolate, "setQuaternion", v8::FunctionTemplate::New(isolate, SetQuaternion)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scale").ToLocalChecked(), GetScale, 0); - templ->InstanceTemplate()->Set(isolate, "getScale", v8::FunctionTemplate::New(isolate, GetScale)); - templ->InstanceTemplate()->Set(isolate, "setScale", v8::FunctionTemplate::New(isolate, SetScale)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "matrix").ToLocalChecked(), GetMatrix, 0); - templ->InstanceTemplate()->Set(isolate, "getMatrix", v8::FunctionTemplate::New(isolate, GetMatrix)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "matrixWorld").ToLocalChecked(), GetMatrixWorld, 0); - templ->InstanceTemplate()->Set(isolate, "getMatrixWorld", v8::FunctionTemplate::New(isolate, GetMatrixWorld)); - - templ->InstanceTemplate()->Set(isolate, "updateMatrix", v8::FunctionTemplate::New(isolate, UpdateMatrix)); - templ->InstanceTemplate()->Set(isolate, "updateMatrixWorld", v8::FunctionTemplate::New(isolate, UpdateMatrixWorld)); - templ->InstanceTemplate()->Set(isolate, "updateWorldMatrix", v8::FunctionTemplate::New(isolate, UpdateWorldMatrix)); - - templ->InstanceTemplate()->Set(isolate, "applyMatrix4", v8::FunctionTemplate::New(isolate, ApplyMatrix4)); - templ->InstanceTemplate()->Set(isolate, "applyQuaternion", v8::FunctionTemplate::New(isolate, ApplyQuaternion)); - templ->InstanceTemplate()->Set(isolate, "setRotationFromAxisAngle", v8::FunctionTemplate::New(isolate, SetRotationFromAxisAngle)); - templ->InstanceTemplate()->Set(isolate, "setRotationFromMatrix", v8::FunctionTemplate::New(isolate, SetRotationFromMatrix)); - templ->InstanceTemplate()->Set(isolate, "rotateOnAxis", v8::FunctionTemplate::New(isolate, RotateOnAxis)); - templ->InstanceTemplate()->Set(isolate, "rotateOnWorldAxis", v8::FunctionTemplate::New(isolate, RotateOnWorldAxis)); - templ->InstanceTemplate()->Set(isolate, "rotateX", v8::FunctionTemplate::New(isolate, RotateX)); - templ->InstanceTemplate()->Set(isolate, "rotateY", v8::FunctionTemplate::New(isolate, RotateY)); - templ->InstanceTemplate()->Set(isolate, "rotateZ", v8::FunctionTemplate::New(isolate, RotateZ)); - templ->InstanceTemplate()->Set(isolate, "translateOnAxis", v8::FunctionTemplate::New(isolate, TranslateOnAxis)); - templ->InstanceTemplate()->Set(isolate, "translateX", v8::FunctionTemplate::New(isolate, TranslateX)); - templ->InstanceTemplate()->Set(isolate, "translateY", v8::FunctionTemplate::New(isolate, TranslateY)); - templ->InstanceTemplate()->Set(isolate, "translateZ", v8::FunctionTemplate::New(isolate, TranslateZ)); - templ->InstanceTemplate()->Set(isolate, "localToWorld", v8::FunctionTemplate::New(isolate, LocalToWorld)); - templ->InstanceTemplate()->Set(isolate, "worldToLocal", v8::FunctionTemplate::New(isolate, WorldToLocal)); - templ->InstanceTemplate()->Set(isolate, "getWorldPosition", v8::FunctionTemplate::New(isolate, GetWorldPosition)); - templ->InstanceTemplate()->Set(isolate, "getWorldQuaternion", v8::FunctionTemplate::New(isolate, GetWorldQuaternion)); - templ->InstanceTemplate()->Set(isolate, "getWorldScale", v8::FunctionTemplate::New(isolate, GetWorldScale)); - templ->InstanceTemplate()->Set(isolate, "getWorldDirection", v8::FunctionTemplate::New(isolate, GetWorldDirection)); - - templ->InstanceTemplate()->Set(isolate, "lookAt", v8::FunctionTemplate::New(isolate, LookAt)); - - templ->InstanceTemplate()->Set(isolate, "add", v8::FunctionTemplate::New(isolate, Add)); - templ->InstanceTemplate()->Set(isolate, "remove", v8::FunctionTemplate::New(isolate, Remove)); - templ->InstanceTemplate()->Set(isolate, "removeFromParent", v8::FunctionTemplate::New(isolate, RemoveFromParent)); - templ->InstanceTemplate()->Set(isolate, "clear", v8::FunctionTemplate::New(isolate, Clear)); - - templ->InstanceTemplate()->Set(isolate, "getObjectByName", v8::FunctionTemplate::New(isolate, GetObjectByName)); - templ->InstanceTemplate()->Set(isolate, "traverse", v8::FunctionTemplate::New(isolate, Traverse)); - - return templ; +#include "WrapperObject3D.h" + +void WrapperObject3D::define(ClassDefinition& cls) +{ + cls.name = "Object3D"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "name", GetName, SetName}, + { "uuid", GetUuid, SetUuid}, + { "isBuilding", GetIsBuilding, SetIsBuilding}, + { "moved", GetMoved, SetMoved}, + { "parent", GetParent, SetParent}, + { "children", GetChildren }, + { "up", GetUp }, + { "position", GetPosition }, + { "rotation", GetRotation }, + { "quaternion", GetQuaternion }, + { "scale", GetScale }, + { "matrix", GetMatrix }, + { "matrixWorld", GetMatrixWorld } + }; + cls.methods = { + {"getUp", GetUp }, + {"setUp", SetUp }, + {"getPosition", GetPosition }, + {"setPosition", SetPosition }, + {"getRotation", GetRotation }, + {"setRotation", SetRotation }, + {"getQuaternion", GetQuaternion }, + {"setQuaternion", SetQuaternion }, + {"getScale", GetScale }, + {"setScale", SetScale }, + {"getMatrix", GetMatrix }, + {"getMatrixWorld", GetMatrixWorld }, + {"updateMatrix", UpdateMatrix }, + {"updateMatrixWorld", UpdateMatrixWorld }, + {"updateWorldMatrix", UpdateWorldMatrix }, + {"applyMatrix4", ApplyMatrix4 }, + {"applyQuaternion", ApplyQuaternion }, + {"setRotationFromAxisAngle", SetRotationFromAxisAngle }, + {"setRotationFromMatrix", SetRotationFromMatrix }, + {"rotateOnAxis", RotateOnAxis }, + {"rotateOnWorldAxis", RotateOnWorldAxis }, + {"rotateX", RotateX }, + {"rotateY", RotateY }, + {"rotateZ", RotateZ }, + {"translateOnAxis", TranslateOnAxis }, + {"translateX", TranslateX }, + {"translateY", TranslateY }, + {"translateZ", TranslateZ }, + {"localToWorld", LocalToWorld }, + {"worldToLocal", WorldToLocal }, + {"getWorldPosition", GetWorldPosition }, + {"getWorldQuaternion", GetWorldQuaternion }, + {"getWorldScale", GetWorldScale }, + {"getWorldDirection", GetWorldDirection }, + {"lookAt", LookAt }, + {"add", Add }, + {"remove", Remove }, + {"removeFromParent", RemoveFromParent }, + {"clear", Clear }, + {"getObjectByName", GetObjectByName }, + {"traverse", Traverse }, + }; + +} + +void* WrapperObject3D::ctor(const v8::FunctionCallbackInfo& info) +{ + return new Object3D(); } - void WrapperObject3D::dtor(void* ptr, GameContext* ctx) -{ +{ delete (Object3D*)ptr; } -void WrapperObject3D::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Object3D* self = new Object3D(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - void WrapperObject3D::GetName(v8::Local property, const v8::PropertyCallbackInfo& info) { - LocalContext lctx(info); + LocalContext lctx(info); Object3D* self = lctx.self(); info.GetReturnValue().Set(lctx.str_to_jstr(self->name.c_str())); } void WrapperObject3D::SetName(v8::Local property, v8::Local value, - const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); + const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); Object3D* self = lctx.self(); self->name = lctx.jstr_to_str(value); } - void WrapperObject3D::GetUuid(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); @@ -285,7 +183,7 @@ void WrapperObject3D::GetUp(v8::Local property, const v8::PropertyCa void WrapperObject3D::GetUp(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); lctx.vec3_to_jvec3(self->up, info[0]); info.GetReturnValue().Set(info[0]); } @@ -343,7 +241,7 @@ void WrapperObject3D::SetPosition(const v8::FunctionCallbackInfo& inf void WrapperObject3D::GetRotation(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); v8::Local rotation = v8::Object::New(lctx.isolate); lctx.vec3_to_jvec3(self->rotation, rotation); info.GetReturnValue().Set(rotation); @@ -397,9 +295,9 @@ void WrapperObject3D::SetQuaternion(const v8::FunctionCallbackInfo& i { LocalContext lctx(info); Object3D* self = lctx.self(); - glm::quat quaternion; + glm::quat quaternion; if (info[0]->IsNumber()) - { + { lctx.jnum_to_num(info[0], quaternion.x); lctx.jnum_to_num(info[1], quaternion.y); lctx.jnum_to_num(info[2], quaternion.z); @@ -434,7 +332,7 @@ void WrapperObject3D::GetScale(const v8::FunctionCallbackInfo& info) void WrapperObject3D::SetScale(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); if (info[0]->IsNumber()) { lctx.jnum_to_num(info[0], self->scale.x); @@ -478,7 +376,7 @@ void WrapperObject3D::GetMatrixWorld(v8::Local property, const v8::P void WrapperObject3D::GetMatrixWorld(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); lctx.mat4_to_jmat4(self->matrixWorld, info[0]); info.GetReturnValue().Set(info[0]); } @@ -513,7 +411,7 @@ void WrapperObject3D::UpdateWorldMatrix(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::mat4 matrix; lctx.jmat4_to_mat4(info[0], matrix); self->applyMatrix4(matrix); @@ -523,7 +421,7 @@ void WrapperObject3D::ApplyMatrix4(const v8::FunctionCallbackInfo& in void WrapperObject3D::ApplyQuaternion(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::quat quaternion; lctx.jquat_to_quat(info[0], quaternion); self->applyQuaternion(quaternion); @@ -533,11 +431,11 @@ void WrapperObject3D::ApplyQuaternion(const v8::FunctionCallbackInfo& void WrapperObject3D::SetRotationFromAxisAngle(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::vec3 axis; lctx.jvec3_to_vec3(info[0], axis); float angle; - lctx.jnum_to_num(info[1], angle); + lctx.jnum_to_num(info[1], angle); self->setRotationFromAxisAngle(axis, angle); info.GetReturnValue().Set(info.Holder()); } @@ -546,7 +444,7 @@ void WrapperObject3D::SetRotationFromAxisAngle(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::mat4 matrix; lctx.jmat4_to_mat4(info[0], matrix); self->setRotationFromMatrix(matrix); @@ -556,7 +454,7 @@ void WrapperObject3D::SetRotationFromMatrix(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::vec3 axis; lctx.jvec3_to_vec3(info[0], axis); float angle; @@ -568,7 +466,7 @@ void WrapperObject3D::RotateOnAxis(const v8::FunctionCallbackInfo& in void WrapperObject3D::RotateOnWorldAxis(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::vec3 axis; lctx.jvec3_to_vec3(info[0], axis); float angle; @@ -685,7 +583,7 @@ void WrapperObject3D::GetWorldPosition(const v8::FunctionCallbackInfo void WrapperObject3D::GetWorldQuaternion(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Object3D* self = lctx.self(); + Object3D* self = lctx.self(); glm::quat quaternion = self->getWorldQuaternion(); lctx.quat_to_jquat(quaternion, info[0]); info.GetReturnValue().Set(info[0]); @@ -760,7 +658,7 @@ void WrapperObject3D::Remove(const v8::FunctionCallbackInfo& info) self->remove(object); v8::Local holder = info.Holder(); - v8::Local holder_object = info[0].As(); + v8::Local holder_object = info[0].As(); v8::Local children = lctx.get_property(holder, "children").As(); @@ -772,9 +670,9 @@ void WrapperObject3D::Remove(const v8::FunctionCallbackInfo& info) lctx.del_property(holder_object, "_parent"); for (unsigned j = i; j < children->Length() - 1; j++) { - children->Set(lctx.context, j, children->Get(lctx.context, j+1).ToLocalChecked()); - } - children->Delete(lctx.context, children->Length()-1); + children->Set(lctx.context, j, children->Get(lctx.context, j + 1).ToLocalChecked()); + } + children->Delete(lctx.context, children->Length() - 1); lctx.set_property(children, "length", lctx.num_to_jnum(children->Length() - 1)); break; } @@ -865,7 +763,7 @@ void WrapperObject3D::GetObjectByName(const v8::FunctionCallbackInfo& void WrapperObject3D::Traverse(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - v8::Local holder = info.Holder(); + v8::Local holder = info.Holder(); v8::Local callback = info[0].As(); v8::Local args[1]; diff --git a/Three.V8/core/WrapperObject3D.h b/Three.V8/core/WrapperObject3D.h new file mode 100644 index 00000000..b2808718 --- /dev/null +++ b/Three.V8/core/WrapperObject3D.h @@ -0,0 +1,93 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperObject3D +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetName(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetName(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetUuid(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetUuid(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetIsBuilding(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetIsBuilding(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetMoved(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetMoved(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetParent(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetParent(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void GetChildren(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void GetUp(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetUp(const v8::FunctionCallbackInfo& info); + static void SetUp(const v8::FunctionCallbackInfo& info); + + static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetPosition(const v8::FunctionCallbackInfo& info); + static void SetPosition(const v8::FunctionCallbackInfo& info); + + static void GetRotation(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetRotation(const v8::FunctionCallbackInfo& info); + static void SetRotation(const v8::FunctionCallbackInfo& info); + + static void GetQuaternion(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetQuaternion(const v8::FunctionCallbackInfo& info); + static void SetQuaternion(const v8::FunctionCallbackInfo& info); + + static void GetScale(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetScale(const v8::FunctionCallbackInfo& info); + static void SetScale(const v8::FunctionCallbackInfo& info); + + static void GetMatrix(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetMatrix(const v8::FunctionCallbackInfo& info); + + static void GetMatrixWorld(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetMatrixWorld(const v8::FunctionCallbackInfo& info); + + static void UpdateMatrix(const v8::FunctionCallbackInfo& info); + static void UpdateMatrixWorld(const v8::FunctionCallbackInfo& info); + static void UpdateWorldMatrix(const v8::FunctionCallbackInfo& info); + + static void ApplyMatrix4(const v8::FunctionCallbackInfo& info); + static void ApplyQuaternion(const v8::FunctionCallbackInfo& info); + static void SetRotationFromAxisAngle(const v8::FunctionCallbackInfo& info); + static void SetRotationFromMatrix(const v8::FunctionCallbackInfo& info); + static void RotateOnAxis(const v8::FunctionCallbackInfo& info); + static void RotateOnWorldAxis(const v8::FunctionCallbackInfo& info); + static void RotateX(const v8::FunctionCallbackInfo& info); + static void RotateY(const v8::FunctionCallbackInfo& info); + static void RotateZ(const v8::FunctionCallbackInfo& info); + static void TranslateOnAxis(const v8::FunctionCallbackInfo& info); + static void TranslateX(const v8::FunctionCallbackInfo& info); + static void TranslateY(const v8::FunctionCallbackInfo& info); + static void TranslateZ(const v8::FunctionCallbackInfo& info); + static void LocalToWorld(const v8::FunctionCallbackInfo& info); + static void WorldToLocal(const v8::FunctionCallbackInfo& info); + static void GetWorldPosition(const v8::FunctionCallbackInfo& info); + static void GetWorldQuaternion(const v8::FunctionCallbackInfo& info); + static void GetWorldScale(const v8::FunctionCallbackInfo& info); + static void GetWorldDirection(const v8::FunctionCallbackInfo& info); + + static void LookAt(const v8::FunctionCallbackInfo& info); + + static void Add(const v8::FunctionCallbackInfo& info); + static void Remove(const v8::FunctionCallbackInfo& info); + static void RemoveFromParent(const v8::FunctionCallbackInfo& info); + static void Clear(const v8::FunctionCallbackInfo& info); + + static void GetObjectByName(const v8::FunctionCallbackInfo& info); + static void Traverse(const v8::FunctionCallbackInfo& info); + +}; + diff --git a/Three.V8/definitions.hpp b/Three.V8/definitions.hpp new file mode 100644 index 00000000..c4304c03 --- /dev/null +++ b/Three.V8/definitions.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include +#include +#include + +class GameContext; + +struct FunctionDefinition +{ + std::string name; + v8::FunctionCallback func; +}; + +struct AccessorDefinition +{ + std::string name; + v8::AccessorGetterCallback get = nullptr; + v8::AccessorSetterCallback set = nullptr; +}; + +typedef void* (*Constructor)(const v8::FunctionCallbackInfo& info); +typedef void* (*ObjConstructor)(); +typedef void (*Destructor)(void* ptr, GameContext* ctx); + + +struct ObjectDefinition +{ + std::string name; + ObjConstructor ctor = nullptr; + Destructor dtor = nullptr; + std::vector methods; + std::vector properties; +}; + +struct ClassDefinition +{ + std::string name; + Constructor ctor; + Destructor dtor; + std::vector methods; + std::vector properties; +}; + +typedef void (*ObjectDefiner)(ObjectDefinition&); +typedef void (*ClassDefiner)(ClassDefinition&); + +struct ModuleDefinition +{ + std::string name; + std::vector functions; + std::vector objects; + std::vector classes; +}; + +struct WorldDefinition +{ + ModuleDefinition default_module; + std::vector modules; +}; + + diff --git a/Three.V8/gui/UIBlock.hpp b/Three.V8/gui/UIBlock.hpp deleted file mode 100644 index 3eb19d4a..00000000 --- a/Three.V8/gui/UIBlock.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include "UIElement.hpp" -#include - - -class WrapperUIBlock -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSize(const v8::FunctionCallbackInfo& info); - static void SetSize(const v8::FunctionCallbackInfo& info); - - static void GetScissorEnabled(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetScissorEnabled(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperUIBlock::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperUIElement::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "size").ToLocalChecked(), GetSize, 0); - templ->InstanceTemplate()->Set(isolate, "getSize", v8::FunctionTemplate::New(isolate, GetSize)); - templ->InstanceTemplate()->Set(isolate, "setSize", v8::FunctionTemplate::New(isolate, SetSize)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scissorEnabled").ToLocalChecked(), GetScissorEnabled, SetScissorEnabled); - return templ; -} - -void WrapperUIBlock::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIBlock* self = new UIBlock(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperUIElement::dtor); -} - -void WrapperUIBlock::GetSize(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - UIBlock* self = lctx.self(); - v8::Local size = v8::Object::New(lctx.isolate); - lctx.vec2_to_jvec2(self->size, size); - info.GetReturnValue().Set(size); -} - - -void WrapperUIBlock::GetSize(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIBlock* self = lctx.self(); - lctx.vec2_to_jvec2(self->size, info[0]); - info.GetReturnValue().Set(info[0]); -} - - -void WrapperUIBlock::SetSize(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIBlock* self = lctx.self(); - glm::vec2 size; - if (info[0]->IsNumber()) - { - lctx.jnum_to_num(info[0], size.x); - lctx.jnum_to_num(info[1], size.y); - } - else - { - lctx.jvec2_to_vec2(info[0], size); - } - if (self->size != size) - { - self->size = size; - self->appearance_changed = true; - } -} - - -void WrapperUIBlock::GetScissorEnabled(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - UIBlock* self = lctx.self(); - v8::Local ret = v8::Boolean::New(lctx.isolate, self->scissor_enabled); - info.GetReturnValue().Set(ret); -} - -void WrapperUIBlock::SetScissorEnabled(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - UIBlock* self = lctx.self(); - self->scissor_enabled = value.As()->Value(); -} diff --git a/Three.V8/gui/UIPanel.hpp b/Three.V8/gui/UIPanel.hpp deleted file mode 100644 index 5dfb1105..00000000 --- a/Three.V8/gui/UIPanel.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include "UIBlock.hpp" -#include - - -class WrapperUIPanel -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void SetStyle(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperUIPanel::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperUIBlock::create_template(isolate, constructor); - templ->InstanceTemplate()->Set(isolate, "setStyle", v8::FunctionTemplate::New(isolate, SetStyle)); - return templ; -} - -void WrapperUIPanel::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIPanel* self = new UIPanel(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperUIElement::dtor); -} - -void WrapperUIPanel::SetStyle(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIPanel* self = lctx.self(); - - v8::Local style = info[0].As(); - - if (lctx.has_property(style, "cornerRadius")) - { - lctx.jnum_to_num(lctx.get_property(style, "cornerRadius"), self->cornerRadius); - } - - if (lctx.has_property(style, "strokeWidth")) - { - lctx.jnum_to_num(lctx.get_property(style, "strokeWidth"), self->strokeWidth); - } - - if (lctx.has_property(style, "colorBg")) - { - std::string str = lctx.jstr_to_str(lctx.get_property(style, "colorBg")); - string_to_color(str.c_str(), self->colorBg); - } - - if (lctx.has_property(style, "colorStroke")) - { - std::string str = lctx.jstr_to_str(lctx.get_property(style, "colorStroke")); - string_to_color(str.c_str(), self->colorStroke); - } - self->appearance_changed = true; -} - diff --git a/Three.V8/gui/UI3DViewer.hpp b/Three.V8/gui/WrapperUI3DViewer.cpp similarity index 72% rename from Three.V8/gui/UI3DViewer.hpp rename to Three.V8/gui/WrapperUI3DViewer.cpp index b49e2e75..1d347217 100644 --- a/Three.V8/gui/UI3DViewer.hpp +++ b/Three.V8/gui/WrapperUI3DViewer.cpp @@ -1,84 +1,34 @@ -#pragma once - #include "WrapperUtils.hpp" #include -class WrapperUI3DViewer -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetBlock(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetBlock(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetOrigin(const v8::FunctionCallbackInfo& info); - static void SetOrigin(const v8::FunctionCallbackInfo& info); - - static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSize(const v8::FunctionCallbackInfo& info); - static void SetSize(const v8::FunctionCallbackInfo& info); - - static void GetOnRender(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnRender(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnMouseDown(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnMouseDown(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnMouseUp(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnMouseUp(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnMouseMove(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnMouseMove(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnMouseWheel(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnMouseWheel(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnTouchDown(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnTouchDown(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnTouchUp(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnTouchUp(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnTouchMove(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnTouchMove(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; - -v8::Local WrapperUI3DViewer::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "block").ToLocalChecked(), GetBlock, SetBlock); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "origin").ToLocalChecked(), GetOrigin, 0); - templ->InstanceTemplate()->Set(isolate, "getOrigin", v8::FunctionTemplate::New(isolate, GetOrigin)); - templ->InstanceTemplate()->Set(isolate, "setOrigin", v8::FunctionTemplate::New(isolate, SetOrigin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "size").ToLocalChecked(), GetSize, 0); - templ->InstanceTemplate()->Set(isolate, "getSize", v8::FunctionTemplate::New(isolate, GetSize)); - templ->InstanceTemplate()->Set(isolate, "setSize", v8::FunctionTemplate::New(isolate, SetSize)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onRender").ToLocalChecked(), GetOnRender, SetOnRender); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onMouseDown").ToLocalChecked(), GetOnMouseDown, SetOnMouseDown); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onMouseUp").ToLocalChecked(), GetOnMouseUp, SetOnMouseUp); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onMouseMove").ToLocalChecked(), GetOnMouseMove, SetOnMouseMove); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onMouseWheel").ToLocalChecked(), GetOnMouseWheel, SetOnMouseWheel); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onTouchDown").ToLocalChecked(), GetOnTouchDown, SetOnTouchDown); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onTouchUp").ToLocalChecked(), GetOnTouchUp, SetOnTouchUp); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onTouchMove").ToLocalChecked(), GetOnTouchMove, SetOnTouchMove); - - return templ; - +#include "WrapperUI3DViewer.h" + +void WrapperUI3DViewer::define(ClassDefinition& cls) +{ + cls.name = "UI3DViewer"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "block", GetBlock, SetBlock }, + { "origin", GetOrigin }, + { "size", GetSize }, + { "onRender", GetOnRender, SetOnRender }, + { "onMouseDown", GetOnMouseDown, SetOnMouseDown }, + { "onMouseUp", GetOnMouseUp, SetOnMouseUp }, + { "onMouseMove", GetOnMouseMove, SetOnMouseMove }, + { "onMouseWheel", GetOnMouseWheel, SetOnMouseWheel }, + { "onTouchDown", GetOnTouchDown, SetOnTouchDown }, + { "onTouchUp", GetOnTouchUp, SetOnTouchUp }, + { "onTouchMove", GetOnTouchMove, SetOnTouchMove }, + }; + cls.methods = { + {"getOrigin", GetOrigin }, + {"setOrigin", SetOrigin }, + {"getSize", GetSize }, + {"setSize", SetSize }, + }; } - typedef v8::Persistent> CallbackT; struct UI3DViewerCallbackData @@ -87,6 +37,10 @@ struct UI3DViewerCallbackData CallbackT callback; }; +void* WrapperUI3DViewer::ctor(const v8::FunctionCallbackInfo& info) +{ + return new UI3DViewer; +} void WrapperUI3DViewer::dtor(void* ptr, GameContext* ctx) { @@ -143,15 +97,6 @@ void WrapperUI3DViewer::dtor(void* ptr, GameContext* ctx) delete self; } -void WrapperUI3DViewer::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UI3DViewer* self = new UI3DViewer(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - void WrapperUI3DViewer::GetBlock(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); @@ -205,7 +150,7 @@ void WrapperUI3DViewer::SetOrigin(const v8::FunctionCallbackInfo& inf if (self->origin != origin) { - self->origin = origin; + self->origin = origin; } } @@ -244,25 +189,25 @@ void WrapperUI3DViewer::SetSize(const v8::FunctionCallbackInfo& info) } if (self->size != size) { - self->size = size; + self->size = size; } } static void UI3DViewerRenderCallback(int width, int height, bool size_changed, void* ptr) { UI3DViewerCallbackData* data = (UI3DViewerCallbackData*)ptr; - GameContext* ctx = data->ctx; + GameContext* ctx = data->ctx; v8::Isolate* isolate = ctx->m_vm->m_isolate; v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); std::vector> args(3); args[0] = v8::Number::New(isolate, (double)width); args[1] = v8::Number::New(isolate, (double)height); args[2] = v8::Boolean::New(isolate, size_changed); ctx->InvokeCallback(*callback, args); - + } void WrapperUI3DViewer::GetOnRender(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -316,7 +261,7 @@ static void UI3DViewerMouseCallback(int button, int clicks, int delta, int x, in v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); std::vector> args(1); args[0] = g_CreateMouseEvent(isolate, context, button, clicks, delta, x, y); ctx->InvokeCallback(*callback, args); @@ -463,7 +408,7 @@ static void UI3DViewerTouchCallback(int pointerId, float x, float y, void* ptr) v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); std::vector> args(1); args[0] = g_CreateTouchEvent(isolate, context, pointerId, x, y); ctx->InvokeCallback(*callback, args); @@ -534,7 +479,7 @@ void WrapperUI3DViewer::SetOnTouchUp(v8::Local property, v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - v8::Local onTouchMove = lctx.get_property(lctx.holder, "_onTouchMove"); + v8::Local onTouchMove = lctx.get_property(lctx.holder, "_onTouchMove"); info.GetReturnValue().Set(onTouchMove); } @@ -560,4 +505,4 @@ void WrapperUI3DViewer::SetOnTouchMove(v8::Local property, v8::Local self->touch_move_data = data; -} \ No newline at end of file +} diff --git a/Three.V8/gui/WrapperUI3DViewer.h b/Three.V8/gui/WrapperUI3DViewer.h new file mode 100644 index 00000000..003398bc --- /dev/null +++ b/Three.V8/gui/WrapperUI3DViewer.h @@ -0,0 +1,53 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUI3DViewer +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetBlock(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetBlock(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetOrigin(const v8::FunctionCallbackInfo& info); + static void SetOrigin(const v8::FunctionCallbackInfo& info); + + static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSize(const v8::FunctionCallbackInfo& info); + static void SetSize(const v8::FunctionCallbackInfo& info); + + static void GetOnRender(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnRender(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnMouseDown(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnMouseDown(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnMouseUp(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnMouseUp(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnMouseMove(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnMouseMove(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnMouseWheel(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnMouseWheel(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnTouchDown(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnTouchDown(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnTouchUp(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnTouchUp(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnTouchMove(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnTouchMove(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; + + diff --git a/Three.V8/gui/UIArea.hpp b/Three.V8/gui/WrapperUIArea.cpp similarity index 63% rename from Three.V8/gui/UIArea.hpp rename to Three.V8/gui/WrapperUIArea.cpp index 6b3568d5..17e238b9 100644 --- a/Three.V8/gui/UIArea.hpp +++ b/Three.V8/gui/WrapperUIArea.cpp @@ -1,69 +1,36 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include "WrapperUIArea.h" - -class WrapperUIArea +void WrapperUIArea::define(ClassDefinition& cls) { -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetElements(v8::Local property, const v8::PropertyCallbackInfo& info); - static void Add(const v8::FunctionCallbackInfo& info); - static void Remove(const v8::FunctionCallbackInfo& info); - static void Clear(const v8::FunctionCallbackInfo& info); - - static void GetViewers(v8::Local property, const v8::PropertyCallbackInfo& info); - static void AddViewer(const v8::FunctionCallbackInfo& info); - static void RemoveViewer(const v8::FunctionCallbackInfo& info); - static void ClearViewers(const v8::FunctionCallbackInfo& info); - - static void GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetOrigin(const v8::FunctionCallbackInfo& info); - static void SetOrigin(const v8::FunctionCallbackInfo& info); - - static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSize(const v8::FunctionCallbackInfo& info); - static void SetSize(const v8::FunctionCallbackInfo& info); - - static void GetScale(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetScale(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; + cls.name = "UIArea"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "elements", GetElements}, + { "viewers", GetViewers}, + { "origin", GetOrigin }, + { "size", GetSize }, + { "scale", GetScale, SetScale }, + }; + cls.methods = { + {"add", Add }, + {"remove", Remove }, + {"clear", Clear }, + {"addViewer", AddViewer }, + {"removeViewer", RemoveViewer }, + {"clearViewer", ClearViewers }, + {"getOrigin", GetOrigin }, + {"setOrigin", SetOrigin }, + {"getSize", GetSize }, + {"setSize", SetSize }, + }; +} -v8::Local WrapperUIArea::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void* WrapperUIArea::ctor(const v8::FunctionCallbackInfo& info) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "elements").ToLocalChecked(), GetElements, 0); - templ->InstanceTemplate()->Set(isolate, "add", v8::FunctionTemplate::New(isolate, Add)); - templ->InstanceTemplate()->Set(isolate, "remove", v8::FunctionTemplate::New(isolate, Remove)); - templ->InstanceTemplate()->Set(isolate, "clear", v8::FunctionTemplate::New(isolate, Clear)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "viewers").ToLocalChecked(), GetViewers, 0); - templ->InstanceTemplate()->Set(isolate, "addViewer", v8::FunctionTemplate::New(isolate, AddViewer)); - templ->InstanceTemplate()->Set(isolate, "removeViewer", v8::FunctionTemplate::New(isolate, RemoveViewer)); - templ->InstanceTemplate()->Set(isolate, "clearViewer", v8::FunctionTemplate::New(isolate, ClearViewers)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "origin").ToLocalChecked(), GetOrigin, 0); - templ->InstanceTemplate()->Set(isolate, "getOrigin", v8::FunctionTemplate::New(isolate, GetOrigin)); - templ->InstanceTemplate()->Set(isolate, "setOrigin", v8::FunctionTemplate::New(isolate, SetOrigin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "size").ToLocalChecked(), GetSize, 0); - templ->InstanceTemplate()->Set(isolate, "getSize", v8::FunctionTemplate::New(isolate, GetSize)); - templ->InstanceTemplate()->Set(isolate, "setSize", v8::FunctionTemplate::New(isolate, SetSize)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scale").ToLocalChecked(), GetScale, SetScale); - - return templ; - + return new UIArea; } void WrapperUIArea::dtor(void* ptr, GameContext* ctx) @@ -71,21 +38,11 @@ void WrapperUIArea::dtor(void* ptr, GameContext* ctx) delete (UIArea*)ptr; } -void WrapperUIArea::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIArea* self = new UIArea(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - - void WrapperUIArea::GetElements(v8::Local property, const v8::PropertyCallbackInfo& info) { - LocalContext lctx(info); + LocalContext lctx(info); v8::Local elements; - if (lctx.has_property(lctx.holder, "_elements")) + if (lctx.has_property(lctx.holder, "_elements")) { elements = lctx.get_property(lctx.holder, "_elements"); } @@ -242,7 +199,7 @@ void WrapperUIArea::GetOrigin(v8::Local property, const v8::Property void WrapperUIArea::GetOrigin(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - UIArea* self = lctx.self(); + UIArea* self = lctx.self(); lctx.vec2_to_jvec2(self->origin, info[0]); info.GetReturnValue().Set(info[0]); } diff --git a/Three.V8/gui/WrapperUIArea.h b/Three.V8/gui/WrapperUIArea.h new file mode 100644 index 00000000..0e8696f3 --- /dev/null +++ b/Three.V8/gui/WrapperUIArea.h @@ -0,0 +1,37 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUIArea +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetElements(v8::Local property, const v8::PropertyCallbackInfo& info); + static void Add(const v8::FunctionCallbackInfo& info); + static void Remove(const v8::FunctionCallbackInfo& info); + static void Clear(const v8::FunctionCallbackInfo& info); + + static void GetViewers(v8::Local property, const v8::PropertyCallbackInfo& info); + static void AddViewer(const v8::FunctionCallbackInfo& info); + static void RemoveViewer(const v8::FunctionCallbackInfo& info); + static void ClearViewers(const v8::FunctionCallbackInfo& info); + + static void GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetOrigin(const v8::FunctionCallbackInfo& info); + static void SetOrigin(const v8::FunctionCallbackInfo& info); + + static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSize(const v8::FunctionCallbackInfo& info); + static void SetSize(const v8::FunctionCallbackInfo& info); + + static void GetScale(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetScale(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; diff --git a/Three.V8/gui/WrapperUIBlock.cpp b/Three.V8/gui/WrapperUIBlock.cpp new file mode 100644 index 00000000..0abe90a8 --- /dev/null +++ b/Three.V8/gui/WrapperUIBlock.cpp @@ -0,0 +1,89 @@ +#include "WrapperUtils.hpp" +#include "WrapperUIElement.h" +#include + +#include "WrapperUIBlock.h" + + +void WrapperUIBlock::define(ClassDefinition& cls) +{ + WrapperUIElement::define(cls); + cls.name = "UIBlock"; + cls.ctor = ctor; + + std::vector props = { + { "size", GetSize }, + { "scissorEnabled", GetScissorEnabled, SetScissorEnabled }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getSize", GetSize }, + {"setSize", SetSize }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); +} + + +void* WrapperUIBlock::ctor(const v8::FunctionCallbackInfo& info) +{ + return new UIBlock; +} + +void WrapperUIBlock::GetSize(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + UIBlock* self = lctx.self(); + v8::Local size = v8::Object::New(lctx.isolate); + lctx.vec2_to_jvec2(self->size, size); + info.GetReturnValue().Set(size); +} + + +void WrapperUIBlock::GetSize(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + UIBlock* self = lctx.self(); + lctx.vec2_to_jvec2(self->size, info[0]); + info.GetReturnValue().Set(info[0]); +} + + +void WrapperUIBlock::SetSize(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + UIBlock* self = lctx.self(); + glm::vec2 size; + if (info[0]->IsNumber()) + { + lctx.jnum_to_num(info[0], size.x); + lctx.jnum_to_num(info[1], size.y); + } + else + { + lctx.jvec2_to_vec2(info[0], size); + } + if (self->size != size) + { + self->size = size; + self->appearance_changed = true; + } +} + + +void WrapperUIBlock::GetScissorEnabled(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + UIBlock* self = lctx.self(); + v8::Local ret = v8::Boolean::New(lctx.isolate, self->scissor_enabled); + info.GetReturnValue().Set(ret); +} + +void WrapperUIBlock::SetScissorEnabled(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + UIBlock* self = lctx.self(); + self->scissor_enabled = value.As()->Value(); +} + + diff --git a/Three.V8/gui/WrapperUIBlock.h b/Three.V8/gui/WrapperUIBlock.h new file mode 100644 index 00000000..5ffd6a2c --- /dev/null +++ b/Three.V8/gui/WrapperUIBlock.h @@ -0,0 +1,19 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperUIBlock +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSize(const v8::FunctionCallbackInfo& info); + static void SetSize(const v8::FunctionCallbackInfo& info); + + static void GetScissorEnabled(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetScissorEnabled(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/gui/UIButton.hpp b/Three.V8/gui/WrapperUIButton.cpp similarity index 69% rename from Three.V8/gui/UIButton.hpp rename to Three.V8/gui/WrapperUIButton.cpp index 66fc7e56..ae42032b 100644 --- a/Three.V8/gui/UIButton.hpp +++ b/Three.V8/gui/WrapperUIButton.cpp @@ -1,53 +1,42 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIBlock.hpp" +#include "WrapperUIElement.h" +#include "WrapperUIBlock.h" #include +#include "WrapperUIButton.h" + +typedef v8::Persistent> CallbackT; -class WrapperUIButton +struct UIButtonClickData { -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void SetStyle(const v8::FunctionCallbackInfo& info); - - static void GetOnClick(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnClick(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnLongPress(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnLongPress(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + GameContext* ctx; + CallbackT callback; }; - -v8::Local WrapperUIButton::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUIButton::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIBlock::create_template(isolate, constructor); - templ->InstanceTemplate()->Set(isolate, "setStyle", v8::FunctionTemplate::New(isolate, SetStyle)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onClick").ToLocalChecked(), GetOnClick, SetOnClick); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onLongPress").ToLocalChecked(), GetOnLongPress, SetOnLongPress); - return templ; + WrapperUIBlock::define(cls); + cls.name = "UIButton"; + cls.ctor = ctor; + cls.dtor = dtor; + + std::vector props = { + { "onClick", GetOnClick, SetOnClick }, + { "onLongPress", GetOnLongPress, SetOnLongPress }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"setStyle", SetStyle }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperUIButton::New(const v8::FunctionCallbackInfo& info) +void* WrapperUIButton::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - UIButton* self = new UIButton(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + return new UIButton; } -typedef v8::Persistent> CallbackT; - -struct UIButtonClickData -{ - GameContext* ctx; - CallbackT callback; -}; - void WrapperUIButton::dtor(void* ptr, GameContext* ctx) { UIButton* self = (UIButton*)ptr; @@ -110,7 +99,7 @@ static void UIButtonClickCallback(void* ptr) v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); std::vector> args; ctx->InvokeCallback(*callback, args); } @@ -133,7 +122,7 @@ void WrapperUIButton::SetOnClick(v8::Local property, v8::Localclick_callback_data != nullptr) { UIButtonClickData* data = (UIButtonClickData*)self->click_callback_data; - delete data; + delete data; } UIButtonClickData* data = new UIButtonClickData; @@ -149,7 +138,7 @@ void WrapperUIButton::SetOnClick(v8::Local property, v8::Local property, const v8::PropertyCallbackInfo& info) { - LocalContext lctx(info); + LocalContext lctx(info); v8::Local onLongPress = lctx.get_property(lctx.holder, "_onLongPress"); info.GetReturnValue().Set(onLongPress); } @@ -176,4 +165,4 @@ void WrapperUIButton::SetOnLongPress(v8::Local property, v8::Locallong_press_callback_data = data; -} \ No newline at end of file +} diff --git a/Three.V8/gui/WrapperUIButton.h b/Three.V8/gui/WrapperUIButton.h new file mode 100644 index 00000000..58f7f2b8 --- /dev/null +++ b/Three.V8/gui/WrapperUIButton.h @@ -0,0 +1,23 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUIButton +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void SetStyle(const v8::FunctionCallbackInfo& info); + + static void GetOnClick(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnClick(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnLongPress(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnLongPress(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/gui/UIDraggable.hpp b/Three.V8/gui/WrapperUIDraggable.cpp similarity index 61% rename from Three.V8/gui/UIDraggable.hpp rename to Three.V8/gui/WrapperUIDraggable.cpp index c7af8b62..3d0e1236 100644 --- a/Three.V8/gui/UIDraggable.hpp +++ b/Three.V8/gui/WrapperUIDraggable.cpp @@ -1,80 +1,52 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIPanel.hpp" +#include "WrapperUIPanel.h" +#include "WrapperUIElement.h" #include +#include "WrapperUIDraggable.h" + +typedef v8::Persistent> CallbackT; -class WrapperUIDraggable +struct UIDragData { -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetDraggableHorizontal(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDraggableHorizontal(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetDraggableVertical(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDraggableVertical(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOriginMin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetOriginMin(const v8::FunctionCallbackInfo& info); - static void SetOriginMin(const v8::FunctionCallbackInfo& info); - - static void GetOriginMax(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetOriginMax(const v8::FunctionCallbackInfo& info); - static void SetOriginMax(const v8::FunctionCallbackInfo& info); - - static void GetValue(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetValue(const v8::FunctionCallbackInfo& info); - static void SetValue(const v8::FunctionCallbackInfo& info); - - static void GetOnDrag(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnDrag(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + GameContext* ctx; + CallbackT callback; }; -v8::Local WrapperUIDraggable::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUIDraggable::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIPanel::create_template(isolate, constructor); + WrapperUIPanel::define(cls); + cls.name = "UIDraggable"; + cls.ctor = ctor; + cls.dtor = dtor; - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "draggableHorizontal").ToLocalChecked(), GetDraggableHorizontal, SetDraggableHorizontal); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "draggableVertical").ToLocalChecked(), GetDraggableVertical, SetDraggableVertical); + std::vector props = { + { "draggableHorizontal", GetDraggableHorizontal, SetDraggableHorizontal }, + { "draggableVertical", GetDraggableVertical, SetDraggableVertical }, + { "originMin", GetOriginMin }, + { "originMax", GetOriginMax }, + { "value", GetValue }, + { "onDrag", GetOnDrag, SetOnDrag }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "originMin").ToLocalChecked(), GetOriginMin, 0); - templ->InstanceTemplate()->Set(isolate, "getOriginMin", v8::FunctionTemplate::New(isolate, GetOriginMin)); - templ->InstanceTemplate()->Set(isolate, "setOriginMin", v8::FunctionTemplate::New(isolate, SetOriginMin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "originMax").ToLocalChecked(), GetOriginMax, 0); - templ->InstanceTemplate()->Set(isolate, "getOriginMax", v8::FunctionTemplate::New(isolate, GetOriginMax)); - templ->InstanceTemplate()->Set(isolate, "setOriginMax", v8::FunctionTemplate::New(isolate, SetOriginMax)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "value").ToLocalChecked(), GetValue, 0); - templ->InstanceTemplate()->Set(isolate, "getValue", v8::FunctionTemplate::New(isolate, GetValue)); - templ->InstanceTemplate()->Set(isolate, "setValue", v8::FunctionTemplate::New(isolate, SetValue)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onDrag").ToLocalChecked(), GetOnDrag, SetOnDrag); - - return templ; -} - -void WrapperUIDraggable::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - UIDraggable* self = new UIDraggable(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + std::vector methods = { + {"getOriginMin", GetOriginMin }, + {"setOriginMin", SetOriginMin }, + {"getOriginMax", GetOriginMax }, + {"setOriginMax", SetOriginMax }, + {"getValue", GetValue }, + {"setValue", SetValue }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -typedef v8::Persistent> CallbackT; - -struct UIDragData +void* WrapperUIDraggable::ctor(const v8::FunctionCallbackInfo& info) { - GameContext* ctx; - CallbackT callback; -}; + return new UIDraggable; +} void WrapperUIDraggable::dtor(void* ptr, GameContext* ctx) { @@ -83,7 +55,7 @@ void WrapperUIDraggable::dtor(void* ptr, GameContext* ctx) { UIDragData* data = (UIDragData*)self->drag_callback_data; delete data; - } + } WrapperUIElement::dtor(ptr, ctx); } @@ -241,10 +213,10 @@ static void UIDragCallback(void* ptr, const glm::vec2& value) v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); std::vector> args(2); args[0] = v8::Number::New(isolate, (double)value.x); - args[1] = v8::Number::New(isolate, (double)value.y); + args[1] = v8::Number::New(isolate, (double)value.y); ctx->InvokeCallback(*callback, args); } diff --git a/Three.V8/gui/WrapperUIDraggable.h b/Three.V8/gui/WrapperUIDraggable.h new file mode 100644 index 00000000..0e47cc0f --- /dev/null +++ b/Three.V8/gui/WrapperUIDraggable.h @@ -0,0 +1,35 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUIDraggable +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetDraggableHorizontal(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDraggableHorizontal(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void GetDraggableVertical(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDraggableVertical(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOriginMin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetOriginMin(const v8::FunctionCallbackInfo& info); + static void SetOriginMin(const v8::FunctionCallbackInfo& info); + + static void GetOriginMax(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetOriginMax(const v8::FunctionCallbackInfo& info); + static void SetOriginMax(const v8::FunctionCallbackInfo& info); + + static void GetValue(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetValue(const v8::FunctionCallbackInfo& info); + static void SetValue(const v8::FunctionCallbackInfo& info); + + static void GetOnDrag(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnDrag(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/gui/UIElement.hpp b/Three.V8/gui/WrapperUIElement.cpp similarity index 69% rename from Three.V8/gui/UIElement.hpp rename to Three.V8/gui/WrapperUIElement.cpp index aa99e78e..334a7621 100644 --- a/Three.V8/gui/UIElement.hpp +++ b/Three.V8/gui/WrapperUIElement.cpp @@ -1,53 +1,28 @@ -#pragma once - #include "WrapperUtils.hpp" #include -class WrapperUIElement -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetBlock(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetBlock(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetOrigin(const v8::FunctionCallbackInfo& info); - static void SetOrigin(const v8::FunctionCallbackInfo& info); - - static void GetOnPointerDown(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnPointerDown(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnPointerUp(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnPointerUp(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnPointerMove(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnPointerMove(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; +#include "WrapperUIElement.h" -v8::Local WrapperUIElement::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUIElement::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "block").ToLocalChecked(), GetBlock, SetBlock); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "origin").ToLocalChecked(), GetOrigin, 0); - templ->InstanceTemplate()->Set(isolate, "getOrigin", v8::FunctionTemplate::New(isolate, GetOrigin)); - templ->InstanceTemplate()->Set(isolate, "setOrigin", v8::FunctionTemplate::New(isolate, SetOrigin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onPointerDown").ToLocalChecked(), GetOnPointerDown, SetOnPointerDown); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onPointerUp").ToLocalChecked(), GetOnPointerUp, SetOnPointerUp); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onPointerMove").ToLocalChecked(), GetOnPointerMove, SetOnPointerMove); + cls.name = "UIElement"; + cls.dtor = dtor; + cls.properties = { + { "block", GetBlock, SetBlock }, + { "origin", GetOrigin }, + { "onPointerDown",GetOnPointerDown, SetOnPointerDown}, + { "onPointerUp", GetOnPointerUp, SetOnPointerUp }, + { "onPointerMove",GetOnPointerMove, SetOnPointerMove }, + }; + cls.methods = { + {"getOrigin", GetOrigin }, + {"setOrigin", SetOrigin } + }; - return templ; } +typedef v8::Persistent> CallbackT; struct UIElementCallbackData { @@ -94,7 +69,7 @@ void WrapperUIElement::SetBlock(v8::Local property, v8::Local(); UIBlock* block = lctx.jobj_to_obj(value); self->block = block; - lctx.set_property(lctx.holder, "_block", value); + lctx.set_property(lctx.holder, "_block", value); } void WrapperUIElement::GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -147,10 +122,10 @@ static void UIElementPointerCallback(float x, float y, void* ptr) v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); std::vector> args(2); args[0] = v8::Number::New(isolate, (double)x); - args[1] = v8::Number::New(isolate, (double)y); + args[1] = v8::Number::New(isolate, (double)y); ctx->InvokeCallback(*callback, args); } @@ -227,7 +202,7 @@ void WrapperUIElement::SetOnPointerUp(v8::Local property, v8::Local< { self->pointer_up_callback = nullptr; self->pointer_up_callback_data = nullptr; - } + } } @@ -266,6 +241,7 @@ void WrapperUIElement::SetOnPointerMove(v8::Local property, v8::Loca { self->pointer_move_callback = nullptr; self->pointer_move_callback_data = nullptr; - } + } + +} -} \ No newline at end of file diff --git a/Three.V8/gui/WrapperUIElement.h b/Three.V8/gui/WrapperUIElement.h new file mode 100644 index 00000000..36ef6bdc --- /dev/null +++ b/Three.V8/gui/WrapperUIElement.h @@ -0,0 +1,30 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUIElement +{ +public: + static void define(ClassDefinition& cls); + static void dtor(void* ptr, GameContext* ctx); + +private: + static void GetBlock(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetBlock(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOrigin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetOrigin(const v8::FunctionCallbackInfo& info); + static void SetOrigin(const v8::FunctionCallbackInfo& info); + + static void GetOnPointerDown(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnPointerDown(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnPointerUp(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnPointerUp(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnPointerMove(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnPointerMove(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; diff --git a/Three.V8/gui/UIImage.hpp b/Three.V8/gui/WrapperUIImage.cpp similarity index 52% rename from Three.V8/gui/UIImage.hpp rename to Three.V8/gui/WrapperUIImage.cpp index d4d767e9..298b75f4 100644 --- a/Three.V8/gui/UIImage.hpp +++ b/Three.V8/gui/WrapperUIImage.cpp @@ -1,48 +1,44 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIElement.hpp" +#include "WrapperUIElement.h" #include +#include +#include "WrapperUIImage.h" -class WrapperUIImage -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSize(const v8::FunctionCallbackInfo& info); - static void SetSize(const v8::FunctionCallbackInfo& info); - - static void SetImage(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperUIImage::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUIImage::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIElement::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "size").ToLocalChecked(), GetSize, 0); - templ->InstanceTemplate()->Set(isolate, "getSize", v8::FunctionTemplate::New(isolate, GetSize)); - templ->InstanceTemplate()->Set(isolate, "setSize", v8::FunctionTemplate::New(isolate, SetSize)); - templ->InstanceTemplate()->Set(isolate, "setImage", v8::FunctionTemplate::New(isolate, SetImage)); - return templ; + WrapperUIElement::define(cls); + cls.name = "UIImage"; + cls.ctor = ctor; + cls.dtor = dtor; + + std::vector props = { + { "size", GetSize }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getSize", GetSize }, + {"setSize", SetSize }, + {"setImage", SetImage }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperUIImage::New(const v8::FunctionCallbackInfo& info) +void* WrapperUIImage::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - UIImage* self = new UIImage(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + return new UIImage; } void WrapperUIImage::dtor(void* ptr, GameContext* ctx) { + v8::Isolate* isolate = ctx->m_vm->m_isolate; + v8::HandleScope handle_scope(isolate); + v8::Context::Scope context_scope(ctx->m_context.Get(isolate)); + LocalContext lctx(isolate); + UIImage* self = (UIImage*)ptr; - GamePlayer* player = ctx->GetGamePlayer(); + GamePlayer* player = lctx.player(); GLUIRenderer& renderer = player->UIRenderer(); if (self->id_image != -1) { @@ -107,4 +103,5 @@ void WrapperUIImage::SetImage(const v8::FunctionCallbackInfo& info) self->size.y = (float)image->height(); self->appearance_changed = true; -} \ No newline at end of file +} + diff --git a/Three.V8/gui/WrapperUIImage.h b/Three.V8/gui/WrapperUIImage.h new file mode 100644 index 00000000..d0b6a8d6 --- /dev/null +++ b/Three.V8/gui/WrapperUIImage.h @@ -0,0 +1,21 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUIImage +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSize(const v8::FunctionCallbackInfo& info); + static void SetSize(const v8::FunctionCallbackInfo& info); + + static void SetImage(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/gui/UILineEdit.hpp b/Three.V8/gui/WrapperUILineEdit.cpp similarity index 57% rename from Three.V8/gui/UILineEdit.hpp rename to Three.V8/gui/WrapperUILineEdit.cpp index e61523b8..5c92b49e 100644 --- a/Three.V8/gui/UILineEdit.hpp +++ b/Three.V8/gui/WrapperUILineEdit.cpp @@ -1,52 +1,39 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIElement.hpp" +#include "WrapperUIElement.h" #include -class WrapperUILineEdit -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSize(const v8::FunctionCallbackInfo& info); - static void SetSize(const v8::FunctionCallbackInfo& info); - - static void GetText(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetText(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +#include "WrapperUILineEdit.h" - static void SetStyle(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperUILineEdit::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUILineEdit::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIElement::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "size").ToLocalChecked(), GetSize, 0); - templ->InstanceTemplate()->Set(isolate, "getSize", v8::FunctionTemplate::New(isolate, GetSize)); - templ->InstanceTemplate()->Set(isolate, "setSize", v8::FunctionTemplate::New(isolate, SetSize)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "text").ToLocalChecked(), GetText, SetText); - templ->InstanceTemplate()->Set(isolate, "setStyle", v8::FunctionTemplate::New(isolate, SetStyle)); - - - return templ; + WrapperUIElement::define(cls); + cls.name = "UILineEdit"; + cls.ctor = ctor; + cls.dtor = dtor; + + std::vector props = { + { "size", GetSize }, + { "text",GetText, SetText }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getSize", GetSize }, + {"setSize", SetSize }, + {"setStyle", SetStyle }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperUILineEdit::New(const v8::FunctionCallbackInfo& info) + +void* WrapperUILineEdit::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - UILineEdit* self = new UILineEdit(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + return new UILineEdit; } void WrapperUILineEdit::dtor(void* ptr, GameContext* ctx) { - UILineEdit* self = (UILineEdit*)ptr; + UILineEdit* self = (UILineEdit*)ptr; WrapperUIElement::dtor(ptr, ctx); } @@ -140,3 +127,7 @@ void WrapperUILineEdit::SetStyle(const v8::FunctionCallbackInfo& info self->appearance_changed = true; } + + + + diff --git a/Three.V8/gui/WrapperUILineEdit.h b/Three.V8/gui/WrapperUILineEdit.h new file mode 100644 index 00000000..710b2ca3 --- /dev/null +++ b/Three.V8/gui/WrapperUILineEdit.h @@ -0,0 +1,22 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperUILineEdit +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetSize(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSize(const v8::FunctionCallbackInfo& info); + static void SetSize(const v8::FunctionCallbackInfo& info); + + static void GetText(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetText(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void SetStyle(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/gui/UIManager.hpp b/Three.V8/gui/WrapperUIManager.cpp similarity index 68% rename from Three.V8/gui/UIManager.hpp rename to Three.V8/gui/WrapperUIManager.cpp index 2efd307e..1d22d4d4 100644 --- a/Three.V8/gui/UIManager.hpp +++ b/Three.V8/gui/WrapperUIManager.cpp @@ -1,32 +1,34 @@ -#pragma once +#include "WrapperUIManager.h" #include "WrapperUtils.hpp" #include -class WrapperUIManager -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void GetAreas(v8::Local property, const v8::PropertyCallbackInfo& info); - static void Add(const v8::FunctionCallbackInfo& info); - static void Remove(const v8::FunctionCallbackInfo& info); - static void Clear(const v8::FunctionCallbackInfo& info); -}; +void WrapperUIManager::define(ObjectDefinition& object) +{ + object.name = "UIManager"; + object.ctor = ctor; + object.dtor = dtor; + object.properties = { + { "areas", GetAreas }, + }; + + object.methods = { + { "add", Add }, + { "remove", Remove }, + { "clear", Clear }, + }; +} -v8::Local WrapperUIManager::create_template(v8::Isolate* isolate) +void* WrapperUIManager::ctor() { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->SetInternalFieldCount(1); - templ->SetAccessor(v8::String::NewFromUtf8(isolate, "areas").ToLocalChecked(), GetAreas, 0); - templ->Set(isolate, "add", v8::FunctionTemplate::New(isolate, Add)); - templ->Set(isolate, "remove", v8::FunctionTemplate::New(isolate, Remove)); - templ->Set(isolate, "clear", v8::FunctionTemplate::New(isolate, Clear)); - return templ; + return new UIManager; } +void WrapperUIManager::dtor(void* ptr, GameContext* ctx) +{ + delete (UIManager*)ptr; +} void WrapperUIManager::GetAreas(v8::Local property, const v8::PropertyCallbackInfo& info) { @@ -71,7 +73,7 @@ void WrapperUIManager::Remove(const v8::FunctionCallbackInfo& info) { v8::Local area_i = areas->Get(lctx.context, i).ToLocalChecked(); if (area_i == info[0]) - { + { for (unsigned j = i; j < areas->Length() - 1; j++) { areas->Set(lctx.context, j, areas->Get(lctx.context, j + 1).ToLocalChecked()); @@ -93,10 +95,11 @@ void WrapperUIManager::Clear(const v8::FunctionCallbackInfo& info) v8::Local areas = lctx.get_property(lctx.holder, "areas").As(); for (unsigned i = 0; i < areas->Length(); i++) - { + { areas->Delete(lctx.context, i); } lctx.set_property(areas, "length", lctx.num_to_jnum(0)); info.GetReturnValue().Set(lctx.holder); -} \ No newline at end of file +} + diff --git a/Three.V8/gui/WrapperUIManager.h b/Three.V8/gui/WrapperUIManager.h new file mode 100644 index 00000000..4f11af3d --- /dev/null +++ b/Three.V8/gui/WrapperUIManager.h @@ -0,0 +1,18 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperUIManager +{ +public: + static void define(ObjectDefinition& object); + +private: + static void* ctor(); + static void dtor(void* ptr, GameContext* ctx); + static void GetAreas(v8::Local property, const v8::PropertyCallbackInfo& info); + static void Add(const v8::FunctionCallbackInfo& info); + static void Remove(const v8::FunctionCallbackInfo& info); + static void Clear(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/gui/WrapperUIPanel.cpp b/Three.V8/gui/WrapperUIPanel.cpp new file mode 100644 index 00000000..14780a6c --- /dev/null +++ b/Three.V8/gui/WrapperUIPanel.cpp @@ -0,0 +1,55 @@ +#include "WrapperUtils.hpp" +#include "WrapperUIBlock.h" +#include + +#include "WrapperUIPanel.h" + + +void WrapperUIPanel::define(ClassDefinition& cls) +{ + WrapperUIBlock::define(cls); + cls.name = "UIPanel"; + cls.ctor = ctor; + + std::vector methods = { + {"setStyle", SetStyle }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); +} + +void* WrapperUIPanel::ctor(const v8::FunctionCallbackInfo& info) +{ + return new UIPanel; +} + +void WrapperUIPanel::SetStyle(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + UIPanel* self = lctx.self(); + + v8::Local style = info[0].As(); + + if (lctx.has_property(style, "cornerRadius")) + { + lctx.jnum_to_num(lctx.get_property(style, "cornerRadius"), self->cornerRadius); + } + + if (lctx.has_property(style, "strokeWidth")) + { + lctx.jnum_to_num(lctx.get_property(style, "strokeWidth"), self->strokeWidth); + } + + if (lctx.has_property(style, "colorBg")) + { + std::string str = lctx.jstr_to_str(lctx.get_property(style, "colorBg")); + string_to_color(str.c_str(), self->colorBg); + } + + if (lctx.has_property(style, "colorStroke")) + { + std::string str = lctx.jstr_to_str(lctx.get_property(style, "colorStroke")); + string_to_color(str.c_str(), self->colorStroke); + } + self->appearance_changed = true; +} + diff --git a/Three.V8/gui/WrapperUIPanel.h b/Three.V8/gui/WrapperUIPanel.h new file mode 100644 index 00000000..04d2109b --- /dev/null +++ b/Three.V8/gui/WrapperUIPanel.h @@ -0,0 +1,15 @@ +#pragma once + +#include "definitions.hpp" + + +class WrapperUIPanel +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void SetStyle(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/gui/UIScrollViewer.hpp b/Three.V8/gui/WrapperUIScrollViewer.cpp similarity index 59% rename from Three.V8/gui/UIScrollViewer.hpp rename to Three.V8/gui/WrapperUIScrollViewer.cpp index 92bc5c3a..523db221 100644 --- a/Three.V8/gui/UIScrollViewer.hpp +++ b/Three.V8/gui/WrapperUIScrollViewer.cpp @@ -1,60 +1,36 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIBlock.hpp" +#include "WrapperUIBlock.h" #include - -class WrapperUIScrollViewer -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void SetStyle(const v8::FunctionCallbackInfo& info); - - static void GetScrollableVertical(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetScrollableVertical(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetScrollableHorizontal(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetScrollableHorizontal(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetScrollPosition(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetScrollPosition(const v8::FunctionCallbackInfo& info); - static void SetScrollPosition(const v8::FunctionCallbackInfo& info); - - static void GetContentSize(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetContentSize(const v8::FunctionCallbackInfo& info); - static void SetContentSize(const v8::FunctionCallbackInfo& info); -}; +#include "WrapperUIScrollViewer.h" -v8::Local WrapperUIScrollViewer::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUIScrollViewer::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIBlock::create_template(isolate, constructor); - templ->InstanceTemplate()->Set(isolate, "setStyle", v8::FunctionTemplate::New(isolate, SetStyle)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scrollableVertical").ToLocalChecked(), GetScrollableVertical, SetScrollableVertical); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scrollableHorizontal").ToLocalChecked(), GetScrollableHorizontal, SetScrollableHorizontal); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "scrollPosition").ToLocalChecked(), GetScrollPosition, 0); - templ->InstanceTemplate()->Set(isolate, "getScrollPosition", v8::FunctionTemplate::New(isolate, GetScrollPosition)); - templ->InstanceTemplate()->Set(isolate, "setScrollPosition", v8::FunctionTemplate::New(isolate, SetScrollPosition)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "contentSize").ToLocalChecked(), GetContentSize, 0); - templ->InstanceTemplate()->Set(isolate, "getContentSize", v8::FunctionTemplate::New(isolate, GetContentSize)); - templ->InstanceTemplate()->Set(isolate, "setContentSize", v8::FunctionTemplate::New(isolate, SetContentSize)); - - return templ; + WrapperUIBlock::define(cls); + cls.name = "UIScrollViewer"; + cls.ctor = ctor; + + std::vector props = { + { "scrollableVertical", GetScrollableVertical, SetScrollableVertical }, + { "scrollableHorizontal", GetScrollableHorizontal, SetScrollableHorizontal }, + { "scrollPosition", GetScrollPosition }, + { "contentSize",GetContentSize }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getScrollPosition", GetScrollPosition }, + {"setScrollPosition", SetScrollPosition }, + {"getContentSize", GetContentSize }, + {"setContentSize", SetContentSize }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperUIScrollViewer::New(const v8::FunctionCallbackInfo& info) +void* WrapperUIScrollViewer::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - UIScrollViewer* self = new UIScrollViewer(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperUIElement::dtor); + return new UIScrollViewer; } void WrapperUIScrollViewer::SetStyle(const v8::FunctionCallbackInfo& info) @@ -66,7 +42,7 @@ void WrapperUIScrollViewer::SetStyle(const v8::FunctionCallbackInfo& if (lctx.has_property(style, "cornerRadius")) { - lctx.jnum_to_num(lctx.get_property(style, "cornerRadius"), self->cornerRadius); + lctx.jnum_to_num(lctx.get_property(style, "cornerRadius"), self->cornerRadius); } if (lctx.has_property(style, "strokeWidth")) @@ -192,10 +168,11 @@ void WrapperUIScrollViewer::SetContentSize(const v8::FunctionCallbackInfocontent_size != content_size) { self->content_size = content_size; self->appearance_changed = true; - } + } } + diff --git a/Three.V8/gui/WrapperUIScrollViewer.h b/Three.V8/gui/WrapperUIScrollViewer.h new file mode 100644 index 00000000..72ae2524 --- /dev/null +++ b/Three.V8/gui/WrapperUIScrollViewer.h @@ -0,0 +1,32 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperUIScrollViewer +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void SetStyle(const v8::FunctionCallbackInfo& info); + + static void GetScrollableVertical(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetScrollableVertical(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetScrollableHorizontal(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetScrollableHorizontal(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetScrollPosition(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetScrollPosition(const v8::FunctionCallbackInfo& info); + static void SetScrollPosition(const v8::FunctionCallbackInfo& info); + + static void GetContentSize(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetContentSize(const v8::FunctionCallbackInfo& info); + static void SetContentSize(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/gui/UIText.hpp b/Three.V8/gui/WrapperUIText.cpp similarity index 52% rename from Three.V8/gui/UIText.hpp rename to Three.V8/gui/WrapperUIText.cpp index c80c024b..760cf498 100644 --- a/Three.V8/gui/UIText.hpp +++ b/Three.V8/gui/WrapperUIText.cpp @@ -1,44 +1,35 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIElement.hpp" +#include "WrapperUIElement.h" #include +#include "WrapperUIText.h" -class WrapperUIText -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetText(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetText(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void SetStyle(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperUIText::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUIText::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIElement::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "text").ToLocalChecked(), GetText, SetText); - templ->InstanceTemplate()->Set(isolate, "setStyle", v8::FunctionTemplate::New(isolate, SetStyle)); - return templ; + WrapperUIElement::define(cls); + cls.name = "UIText"; + cls.ctor = ctor; + + std::vector props = { + { "text", GetText, SetText }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"setStyle", SetStyle }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperUIText::New(const v8::FunctionCallbackInfo& info) +void* WrapperUIText::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - UIText* self = new UIText(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperUIElement::dtor); + return new UIText; } - void WrapperUIText::GetText(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - UIText* self = lctx.self(); + UIText* self = lctx.self(); info.GetReturnValue().Set(lctx.str_to_jstr(self->text.c_str())); } @@ -79,7 +70,7 @@ void WrapperUIText::SetStyle(const v8::FunctionCallbackInfo& info) lctx.jnum_to_num(lctx.get_property(style, "alignmentVertical"), self->alignment_vertical); } - if (lctx.has_property(style, "colorFg")) + if (lctx.has_property(style, "colorFg")) { std::string str = lctx.jstr_to_str(lctx.get_property(style, "colorFg")); string_to_color(str.c_str(), self->colorFg); @@ -88,3 +79,4 @@ void WrapperUIText::SetStyle(const v8::FunctionCallbackInfo& info) self->appearance_changed = true; } + diff --git a/Three.V8/gui/WrapperUIText.h b/Three.V8/gui/WrapperUIText.h new file mode 100644 index 00000000..f0bc5858 --- /dev/null +++ b/Three.V8/gui/WrapperUIText.h @@ -0,0 +1,15 @@ +#include "definitions.hpp" + +class WrapperUIText +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetText(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetText(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void SetStyle(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/gui/UITextBlock.hpp b/Three.V8/gui/WrapperUITextBlock.cpp similarity index 59% rename from Three.V8/gui/UITextBlock.hpp rename to Three.V8/gui/WrapperUITextBlock.cpp index 54702cc2..65adea9f 100644 --- a/Three.V8/gui/UITextBlock.hpp +++ b/Three.V8/gui/WrapperUITextBlock.cpp @@ -1,39 +1,31 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "UIElement.hpp" +#include "WrapperUIElement.h" #include +#include "WrapperUITextBlock.h" -class WrapperUITextBlock -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetText(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetText(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void SetStyle(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperUITextBlock::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperUITextBlock::define(ClassDefinition& cls) { - v8::Local templ = WrapperUIElement::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "text").ToLocalChecked(), GetText, SetText); - templ->InstanceTemplate()->Set(isolate, "setStyle", v8::FunctionTemplate::New(isolate, SetStyle)); - return templ; + WrapperUIElement::define(cls); + cls.name = "UITextBlock"; + cls.ctor = ctor; + + std::vector props = { + { "text", GetText, SetText }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"setStyle", SetStyle }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperUITextBlock::New(const v8::FunctionCallbackInfo& info) +void* WrapperUITextBlock::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - UITextBlock* self = new UITextBlock(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperUIElement::dtor); + return new UITextBlock; } - void WrapperUITextBlock::GetText(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); @@ -97,3 +89,4 @@ void WrapperUITextBlock::SetStyle(const v8::FunctionCallbackInfo& inf self->appearance_changed = true; } + diff --git a/Three.V8/gui/WrapperUITextBlock.h b/Three.V8/gui/WrapperUITextBlock.h new file mode 100644 index 00000000..81ed859a --- /dev/null +++ b/Three.V8/gui/WrapperUITextBlock.h @@ -0,0 +1,15 @@ +#include "definitions.hpp" + +class WrapperUITextBlock +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetText(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetText(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void SetStyle(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/lights/AmbientLight.hpp b/Three.V8/lights/AmbientLight.hpp deleted file mode 100644 index eaf5065e..00000000 --- a/Three.V8/lights/AmbientLight.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include "IndirectLight.hpp" -#include - - -class WrapperAmbientLight -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetColor(const v8::FunctionCallbackInfo& info); - static void SetColor(const v8::FunctionCallbackInfo& info); - - static void GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; - -v8::Local WrapperAmbientLight::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperIndirectLight::create_template(isolate, constructor); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "color").ToLocalChecked(), GetColor, 0); - templ->InstanceTemplate()->Set(isolate, "getColor", v8::FunctionTemplate::New(isolate, GetColor)); - templ->InstanceTemplate()->Set(isolate, "setColor", v8::FunctionTemplate::New(isolate, SetColor)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "intensity").ToLocalChecked(), GetIntensity, SetIntensity); - - return templ; -} - -void WrapperAmbientLight::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - AmbientLight* self = new AmbientLight(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperIndirectLight::dtor); -} - -void WrapperAmbientLight::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - AmbientLight* self = lctx.self(); - v8::Local color = v8::Object::New(lctx.isolate); - lctx.vec3_to_jvec3(self->color, color); - info.GetReturnValue().Set(color); -} - -void WrapperAmbientLight::GetColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - AmbientLight* self = lctx.self(); - lctx.vec3_to_jvec3(self->color, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperAmbientLight::SetColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - AmbientLight* self = lctx.self(); - if (info[0]->IsNumber()) - { - lctx.jnum_to_num(info[0], self->color.x); - lctx.jnum_to_num(info[1], self->color.y); - lctx.jnum_to_num(info[2], self->color.z); - } - else - { - lctx.jvec3_to_vec3(info[0], self->color); - } -} - -void WrapperAmbientLight::GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - AmbientLight* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->intensity)); -} - -void WrapperAmbientLight::SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - AmbientLight* self = lctx.self(); - lctx.jnum_to_num(value, self->intensity); -} - diff --git a/Three.V8/lights/WrapperAmbientLight.cpp b/Three.V8/lights/WrapperAmbientLight.cpp new file mode 100644 index 00000000..4e12141e --- /dev/null +++ b/Three.V8/lights/WrapperAmbientLight.cpp @@ -0,0 +1,78 @@ +#include "WrapperUtils.hpp" +#include "WrapperIndirectLight.h" +#include + +#include "WrapperAmbientLight.h" + +void WrapperAmbientLight::define(ClassDefinition& cls) +{ + WrapperIndirectLight::define(cls); + cls.name = "AmbientLight"; + cls.ctor = ctor; + + std::vector props = { + { "color", GetColor }, + { "intensity", GetIntensity, SetIntensity }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getColor", GetColor }, + {"setColor", SetColor }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); + +} + +void* WrapperAmbientLight::ctor(const v8::FunctionCallbackInfo& info) +{ + return new AmbientLight; +} + +void WrapperAmbientLight::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + AmbientLight* self = lctx.self(); + v8::Local color = v8::Object::New(lctx.isolate); + lctx.vec3_to_jvec3(self->color, color); + info.GetReturnValue().Set(color); +} + +void WrapperAmbientLight::GetColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + AmbientLight* self = lctx.self(); + lctx.vec3_to_jvec3(self->color, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperAmbientLight::SetColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + AmbientLight* self = lctx.self(); + if (info[0]->IsNumber()) + { + lctx.jnum_to_num(info[0], self->color.x); + lctx.jnum_to_num(info[1], self->color.y); + lctx.jnum_to_num(info[2], self->color.z); + } + else + { + lctx.jvec3_to_vec3(info[0], self->color); + } +} + +void WrapperAmbientLight::GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + AmbientLight* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->intensity)); +} + +void WrapperAmbientLight::SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + AmbientLight* self = lctx.self(); + lctx.jnum_to_num(value, self->intensity); +} + diff --git a/Three.V8/lights/WrapperAmbientLight.h b/Three.V8/lights/WrapperAmbientLight.h new file mode 100644 index 00000000..769b6c7a --- /dev/null +++ b/Three.V8/lights/WrapperAmbientLight.h @@ -0,0 +1,21 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperAmbientLight +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetColor(const v8::FunctionCallbackInfo& info); + static void SetColor(const v8::FunctionCallbackInfo& info); + + static void GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; + diff --git a/Three.V8/lights/DirectionalLight.hpp b/Three.V8/lights/WrapperDirectionalLight.cpp similarity index 61% rename from Three.V8/lights/DirectionalLight.hpp rename to Three.V8/lights/WrapperDirectionalLight.cpp index 21d4b189..ed4885d5 100644 --- a/Three.V8/lights/DirectionalLight.hpp +++ b/Three.V8/lights/WrapperDirectionalLight.cpp @@ -1,57 +1,39 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "lights/Light.hpp" +#include "lights/WrapperLight.h" #include #include #include -class WrapperDirectionalLight -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetTarget(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetTarget(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void SetShadow(const v8::FunctionCallbackInfo& info); - static void SetShadowProjection(const v8::FunctionCallbackInfo& info); - static void SetShadowRadius(const v8::FunctionCallbackInfo& info); - - static void GetBias(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetBias(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetForceCull(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetForceCull(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetBoundingBox(const v8::FunctionCallbackInfo& info); -}; - +#include "WrapperDirectionalLight.h" -v8::Local WrapperDirectionalLight::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperDirectionalLight::define(ClassDefinition& cls) { - v8::Local templ = WrapperLight::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "target").ToLocalChecked(), GetTarget, SetTarget); - templ->InstanceTemplate()->Set(isolate, "setShadow", v8::FunctionTemplate::New(isolate, SetShadow)); - templ->InstanceTemplate()->Set(isolate, "setShadowProjection", v8::FunctionTemplate::New(isolate, SetShadowProjection)); - templ->InstanceTemplate()->Set(isolate, "setShadowRadius", v8::FunctionTemplate::New(isolate, SetShadowRadius)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "bias").ToLocalChecked(), GetBias, SetBias); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "forceCull").ToLocalChecked(), GetForceCull, SetForceCull); - - templ->InstanceTemplate()->Set(isolate, "getBoundingBox", v8::FunctionTemplate::New(isolate, GetBoundingBox)); - return templ; + WrapperLight::define(cls); + cls.name = "DirectionalLight"; + cls.ctor = ctor; + + std::vector props = { + { "target", GetTarget, SetTarget }, + { "bias", GetBias, SetBias }, + { "forceCull", GetForceCull, SetForceCull }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"setShadow", SetShadow }, + {"setShadowProjection", SetShadowProjection }, + {"setShadowRadius", SetShadowRadius }, + {"getBoundingBox", GetBoundingBox }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperDirectionalLight::New(const v8::FunctionCallbackInfo& info) + +void* WrapperDirectionalLight::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - DirectionalLight* self = new DirectionalLight(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new DirectionalLight; } - void WrapperDirectionalLight::GetTarget(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); @@ -78,9 +60,9 @@ void WrapperDirectionalLight::SetTarget(v8::Local property, v8::Loca Object3D* target = lctx.jobj_to_obj(value); self->target = target; } - + v8::Local holder = info.Holder(); - lctx.set_property(holder, "_target", value); + lctx.set_property(holder, "_target", value); } void WrapperDirectionalLight::SetShadow(const v8::FunctionCallbackInfo& info) @@ -122,7 +104,7 @@ void WrapperDirectionalLight::SetShadowRadius(const v8::FunctionCallbackInfo(); float radius; - lctx.jnum_to_num(info[0], radius); + lctx.jnum_to_num(info[0], radius); self->SetShadowRadius(radius); } @@ -182,10 +164,10 @@ void WrapperDirectionalLight::GetBoundingBox(const v8::FunctionCallbackInfo(); Scene* scene = lctx.jobj_to_obj(info[0]); - + self->lookAtTarget(); self->updateWorldMatrix(false, false); - glm::mat4 view_matrix = glm::inverse(self->matrixWorld); + glm::mat4 view_matrix = glm::inverse(self->matrixWorld); glm::vec3 min_pos, max_pos; scene->get_bounding_box(min_pos, max_pos, view_matrix); @@ -199,3 +181,4 @@ void WrapperDirectionalLight::GetBoundingBox(const v8::FunctionCallbackInfo& info); + + static void GetTarget(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetTarget(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void SetShadow(const v8::FunctionCallbackInfo& info); + static void SetShadowProjection(const v8::FunctionCallbackInfo& info); + static void SetShadowRadius(const v8::FunctionCallbackInfo& info); + + static void GetBias(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetBias(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetForceCull(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetForceCull(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetBoundingBox(const v8::FunctionCallbackInfo& info); +}; + + diff --git a/Three.V8/lights/EnvironmentMap.hpp b/Three.V8/lights/WrapperEnvironmentMap.cpp similarity index 53% rename from Three.V8/lights/EnvironmentMap.hpp rename to Three.V8/lights/WrapperEnvironmentMap.cpp index 34bf262e..e5f4d092 100644 --- a/Three.V8/lights/EnvironmentMap.hpp +++ b/Three.V8/lights/WrapperEnvironmentMap.cpp @@ -1,33 +1,24 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "IndirectLight.hpp" +#include "WrapperIndirectLight.h" #include +#include "WrapperEnvironmentMap.h" -class WrapperEnvironmentMap +void WrapperEnvironmentMap::define(ClassDefinition& cls) { -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); + WrapperIndirectLight::define(cls); + cls.name = "EnvironmentMap"; + cls.ctor = ctor; -private: - static void GetSHCoefficients(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSHCoefficients(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; + std::vector props = { + { "shCoefficients", GetSHCoefficients, SetSHCoefficients }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); -v8::Local WrapperEnvironmentMap::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperIndirectLight::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "shCoefficients").ToLocalChecked(), GetSHCoefficients, SetSHCoefficients); - return templ; } -void WrapperEnvironmentMap::New(const v8::FunctionCallbackInfo& info) +void* WrapperEnvironmentMap::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - EnvironmentMap* self = new EnvironmentMap(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperIndirectLight::dtor); + return new EnvironmentMap; } void WrapperEnvironmentMap::GetSHCoefficients(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -61,4 +52,5 @@ void WrapperEnvironmentMap::SetSHCoefficients(v8::Local property, v8 lctx.jnum_to_num(coef->Get(lctx.context, 1).ToLocalChecked(), col.y); lctx.jnum_to_num(coef->Get(lctx.context, 2).ToLocalChecked(), col.z); } -} \ No newline at end of file +} + diff --git a/Three.V8/lights/WrapperEnvironmentMap.h b/Three.V8/lights/WrapperEnvironmentMap.h new file mode 100644 index 00000000..fa92e510 --- /dev/null +++ b/Three.V8/lights/WrapperEnvironmentMap.h @@ -0,0 +1,16 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperEnvironmentMap +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetSHCoefficients(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSHCoefficients(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; + diff --git a/Three.V8/lights/EnvironmentMapCreator.hpp b/Three.V8/lights/WrapperEnvironmentMapCreator.cpp similarity index 55% rename from Three.V8/lights/EnvironmentMapCreator.hpp rename to Three.V8/lights/WrapperEnvironmentMapCreator.cpp index c8fd2ee0..14ae136a 100644 --- a/Three.V8/lights/EnvironmentMapCreator.hpp +++ b/Three.V8/lights/WrapperEnvironmentMapCreator.cpp @@ -1,54 +1,37 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include #include +#include "WrapperEnvironmentMapCreator.h" -class WrapperEnvironmentMapCreator -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void Create(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperEnvironmentMapCreator::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperEnvironmentMapCreator::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "create", v8::FunctionTemplate::New(isolate, Create)); - return templ; + cls.name = "EnvironmentMapCreator"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"create", Create }, + }; } - -void WrapperEnvironmentMapCreator::dtor(void* ptr, GameContext* ctx) +void* WrapperEnvironmentMapCreator::ctor(const v8::FunctionCallbackInfo& info) { - delete (EnvironmentMapCreator*)ptr; + return new EnvironmentMapCreator; } -void WrapperEnvironmentMapCreator::New(const v8::FunctionCallbackInfo& info) +void WrapperEnvironmentMapCreator::dtor(void* ptr, GameContext* ctx) { - LocalContext lctx(info); - EnvironmentMapCreator* self = new EnvironmentMapCreator(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + delete (EnvironmentMapCreator*)ptr; } - void WrapperEnvironmentMapCreator::Create(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); EnvironmentMapCreator* creator = lctx.self(); v8::Local holder = lctx.instantiate("EnvironmentMap"); - EnvironmentMap* self = lctx.jobj_to_obj(holder); + EnvironmentMap* self = lctx.jobj_to_obj(holder); v8::Local holder_image = info[0].As(); @@ -57,7 +40,7 @@ void WrapperEnvironmentMapCreator::Create(const v8::FunctionCallbackInfo()->Value(); } - + std::string clsname = lctx.jstr_to_str(holder_image->GetConstructorName()); if (clsname == "CubeImage") { @@ -76,7 +59,7 @@ void WrapperEnvironmentMapCreator::Create(const v8::FunctionCallbackInfo(holder_image); + CubeRenderTarget* target = lctx.jobj_to_obj(holder_image); creator->Create(target, self, irradiance_only); } diff --git a/Three.V8/lights/WrapperEnvironmentMapCreator.h b/Three.V8/lights/WrapperEnvironmentMapCreator.h new file mode 100644 index 00000000..0a698d97 --- /dev/null +++ b/Three.V8/lights/WrapperEnvironmentMapCreator.h @@ -0,0 +1,18 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperEnvironmentMapCreator +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void Create(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/lights/HemisphereLight.hpp b/Three.V8/lights/WrapperHemisphereLight.cpp similarity index 53% rename from Three.V8/lights/HemisphereLight.hpp rename to Three.V8/lights/WrapperHemisphereLight.cpp index c948953c..c471ff88 100644 --- a/Three.V8/lights/HemisphereLight.hpp +++ b/Three.V8/lights/WrapperHemisphereLight.cpp @@ -1,52 +1,36 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "IndirectLight.hpp" +#include "WrapperIndirectLight.h" #include -class WrapperHemisphereLight -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSkyColor(const v8::FunctionCallbackInfo& info); - static void SetSkyColor(const v8::FunctionCallbackInfo& info); - - static void GetGroundColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetGroundColor(const v8::FunctionCallbackInfo& info); - static void SetGroundColor(const v8::FunctionCallbackInfo& info); - - static void GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +#include "WrapperHemisphereLight.h" -}; -v8::Local WrapperHemisphereLight::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperHemisphereLight::define(ClassDefinition& cls) { - v8::Local templ = WrapperIndirectLight::create_template(isolate, constructor); + WrapperIndirectLight::define(cls); + cls.name = "HemisphereLight"; + cls.ctor = ctor; + + std::vector props = { + { "skyColor", GetSkyColor }, + { "groundColor", GetGroundColor }, + { "intensity", GetIntensity, SetIntensity }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getSkyColor", GetSkyColor }, + {"setSkyColor", SetSkyColor }, + {"getGroundColor", GetGroundColor }, + {"setGroundColor", SetGroundColor }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "skyColor").ToLocalChecked(), GetSkyColor, 0); - templ->InstanceTemplate()->Set(isolate, "getSkyColor", v8::FunctionTemplate::New(isolate, GetSkyColor)); - templ->InstanceTemplate()->Set(isolate, "setSkyColor", v8::FunctionTemplate::New(isolate, SetSkyColor)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "groundColor").ToLocalChecked(), GetGroundColor, 0); - templ->InstanceTemplate()->Set(isolate, "getGroundColor", v8::FunctionTemplate::New(isolate, GetGroundColor)); - templ->InstanceTemplate()->Set(isolate, "setGroundColor", v8::FunctionTemplate::New(isolate, SetGroundColor)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "intensity").ToLocalChecked(), GetIntensity, SetIntensity); - - return templ; } -void WrapperHemisphereLight::New(const v8::FunctionCallbackInfo& info) +void* WrapperHemisphereLight::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - HemisphereLight* self = new HemisphereLight(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperIndirectLight::dtor); + return new HemisphereLight; } void WrapperHemisphereLight::GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info) diff --git a/Three.V8/lights/WrapperHemisphereLight.h b/Three.V8/lights/WrapperHemisphereLight.h new file mode 100644 index 00000000..dc10c2f0 --- /dev/null +++ b/Three.V8/lights/WrapperHemisphereLight.h @@ -0,0 +1,26 @@ +#pragma once + +#include "definitions.hpp" + + +class WrapperHemisphereLight +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetSkyColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSkyColor(const v8::FunctionCallbackInfo& info); + static void SetSkyColor(const v8::FunctionCallbackInfo& info); + + static void GetGroundColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetGroundColor(const v8::FunctionCallbackInfo& info); + static void SetGroundColor(const v8::FunctionCallbackInfo& info); + + static void GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; + diff --git a/Three.V8/lights/IndirectLight.hpp b/Three.V8/lights/WrapperIndirectLight.cpp similarity index 55% rename from Three.V8/lights/IndirectLight.hpp rename to Three.V8/lights/WrapperIndirectLight.cpp index 41a47e24..7e36b441 100644 --- a/Three.V8/lights/IndirectLight.hpp +++ b/Three.V8/lights/WrapperIndirectLight.cpp @@ -1,54 +1,22 @@ -#pragma once - #include "WrapperUtils.hpp" #include - - -class WrapperIndirectLight -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetDiffuseThresh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDiffuseThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetDiffuseHigh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDiffuseHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetDiffuseLow(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDiffuseLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetSpecularThresh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSpecularThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetSpecularHigh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSpecularHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetSpecularLow(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSpecularLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetDynamicMap(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDynamicMap(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; - -v8::Local WrapperIndirectLight::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "diffuseThresh").ToLocalChecked(), GetDiffuseThresh, SetDiffuseThresh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "diffuseHigh").ToLocalChecked(), GetDiffuseHigh, SetDiffuseHigh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "diffuseLow").ToLocalChecked(), GetDiffuseLow, SetDiffuseLow); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "specularThresh").ToLocalChecked(), GetSpecularThresh, SetSpecularThresh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "specularHigh").ToLocalChecked(), GetSpecularHigh, SetSpecularHigh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "specularLow").ToLocalChecked(), GetSpecularLow, SetSpecularLow); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "dynamicMap").ToLocalChecked(), GetDynamicMap, SetDynamicMap); - return templ; +#include "WrapperIndirectLight.h" + +void WrapperIndirectLight::define(ClassDefinition& cls) +{ + cls.name = "IndirectLight"; + cls.dtor = dtor; + cls.properties = { + { "diffuseThresh", GetDiffuseThresh, SetDiffuseThresh }, + { "diffuseHigh", GetDiffuseHigh, SetDiffuseHigh }, + { "diffuseLow", GetDiffuseLow, SetDiffuseLow }, + { "specularThresh", GetSpecularThresh, SetSpecularThresh }, + { "specularHigh", GetSpecularHigh, SetSpecularHigh }, + { "specularLow", GetSpecularLow, SetSpecularLow }, + { "dynamicMap", GetDynamicMap, SetDynamicMap }, + }; } - void WrapperIndirectLight::dtor(void* ptr, GameContext* ctx) { delete (IndirectLight*)ptr; diff --git a/Three.V8/lights/WrapperIndirectLight.h b/Three.V8/lights/WrapperIndirectLight.h new file mode 100644 index 00000000..8f9baaa9 --- /dev/null +++ b/Three.V8/lights/WrapperIndirectLight.h @@ -0,0 +1,35 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperIndirectLight +{ +public: + static void define(ClassDefinition& cls); + +private: + static void dtor(void* ptr, GameContext* ctx); + + static void GetDiffuseThresh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDiffuseThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetDiffuseHigh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDiffuseHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetDiffuseLow(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDiffuseLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetSpecularThresh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSpecularThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetSpecularHigh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSpecularHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetSpecularLow(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSpecularLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetDynamicMap(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDynamicMap(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/lights/LODProbeGrid.hpp b/Three.V8/lights/WrapperLODProbeGrid.cpp similarity index 56% rename from Three.V8/lights/LODProbeGrid.hpp rename to Three.V8/lights/WrapperLODProbeGrid.cpp index 729a732e..ea790faa 100644 --- a/Three.V8/lights/LODProbeGrid.hpp +++ b/Three.V8/lights/WrapperLODProbeGrid.cpp @@ -1,82 +1,44 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "IndirectLight.hpp" +#include "WrapperIndirectLight.h" #include -class WrapperLODProbeGrid -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - - static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMin(const v8::FunctionCallbackInfo& info); - static void SetCoverageMin(const v8::FunctionCallbackInfo& info); - - static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMax(const v8::FunctionCallbackInfo& info); - static void SetCoverageMax(const v8::FunctionCallbackInfo& info); - - static void GetBaseDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetBaseDivisions(const v8::FunctionCallbackInfo& info); - static void SetBaseDivisions(const v8::FunctionCallbackInfo& info); - - static void GetSubDivisionLevel(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSubDivisionLevel(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetNumberOfProbes(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void GetNormalBias(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetNormalBias(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetPerPrimitive(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetPerPrimitive(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void Initialize(const v8::FunctionCallbackInfo& info); - static void ConstructVisibility(const v8::FunctionCallbackInfo& info); +#include "WrapperLODProbeGrid.h" - static void ToProbeGrid(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperLODProbeGrid::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperLODProbeGrid::define(ClassDefinition& cls) { - v8::Local templ = WrapperIndirectLight::create_template(isolate, constructor); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMin").ToLocalChecked(), GetCoverageMin, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMin", v8::FunctionTemplate::New(isolate, GetCoverageMin)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMin", v8::FunctionTemplate::New(isolate, SetCoverageMin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMax").ToLocalChecked(), GetCoverageMax, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMax", v8::FunctionTemplate::New(isolate, GetCoverageMax)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMax", v8::FunctionTemplate::New(isolate, SetCoverageMax)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "baseDivisions").ToLocalChecked(), GetBaseDivisions, 0); - templ->InstanceTemplate()->Set(isolate, "getBaseDivisions", v8::FunctionTemplate::New(isolate, GetBaseDivisions)); - templ->InstanceTemplate()->Set(isolate, "setBaseDivisions", v8::FunctionTemplate::New(isolate, SetBaseDivisions)); + WrapperIndirectLight::define(cls); + cls.name = "LODProbeGrid"; + cls.ctor = ctor; - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "subDivisionLevel").ToLocalChecked(), GetSubDivisionLevel, SetSubDivisionLevel); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "numberOfProbes").ToLocalChecked(), GetNumberOfProbes, 0); + std::vector props = { + { "coverageMin", GetCoverageMin }, + { "coverageMax", GetCoverageMax }, + { "baseDivisions", GetBaseDivisions }, + { "subDivisionLevel", GetSubDivisionLevel, SetSubDivisionLevel }, + { "numberOfProbes", GetNumberOfProbes }, + { "normalBias", GetNormalBias, SetNormalBias }, + { "perPrimitive", GetPerPrimitive, SetPerPrimitive }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "normalBias").ToLocalChecked(), GetNormalBias, SetNormalBias); + std::vector methods = { + {"getCoverageMin", GetCoverageMin }, + {"setCoverageMin", SetCoverageMin }, + {"getCoverageMax", GetCoverageMax }, + {"setCoverageMax", SetCoverageMax }, + {"getBaseDivisions", GetBaseDivisions }, + {"setBaseDivisions", SetBaseDivisions }, + {"initialize", Initialize }, + {"constructVisibility", ConstructVisibility }, + {"toProbeGrid", ToProbeGrid }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "perPrimitive").ToLocalChecked(), GetPerPrimitive, SetPerPrimitive); - - templ->InstanceTemplate()->Set(isolate, "initialize", v8::FunctionTemplate::New(isolate, Initialize)); - templ->InstanceTemplate()->Set(isolate, "constructVisibility", v8::FunctionTemplate::New(isolate, ConstructVisibility)); - - templ->InstanceTemplate()->Set(isolate, "toProbeGrid", v8::FunctionTemplate::New(isolate, ToProbeGrid)); - - return templ; } -void WrapperLODProbeGrid::New(const v8::FunctionCallbackInfo& info) +void* WrapperLODProbeGrid::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - LODProbeGrid* self = new LODProbeGrid(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperIndirectLight::dtor); + return new LODProbeGrid; } void WrapperLODProbeGrid::GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -185,7 +147,7 @@ void WrapperLODProbeGrid::Initialize(const v8::FunctionCallbackInfo& { LocalContext lctx(info); LODProbeGrid* self = lctx.self(); - GLRenderer *renderer = lctx.jobj_to_obj(info[0]); + GLRenderer* renderer = lctx.jobj_to_obj(info[0]); Scene* scene = lctx.jobj_to_obj(info[1]); self->initialize(*renderer, *scene); @@ -264,3 +226,4 @@ void WrapperLODProbeGrid::ToProbeGrid(const v8::FunctionCallbackInfo& self->ToProbeGrid(grid_out, *scene); info.GetReturnValue().Set(holder_out); } + diff --git a/Three.V8/lights/WrapperLODProbeGrid.h b/Three.V8/lights/WrapperLODProbeGrid.h new file mode 100644 index 00000000..dfe97c0f --- /dev/null +++ b/Three.V8/lights/WrapperLODProbeGrid.h @@ -0,0 +1,41 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperLODProbeGrid +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMin(const v8::FunctionCallbackInfo& info); + static void SetCoverageMin(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMax(const v8::FunctionCallbackInfo& info); + static void SetCoverageMax(const v8::FunctionCallbackInfo& info); + + static void GetBaseDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetBaseDivisions(const v8::FunctionCallbackInfo& info); + static void SetBaseDivisions(const v8::FunctionCallbackInfo& info); + + static void GetSubDivisionLevel(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSubDivisionLevel(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetNumberOfProbes(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void GetNormalBias(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetNormalBias(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetPerPrimitive(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetPerPrimitive(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void Initialize(const v8::FunctionCallbackInfo& info); + static void ConstructVisibility(const v8::FunctionCallbackInfo& info); + + static void ToProbeGrid(const v8::FunctionCallbackInfo& info); + +}; diff --git a/Three.V8/lights/LODProbeGridWidget.hpp b/Three.V8/lights/WrapperLODProbeGridWidget.cpp similarity index 56% rename from Three.V8/lights/LODProbeGridWidget.hpp rename to Three.V8/lights/WrapperLODProbeGridWidget.cpp index 4d0a8bb2..56e3f9a1 100644 --- a/Three.V8/lights/LODProbeGridWidget.hpp +++ b/Three.V8/lights/WrapperLODProbeGridWidget.cpp @@ -1,60 +1,37 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include -class WrapperLODProbeGridWidget -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMin(const v8::FunctionCallbackInfo& info); - static void SetCoverageMin(const v8::FunctionCallbackInfo& info); - - static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMax(const v8::FunctionCallbackInfo& info); - static void SetCoverageMax(const v8::FunctionCallbackInfo& info); - - static void GetBaseDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetBaseDivisions(const v8::FunctionCallbackInfo& info); - static void SetBaseDivisions(const v8::FunctionCallbackInfo& info); - - static void GetProbeGrid(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetProbeGrid(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; - +#include "WrapperLODProbeGridWidget.h" -v8::Local WrapperLODProbeGridWidget::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperLODProbeGridWidget::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMin").ToLocalChecked(), GetCoverageMin, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMin", v8::FunctionTemplate::New(isolate, GetCoverageMin)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMin", v8::FunctionTemplate::New(isolate, SetCoverageMin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMax").ToLocalChecked(), GetCoverageMax, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMax", v8::FunctionTemplate::New(isolate, GetCoverageMax)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMax", v8::FunctionTemplate::New(isolate, SetCoverageMax)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "baseDivisions").ToLocalChecked(), GetBaseDivisions, 0); - templ->InstanceTemplate()->Set(isolate, "getBaseDivisions", v8::FunctionTemplate::New(isolate, GetBaseDivisions)); - templ->InstanceTemplate()->Set(isolate, "setBaseDivisions", v8::FunctionTemplate::New(isolate, SetBaseDivisions)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "probeGrid").ToLocalChecked(), GetProbeGrid, SetProbeGrid); - - return templ; + WrapperObject3D::define(cls); + cls.name = "LODProbeGridWidget"; + cls.ctor = ctor; + + std::vector props = { + { "coverageMin", GetCoverageMin }, + { "coverageMax", GetCoverageMin }, + { "baseDivisions", GetBaseDivisions }, + { "probeGrid", GetProbeGrid, SetProbeGrid }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getCoverageMin", GetCoverageMin }, + {"setCoverageMin", SetCoverageMin }, + {"getCoverageMax", GetCoverageMax }, + {"setCoverageMax", SetCoverageMax }, + {"getBaseDivisions", GetBaseDivisions }, + {"setBaseDivisions", SetBaseDivisions }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } - -void WrapperLODProbeGridWidget::New(const v8::FunctionCallbackInfo& info) +void* WrapperLODProbeGridWidget::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - LODProbeGridWidget* self = new LODProbeGridWidget(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new LODProbeGridWidget; } void WrapperLODProbeGridWidget::GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info) diff --git a/Three.V8/lights/WrapperLODProbeGridWidget.h b/Three.V8/lights/WrapperLODProbeGridWidget.h new file mode 100644 index 00000000..cc8f0f25 --- /dev/null +++ b/Three.V8/lights/WrapperLODProbeGridWidget.h @@ -0,0 +1,29 @@ +#pragma once + +#include "definitions.hpp" + + +class WrapperLODProbeGridWidget +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMin(const v8::FunctionCallbackInfo& info); + static void SetCoverageMin(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMax(const v8::FunctionCallbackInfo& info); + static void SetCoverageMax(const v8::FunctionCallbackInfo& info); + + static void GetBaseDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetBaseDivisions(const v8::FunctionCallbackInfo& info); + static void SetBaseDivisions(const v8::FunctionCallbackInfo& info); + + static void GetProbeGrid(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetProbeGrid(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; + diff --git a/Three.V8/lights/Light.hpp b/Three.V8/lights/WrapperLight.cpp similarity index 53% rename from Three.V8/lights/Light.hpp rename to Three.V8/lights/WrapperLight.cpp index 8742436b..b6064c4d 100644 --- a/Three.V8/lights/Light.hpp +++ b/Three.V8/lights/WrapperLight.cpp @@ -1,63 +1,38 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include +#include "WrapperLight.h" -class WrapperLight -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor); - -private: - static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetColor(const v8::FunctionCallbackInfo& info); - static void SetColor(const v8::FunctionCallbackInfo& info); - - static void GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetDiffuseThresh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDiffuseThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetDiffuseHigh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDiffuseHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetDiffuseLow(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDiffuseLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetSpecularThresh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSpecularThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetSpecularHigh(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSpecularHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetSpecularLow(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetSpecularLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; +void WrapperLight::define(ClassDefinition& cls) +{ + WrapperObject3D::define(cls); + cls.name = "Light"; + std::vector props = { + { "color", GetColor }, + { "intensity", GetIntensity, SetIntensity }, + { "diffuseThresh", GetDiffuseThresh, SetDiffuseThresh }, + { "diffuseHigh", GetDiffuseHigh, SetDiffuseHigh }, + { "diffuseLow", GetDiffuseLow, SetDiffuseLow }, + { "specularThresh", GetSpecularThresh, SetSpecularThresh }, + { "specularHigh", GetSpecularHigh, SetSpecularHigh }, + { "specularLow", GetSpecularLow, SetSpecularLow }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); -v8::Local WrapperLight::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "color").ToLocalChecked(), GetColor, 0); - templ->InstanceTemplate()->Set(isolate, "getColor", v8::FunctionTemplate::New(isolate, GetColor)); - templ->InstanceTemplate()->Set(isolate, "setColor", v8::FunctionTemplate::New(isolate, SetColor)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "intensity").ToLocalChecked(), GetIntensity, SetIntensity); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "diffuseThresh").ToLocalChecked(), GetDiffuseThresh, SetDiffuseThresh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "diffuseHigh").ToLocalChecked(), GetDiffuseHigh, SetDiffuseHigh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "diffuseLow").ToLocalChecked(), GetDiffuseLow, SetDiffuseLow); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "specularThresh").ToLocalChecked(), GetSpecularThresh, SetSpecularThresh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "specularHigh").ToLocalChecked(), GetSpecularHigh, SetSpecularHigh); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "specularLow").ToLocalChecked(), GetSpecularLow, SetSpecularLow); - return templ; + std::vector methods = { + {"getColor", GetColor }, + {"setColor", SetColor }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } void WrapperLight::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - Light* self = lctx.self(); + Light* self = lctx.self(); v8::Local color = v8::Object::New(lctx.isolate); lctx.vec3_to_jvec3(self->color, color); info.GetReturnValue().Set(color); @@ -66,7 +41,7 @@ void WrapperLight::GetColor(v8::Local property, const v8::PropertyCa void WrapperLight::GetColor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Light* self = lctx.self(); + Light* self = lctx.self(); lctx.vec3_to_jvec3(self->color, info[0]); info.GetReturnValue().Set(info[0]); } @@ -90,7 +65,7 @@ void WrapperLight::SetColor(const v8::FunctionCallbackInfo& info) void WrapperLight::GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - Light* self = lctx.self(); + Light* self = lctx.self(); info.GetReturnValue().Set(lctx.num_to_jnum(self->intensity)); } @@ -186,3 +161,4 @@ void WrapperLight::SetSpecularLow(v8::Local property, v8::Local(); lctx.jnum_to_num(value, self->specular_low); } + diff --git a/Three.V8/lights/WrapperLight.h b/Three.V8/lights/WrapperLight.h new file mode 100644 index 00000000..f8e25a57 --- /dev/null +++ b/Three.V8/lights/WrapperLight.h @@ -0,0 +1,35 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperLight +{ +public: + static void define(ClassDefinition& cls); + +private: + static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetColor(const v8::FunctionCallbackInfo& info); + static void SetColor(const v8::FunctionCallbackInfo& info); + + static void GetIntensity(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetIntensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetDiffuseThresh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDiffuseThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetDiffuseHigh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDiffuseHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetDiffuseLow(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDiffuseLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetSpecularThresh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSpecularThresh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetSpecularHigh(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSpecularHigh(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetSpecularLow(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetSpecularLow(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/lights/ProbeGrid.hpp b/Three.V8/lights/WrapperProbeGrid.cpp similarity index 56% rename from Three.V8/lights/ProbeGrid.hpp rename to Three.V8/lights/WrapperProbeGrid.cpp index cc36472b..287df0a8 100644 --- a/Three.V8/lights/ProbeGrid.hpp +++ b/Three.V8/lights/WrapperProbeGrid.cpp @@ -1,79 +1,43 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "IndirectLight.hpp" +#include "WrapperIndirectLight.h" #include -class WrapperProbeGrid -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - - static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMin(const v8::FunctionCallbackInfo& info); - static void SetCoverageMin(const v8::FunctionCallbackInfo& info); - - static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMax(const v8::FunctionCallbackInfo& info); - static void SetCoverageMax(const v8::FunctionCallbackInfo& info); - - static void GetDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetDivisions(const v8::FunctionCallbackInfo& info); - static void SetDivisions(const v8::FunctionCallbackInfo& info); - - static void GetYpower(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetYpower(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetNormalBias(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetNormalBias(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetPerPrimitive(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetPerPrimitive(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetRecordReferences(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetRecordReferences(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetReferences(const v8::FunctionCallbackInfo& info); +#include "WrapperProbeGrid.h" - static void ConstructVisibility(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperProbeGrid::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperProbeGrid::define(ClassDefinition& cls) { - v8::Local templ = WrapperIndirectLight::create_template(isolate, constructor); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMin").ToLocalChecked(), GetCoverageMin, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMin", v8::FunctionTemplate::New(isolate, GetCoverageMin)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMin", v8::FunctionTemplate::New(isolate, SetCoverageMin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMax").ToLocalChecked(), GetCoverageMax, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMax", v8::FunctionTemplate::New(isolate, GetCoverageMax)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMax", v8::FunctionTemplate::New(isolate, SetCoverageMax)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "divisions").ToLocalChecked(), GetDivisions, 0); - templ->InstanceTemplate()->Set(isolate, "getDivisions", v8::FunctionTemplate::New(isolate, GetDivisions)); - templ->InstanceTemplate()->Set(isolate, "setDivisions", v8::FunctionTemplate::New(isolate, SetDivisions)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "ypower").ToLocalChecked(), GetYpower, SetYpower); + WrapperIndirectLight::define(cls); + cls.name = "ProbeGrid"; + cls.ctor = ctor; - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "normalBias").ToLocalChecked(), GetNormalBias, SetNormalBias); + std::vector props = { + { "coverageMin", GetCoverageMin }, + { "coverageMax", GetCoverageMax }, + { "divisions", GetDivisions }, + { "ypower", GetYpower, SetYpower }, + { "normalBias", GetNormalBias, SetNormalBias }, + { "perPrimitive", GetPerPrimitive, SetPerPrimitive }, + { "recordReferences", GetRecordReferences, SetRecordReferences }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "perPrimitive").ToLocalChecked(), GetPerPrimitive, SetPerPrimitive); + std::vector methods = { + {"getCoverageMin", GetCoverageMin }, + {"setCoverageMin", SetCoverageMin }, + {"getCoverageMax", GetCoverageMax }, + {"setCoverageMax", SetCoverageMax }, + {"getDivisions", GetDivisions }, + {"setDivisions", SetDivisions }, + {"getReferences", GetReferences }, + {"constructVisibility", ConstructVisibility }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "recordReferences").ToLocalChecked(), GetRecordReferences, SetRecordReferences); - templ->InstanceTemplate()->Set(isolate, "getReferences", v8::FunctionTemplate::New(isolate, GetReferences)); - - templ->InstanceTemplate()->Set(isolate, "constructVisibility", v8::FunctionTemplate::New(isolate, ConstructVisibility)); - - return templ; } -void WrapperProbeGrid::New(const v8::FunctionCallbackInfo& info) +void* WrapperProbeGrid::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - ProbeGrid* self = new ProbeGrid(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperIndirectLight::dtor); + return new ProbeGrid; } void WrapperProbeGrid::GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -191,7 +155,7 @@ void WrapperProbeGrid::SetYpower(v8::Local property, v8::Local& info) { LocalContext lctx(info); - ProbeGrid* self = lctx.self(); + ProbeGrid* self = lctx.self(); lctx.jnum_to_num(value, self->ypower); } diff --git a/Three.V8/lights/WrapperProbeGrid.h b/Three.V8/lights/WrapperProbeGrid.h new file mode 100644 index 00000000..e1d3eec3 --- /dev/null +++ b/Three.V8/lights/WrapperProbeGrid.h @@ -0,0 +1,40 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperProbeGrid +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMin(const v8::FunctionCallbackInfo& info); + static void SetCoverageMin(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMax(const v8::FunctionCallbackInfo& info); + static void SetCoverageMax(const v8::FunctionCallbackInfo& info); + + static void GetDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetDivisions(const v8::FunctionCallbackInfo& info); + static void SetDivisions(const v8::FunctionCallbackInfo& info); + + static void GetYpower(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetYpower(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetNormalBias(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetNormalBias(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetPerPrimitive(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetPerPrimitive(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetRecordReferences(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetRecordReferences(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void GetReferences(const v8::FunctionCallbackInfo& info); + + static void ConstructVisibility(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/lights/ProbeGridWidget.hpp b/Three.V8/lights/WrapperProbeGridWidget.cpp similarity index 55% rename from Three.V8/lights/ProbeGridWidget.hpp rename to Three.V8/lights/WrapperProbeGridWidget.cpp index 6bc80dee..30b48bf4 100644 --- a/Three.V8/lights/ProbeGridWidget.hpp +++ b/Three.V8/lights/WrapperProbeGridWidget.cpp @@ -1,60 +1,39 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include -class WrapperProbeGridWidget -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMin(const v8::FunctionCallbackInfo& info); - static void SetCoverageMin(const v8::FunctionCallbackInfo& info); - - static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetCoverageMax(const v8::FunctionCallbackInfo& info); - static void SetCoverageMax(const v8::FunctionCallbackInfo& info); - - static void GetDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetDivisions(const v8::FunctionCallbackInfo& info); - static void SetDivisions(const v8::FunctionCallbackInfo& info); - - static void GetYpower(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetYpower(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; - +#include "WrapperProbeGridWidget.h" -v8::Local WrapperProbeGridWidget::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperProbeGridWidget::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMin").ToLocalChecked(), GetCoverageMin, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMin", v8::FunctionTemplate::New(isolate, GetCoverageMin)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMin", v8::FunctionTemplate::New(isolate, SetCoverageMin)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "coverageMax").ToLocalChecked(), GetCoverageMax, 0); - templ->InstanceTemplate()->Set(isolate, "getCoverageMax", v8::FunctionTemplate::New(isolate, GetCoverageMax)); - templ->InstanceTemplate()->Set(isolate, "setCoverageMax", v8::FunctionTemplate::New(isolate, SetCoverageMax)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "divisions").ToLocalChecked(), GetDivisions, 0); - templ->InstanceTemplate()->Set(isolate, "getDivisions", v8::FunctionTemplate::New(isolate, GetDivisions)); - templ->InstanceTemplate()->Set(isolate, "setDivisions", v8::FunctionTemplate::New(isolate, SetDivisions)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "ypower").ToLocalChecked(), GetYpower, SetYpower); - - return templ; + WrapperObject3D::define(cls); + cls.name = "ProbeGridWidget"; + cls.ctor = ctor; + + std::vector props = { + { "coverageMin", GetCoverageMin }, + { "coverageMax", GetCoverageMin }, + { "divisions", GetDivisions }, + { "ypower", GetYpower, SetYpower }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getCoverageMin", GetCoverageMin }, + {"setCoverageMin", SetCoverageMin }, + {"getCoverageMax", GetCoverageMax }, + {"setCoverageMax", SetCoverageMax }, + {"getDivisions", GetDivisions }, + {"setDivisions", SetDivisions }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperProbeGridWidget::New(const v8::FunctionCallbackInfo& info) + +void* WrapperProbeGridWidget::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - ProbeGridWidget* self = new ProbeGridWidget(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new ProbeGridWidget; } void WrapperProbeGridWidget::GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -173,3 +152,4 @@ void WrapperProbeGridWidget::SetYpower(v8::Local property, v8::Local ProbeGridWidget* self = lctx.self(); lctx.jnum_to_num(value, self->ypower); } + diff --git a/Three.V8/lights/WrapperProbeGridWidget.h b/Three.V8/lights/WrapperProbeGridWidget.h new file mode 100644 index 00000000..d17754da --- /dev/null +++ b/Three.V8/lights/WrapperProbeGridWidget.h @@ -0,0 +1,27 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperProbeGridWidget +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMin(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMin(const v8::FunctionCallbackInfo& info); + static void SetCoverageMin(const v8::FunctionCallbackInfo& info); + + static void GetCoverageMax(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetCoverageMax(const v8::FunctionCallbackInfo& info); + static void SetCoverageMax(const v8::FunctionCallbackInfo& info); + + static void GetDivisions(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetDivisions(const v8::FunctionCallbackInfo& info); + static void SetDivisions(const v8::FunctionCallbackInfo& info); + + static void GetYpower(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetYpower(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/loaders/DDSImageLoader.hpp b/Three.V8/loaders/WrapperDDSImageLoader.cpp similarity index 60% rename from Three.V8/loaders/DDSImageLoader.hpp rename to Three.V8/loaders/WrapperDDSImageLoader.cpp index 03dd00ec..fc11acb2 100644 --- a/Three.V8/loaders/DDSImageLoader.hpp +++ b/Three.V8/loaders/WrapperDDSImageLoader.cpp @@ -1,25 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include - -class WrapperDDSImageLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadFile(const v8::FunctionCallbackInfo& info); - static void LoadMemory(const v8::FunctionCallbackInfo& info); -}; +#include +#include "WrapperDDSImageLoader.h" -v8::Local WrapperDDSImageLoader::create_template(v8::Isolate* isolate) +void WrapperDDSImageLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadFile", v8::FunctionTemplate::New(isolate, LoadFile)); - templ->Set(isolate, "loadMemory", v8::FunctionTemplate::New(isolate, LoadMemory)); - return templ; + object.name = "DDSImageLoader"; + object.methods = { + { "loadFile", LoadFile}, + { "loadMemory", LoadMemory}, + }; } void WrapperDDSImageLoader::LoadFile(const v8::FunctionCallbackInfo& info) diff --git a/Three.V8/loaders/WrapperDDSImageLoader.h b/Three.V8/loaders/WrapperDDSImageLoader.h new file mode 100644 index 00000000..1ec54b15 --- /dev/null +++ b/Three.V8/loaders/WrapperDDSImageLoader.h @@ -0,0 +1,15 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperDDSImageLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadFile(const v8::FunctionCallbackInfo& info); + static void LoadMemory(const v8::FunctionCallbackInfo& info); +}; + + diff --git a/Three.V8/loaders/FileLoader.hpp b/Three.V8/loaders/WrapperFileLoader.cpp similarity index 62% rename from Three.V8/loaders/FileLoader.hpp rename to Three.V8/loaders/WrapperFileLoader.cpp index 2b776fa8..2d863739 100644 --- a/Three.V8/loaders/FileLoader.hpp +++ b/Three.V8/loaders/WrapperFileLoader.cpp @@ -1,29 +1,18 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include -class WrapperFileLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadBinaryFile(const v8::FunctionCallbackInfo& info); - static void LoadTextFile(const v8::FunctionCallbackInfo& info); - -}; +#include "WrapperFileLoader.h" -v8::Local WrapperFileLoader::create_template(v8::Isolate* isolate) +void WrapperFileLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadBinaryFile", v8::FunctionTemplate::New(isolate, LoadBinaryFile)); - templ->Set(isolate, "loadTextFile", v8::FunctionTemplate::New(isolate, LoadTextFile)); - return templ; + object.name = "fileLoader"; + object.methods = { + { "loadBinaryFile", LoadBinaryFile}, + { "loadTextFile", LoadTextFile}, + }; } - void WrapperFileLoader::LoadBinaryFile(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); @@ -41,7 +30,7 @@ void WrapperFileLoader::LoadBinaryFile(const v8::FunctionCallbackInfo v8::Local ret = v8::ArrayBuffer::New(lctx.isolate, data.size()); void* p_data = ret->GetBackingStore()->Data(); memcpy(p_data, data.data(), data.size()); - + info.GetReturnValue().Set(ret); } diff --git a/Three.V8/loaders/WrapperFileLoader.h b/Three.V8/loaders/WrapperFileLoader.h new file mode 100644 index 00000000..1564c869 --- /dev/null +++ b/Three.V8/loaders/WrapperFileLoader.h @@ -0,0 +1,16 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperFileLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadBinaryFile(const v8::FunctionCallbackInfo& info); + static void LoadTextFile(const v8::FunctionCallbackInfo& info); +}; + + + diff --git a/Three.V8/loaders/GLTFLoader.hpp b/Three.V8/loaders/WrapperGLTFLoader.cpp similarity index 68% rename from Three.V8/loaders/GLTFLoader.hpp rename to Three.V8/loaders/WrapperGLTFLoader.cpp index 7804409d..2a3a2bc2 100644 --- a/Three.V8/loaders/GLTFLoader.hpp +++ b/Three.V8/loaders/WrapperGLTFLoader.cpp @@ -1,29 +1,19 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include -class WrapperGLTFLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadModelFromFile(const v8::FunctionCallbackInfo& info); - static void LoadAnimationsFromFile(const v8::FunctionCallbackInfo& info); - static void LoadModelFromMemory(const v8::FunctionCallbackInfo& info); - static void LoadAnimationsFromMemory(const v8::FunctionCallbackInfo& info); -}; +#include "WrapperGLTFLoader.h" -v8::Local WrapperGLTFLoader::create_template(v8::Isolate* isolate) +void WrapperGLTFLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadModelFromFile", v8::FunctionTemplate::New(isolate, LoadModelFromFile)); - templ->Set(isolate, "loadAnimationsFromFile", v8::FunctionTemplate::New(isolate, LoadAnimationsFromFile)); - templ->Set(isolate, "loadModelFromMemory", v8::FunctionTemplate::New(isolate, LoadModelFromMemory)); - templ->Set(isolate, "loadAnimationsFromMemory", v8::FunctionTemplate::New(isolate, LoadAnimationsFromMemory)); - return templ; + object.name = "gltfLoader"; + object.methods = { + { "loadModelFromFile", LoadModelFromFile}, + { "loadAnimationsFromFile", LoadAnimationsFromFile}, + { "loadModelFromMemory", LoadModelFromMemory}, + { "loadAnimationsFromMemory", LoadAnimationsFromMemory}, + }; } void WrapperGLTFLoader::LoadModelFromFile(const v8::FunctionCallbackInfo& info) @@ -36,7 +26,7 @@ void WrapperGLTFLoader::LoadModelFromFile(const v8::FunctionCallbackInfo holder = lctx.instantiate("GLTFModel"); - GLTFModel* self = lctx.jobj_to_obj(holder); + GLTFModel* self = lctx.jobj_to_obj(holder); GLTFLoader::LoadModelFromFile(self, filename.c_str()); info.GetReturnValue().Set(holder); } @@ -83,9 +73,9 @@ void WrapperGLTFLoader::LoadModelFromMemory(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - + std::vector animations; - + v8::Local data = info[0].As(); GLTFLoader::LoadAnimationsFromMemory(animations, (unsigned char*)data->GetBackingStore()->Data(), data->ByteLength()); diff --git a/Three.V8/loaders/WrapperGLTFLoader.h b/Three.V8/loaders/WrapperGLTFLoader.h new file mode 100644 index 00000000..e21ab8b6 --- /dev/null +++ b/Three.V8/loaders/WrapperGLTFLoader.h @@ -0,0 +1,16 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperGLTFLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadModelFromFile(const v8::FunctionCallbackInfo& info); + static void LoadAnimationsFromFile(const v8::FunctionCallbackInfo& info); + static void LoadModelFromMemory(const v8::FunctionCallbackInfo& info); + static void LoadAnimationsFromMemory(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/loaders/HDRImageLoader.hpp b/Three.V8/loaders/WrapperHDRImageLoader.cpp similarity index 75% rename from Three.V8/loaders/HDRImageLoader.hpp rename to Three.V8/loaders/WrapperHDRImageLoader.cpp index 18142b20..00458e82 100644 --- a/Three.V8/loaders/HDRImageLoader.hpp +++ b/Three.V8/loaders/WrapperHDRImageLoader.cpp @@ -1,33 +1,20 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include +#include "WrapperHDRImageLoader.h" -class WrapperHDRImageLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadFile(const v8::FunctionCallbackInfo& info); - static void LoadMemory(const v8::FunctionCallbackInfo& info); - static void LoadCubeFromFile(const v8::FunctionCallbackInfo& info); - static void LoadCubeFromMemory(const v8::FunctionCallbackInfo& info); - static void FromImages(const v8::FunctionCallbackInfo& info); - static void FromRGBM(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperHDRImageLoader::create_template(v8::Isolate* isolate) +void WrapperHDRImageLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadFile", v8::FunctionTemplate::New(isolate, LoadFile)); - templ->Set(isolate, "loadMemory", v8::FunctionTemplate::New(isolate, LoadMemory)); - templ->Set(isolate, "loadCubeFromFile", v8::FunctionTemplate::New(isolate, LoadCubeFromFile)); - templ->Set(isolate, "loadCubeFromMemory", v8::FunctionTemplate::New(isolate, LoadCubeFromMemory)); - templ->Set(isolate, "fromImages", v8::FunctionTemplate::New(isolate, FromImages)); - templ->Set(isolate, "fromRGBM", v8::FunctionTemplate::New(isolate, FromRGBM)); - return templ; + object.name = "HDRImageLoader"; + object.methods = { + { "loadFile", LoadFile}, + { "loadMemory", LoadMemory}, + { "loadCubeFromFile", LoadCubeFromFile}, + { "loadCubeFromMemory", LoadCubeFromMemory}, + { "fromImages", FromImages}, + { "fromRGBM", FromRGBM}, + }; } void WrapperHDRImageLoader::LoadFile(const v8::FunctionCallbackInfo& info) @@ -58,7 +45,7 @@ void WrapperHDRImageLoader::LoadMemory(const v8::FunctionCallbackInfo void WrapperHDRImageLoader::LoadCubeFromFile(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); + LocalContext lctx(info); std::string filenames[6] = { lctx.jstr_to_str(info[0]), @@ -77,10 +64,10 @@ void WrapperHDRImageLoader::LoadCubeFromFile(const v8::FunctionCallbackInfo holder = lctx.instantiate("HDRCubeImage"); HDRCubeImage* self = lctx.jobj_to_obj(holder); - HDRImageLoader::LoadCubeFromFile(self, filenames[0].c_str(), filenames[1].c_str(), + HDRImageLoader::LoadCubeFromFile(self, filenames[0].c_str(), filenames[1].c_str(), filenames[2].c_str(), filenames[3].c_str(), filenames[4].c_str(), filenames[5].c_str()); info.GetReturnValue().Set(holder); @@ -102,7 +89,7 @@ void WrapperHDRImageLoader::LoadCubeFromMemory(const v8::FunctionCallbackInfoGetBackingStore()->Data(), data[0]->ByteLength(), (unsigned char*)data[1]->GetBackingStore()->Data(), data[1]->ByteLength(), (unsigned char*)data[2]->GetBackingStore()->Data(), data[2]->ByteLength(), - (unsigned char*)data[3]->GetBackingStore()->Data(), data[3]->ByteLength(), + (unsigned char*)data[3]->GetBackingStore()->Data(), data[3]->ByteLength(), (unsigned char*)data[4]->GetBackingStore()->Data(), data[4]->ByteLength(), (unsigned char*)data[5]->GetBackingStore()->Data(), data[5]->ByteLength()); @@ -129,20 +116,20 @@ void WrapperHDRImageLoader::FromImages(const v8::FunctionCallbackInfo v8::Local j_high = lctx.get_property(j_range, "high"); HDRImageLoader::Range range; lctx.jvec3_to_vec3(j_low, range.low); - lctx.jvec3_to_vec3(j_high, range.high); + lctx.jvec3_to_vec3(j_high, range.high); ranges[i] = range; } v8::Local holder = lctx.instantiate("HDRImage"); - HDRImage* self = lctx.jobj_to_obj(holder); - HDRImageLoader::FromImages(self, images.data(), ranges.data(), count); + HDRImage* self = lctx.jobj_to_obj(holder); + HDRImageLoader::FromImages(self, images.data(), ranges.data(), count); info.GetReturnValue().Set(holder); } void WrapperHDRImageLoader::FromRGBM(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - + float rate = 16.0f; if (info.Length() > 1) { @@ -155,7 +142,7 @@ void WrapperHDRImageLoader::FromRGBM(const v8::FunctionCallbackInfo& if (clsname == "Image") { Image* img = lctx.jobj_to_obj(holder_img); - + v8::Local holder = lctx.instantiate("HDRImage"); HDRImage* self = lctx.jobj_to_obj(holder); HDRImageLoader::FromRGBM(self, img, rate); @@ -171,3 +158,5 @@ void WrapperHDRImageLoader::FromRGBM(const v8::FunctionCallbackInfo& info.GetReturnValue().Set(holder); } } + + diff --git a/Three.V8/loaders/WrapperHDRImageLoader.h b/Three.V8/loaders/WrapperHDRImageLoader.h new file mode 100644 index 00000000..d3eb400e --- /dev/null +++ b/Three.V8/loaders/WrapperHDRImageLoader.h @@ -0,0 +1,17 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperHDRImageLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadFile(const v8::FunctionCallbackInfo& info); + static void LoadMemory(const v8::FunctionCallbackInfo& info); + static void LoadCubeFromFile(const v8::FunctionCallbackInfo& info); + static void LoadCubeFromMemory(const v8::FunctionCallbackInfo& info); + static void FromImages(const v8::FunctionCallbackInfo& info); + static void FromRGBM(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/loaders/ImageLoader.hpp b/Three.V8/loaders/WrapperImageLoader.cpp similarity index 67% rename from Three.V8/loaders/ImageLoader.hpp rename to Three.V8/loaders/WrapperImageLoader.cpp index d174d758..31b90552 100644 --- a/Three.V8/loaders/ImageLoader.hpp +++ b/Three.V8/loaders/WrapperImageLoader.cpp @@ -1,29 +1,17 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include +#include "WrapperImageLoader.h" -class WrapperImageLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadFile(const v8::FunctionCallbackInfo& info); - static void LoadMemory(const v8::FunctionCallbackInfo& info); - static void LoadCubeFromFile(const v8::FunctionCallbackInfo& info); - static void LoadCubeFromMemory(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperImageLoader::create_template(v8::Isolate* isolate) +void WrapperImageLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadFile", v8::FunctionTemplate::New(isolate, LoadFile)); - templ->Set(isolate, "loadMemory", v8::FunctionTemplate::New(isolate, LoadMemory)); - templ->Set(isolate, "loadCubeFromFile", v8::FunctionTemplate::New(isolate, LoadCubeFromFile)); - templ->Set(isolate, "loadCubeFromMemory", v8::FunctionTemplate::New(isolate, LoadCubeFromMemory)); - return templ; + object.name = "imageLoader"; + object.methods = { + { "loadFile", LoadFile}, + { "loadMemory", LoadMemory}, + { "loadCubeFromFile", LoadCubeFromFile}, + { "loadCubeFromMemory", LoadCubeFromMemory}, + }; } void WrapperImageLoader::LoadFile(const v8::FunctionCallbackInfo& info) @@ -36,7 +24,7 @@ void WrapperImageLoader::LoadFile(const v8::FunctionCallbackInfo& inf return; } v8::Local holder = lctx.instantiate("Image"); - Image* self = lctx.jobj_to_obj(holder); + Image* self = lctx.jobj_to_obj(holder); ImageLoader::LoadFile(self, filename.c_str()); info.GetReturnValue().Set(holder); } @@ -48,13 +36,13 @@ void WrapperImageLoader::LoadMemory(const v8::FunctionCallbackInfo& i v8::Local holder = lctx.instantiate("Image"); Image* self = lctx.jobj_to_obj(holder); v8::Local data = info[0].As(); - ImageLoader::LoadMemory(self, (unsigned char*)data->GetBackingStore()->Data(), data->ByteLength()); + ImageLoader::LoadMemory(self, (unsigned char*)data->GetBackingStore()->Data(), data->ByteLength()); info.GetReturnValue().Set(holder); } void WrapperImageLoader::LoadCubeFromFile(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); + LocalContext lctx(info); std::string filenames[6] = { lctx.jstr_to_str(info[0]), @@ -73,10 +61,10 @@ void WrapperImageLoader::LoadCubeFromFile(const v8::FunctionCallbackInfo holder = lctx.instantiate("CubeImage"); CubeImage* self = lctx.jobj_to_obj(holder); - ImageLoader::LoadCubeFromFile(self, filenames[0].c_str(), filenames[1].c_str(), + ImageLoader::LoadCubeFromFile(self, filenames[0].c_str(), filenames[1].c_str(), filenames[2].c_str(), filenames[3].c_str(), filenames[4].c_str(), filenames[5].c_str()); info.GetReturnValue().Set(holder); @@ -94,13 +82,15 @@ void WrapperImageLoader::LoadCubeFromMemory(const v8::FunctionCallbackInfo(); } - ImageLoader::LoadCubeFromMemory(self, + ImageLoader::LoadCubeFromMemory(self, (unsigned char*)data[0]->GetBackingStore()->Data(), data[0]->ByteLength(), (unsigned char*)data[1]->GetBackingStore()->Data(), data[1]->ByteLength(), (unsigned char*)data[2]->GetBackingStore()->Data(), data[2]->ByteLength(), - (unsigned char*)data[3]->GetBackingStore()->Data(), data[3]->ByteLength(), + (unsigned char*)data[3]->GetBackingStore()->Data(), data[3]->ByteLength(), (unsigned char*)data[4]->GetBackingStore()->Data(), data[4]->ByteLength(), (unsigned char*)data[5]->GetBackingStore()->Data(), data[5]->ByteLength()); info.GetReturnValue().Set(holder); } + + diff --git a/Three.V8/loaders/WrapperImageLoader.h b/Three.V8/loaders/WrapperImageLoader.h new file mode 100644 index 00000000..f0baf31f --- /dev/null +++ b/Three.V8/loaders/WrapperImageLoader.h @@ -0,0 +1,17 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperImageLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadFile(const v8::FunctionCallbackInfo& info); + static void LoadMemory(const v8::FunctionCallbackInfo& info); + static void LoadCubeFromFile(const v8::FunctionCallbackInfo& info); + static void LoadCubeFromMemory(const v8::FunctionCallbackInfo& info); +}; + + diff --git a/Three.V8/loaders/LODProbeGridLoader.hpp b/Three.V8/loaders/WrapperLODProbeGridLoader.cpp similarity index 61% rename from Three.V8/loaders/LODProbeGridLoader.hpp rename to Three.V8/loaders/WrapperLODProbeGridLoader.cpp index d81825be..e8c2037d 100644 --- a/Three.V8/loaders/LODProbeGridLoader.hpp +++ b/Three.V8/loaders/WrapperLODProbeGridLoader.cpp @@ -1,24 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include -class WrapperLODProbeGridLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadFile(const v8::FunctionCallbackInfo& info); - static void LoadMemory(const v8::FunctionCallbackInfo& info); -}; +#include "WrapperLODProbeGridLoader.h" -v8::Local WrapperLODProbeGridLoader::create_template(v8::Isolate* isolate) +void WrapperLODProbeGridLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadFile", v8::FunctionTemplate::New(isolate, LoadFile)); - templ->Set(isolate, "loadMemory", v8::FunctionTemplate::New(isolate, LoadMemory)); - return templ; + object.name = "LODProbeGridLoader"; + object.methods = { + { "loadFile", LoadFile}, + { "loadMemory", LoadMemory}, + }; } void WrapperLODProbeGridLoader::LoadFile(const v8::FunctionCallbackInfo& info) diff --git a/Three.V8/loaders/WrapperLODProbeGridLoader.h b/Three.V8/loaders/WrapperLODProbeGridLoader.h new file mode 100644 index 00000000..f54478ac --- /dev/null +++ b/Three.V8/loaders/WrapperLODProbeGridLoader.h @@ -0,0 +1,15 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperLODProbeGridLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadFile(const v8::FunctionCallbackInfo& info); + static void LoadMemory(const v8::FunctionCallbackInfo& info); +}; + + diff --git a/Three.V8/loaders/ProbeGridLoader.hpp b/Three.V8/loaders/WrapperProbeGridLoader.cpp similarity index 61% rename from Three.V8/loaders/ProbeGridLoader.hpp rename to Three.V8/loaders/WrapperProbeGridLoader.cpp index 1dbabefa..6bf52f2e 100644 --- a/Three.V8/loaders/ProbeGridLoader.hpp +++ b/Three.V8/loaders/WrapperProbeGridLoader.cpp @@ -1,26 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include +#include "WrapperProbeGridLoader.h" -class WrapperProbeGridLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadFile(const v8::FunctionCallbackInfo& info); - static void LoadMemory(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperProbeGridLoader::create_template(v8::Isolate* isolate) +void WrapperProbeGridLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadFile", v8::FunctionTemplate::New(isolate, LoadFile)); - templ->Set(isolate, "loadMemory", v8::FunctionTemplate::New(isolate, LoadMemory)); - return templ; + object.name = "probeGridLoader"; + object.methods = { + { "loadFile", LoadFile}, + { "loadMemory", LoadMemory}, + }; } void WrapperProbeGridLoader::LoadFile(const v8::FunctionCallbackInfo& info) diff --git a/Three.V8/loaders/WrapperProbeGridLoader.h b/Three.V8/loaders/WrapperProbeGridLoader.h new file mode 100644 index 00000000..2411091c --- /dev/null +++ b/Three.V8/loaders/WrapperProbeGridLoader.h @@ -0,0 +1,13 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperProbeGridLoader +{ +public: + static void define(ObjectDefinition& object); + +private: + static void LoadFile(const v8::FunctionCallbackInfo& info); + static void LoadMemory(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/models/HeightField.hpp b/Three.V8/models/HeightField.hpp deleted file mode 100644 index 75c16cc8..00000000 --- a/Three.V8/models/HeightField.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperHeightField -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void SaveFile(const v8::FunctionCallbackInfo& info); - -}; - - -v8::Local WrapperHeightField::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "saveFile", v8::FunctionTemplate::New(isolate, SaveFile)); - - return templ; -} - - -void WrapperHeightField::dtor(void* ptr, GameContext* ctx) -{ - delete (HeightField*)ptr; -} - -void WrapperHeightField::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - - glm::vec3 min_pos, max_pos; - lctx.jvec3_to_vec3(info[0], min_pos); - lctx.jvec3_to_vec3(info[1], max_pos); - int width, height; - lctx.jnum_to_num(info[2], width); - lctx.jnum_to_num(info[3], height); - - HeightField* self = new HeightField(min_pos, max_pos, width, height); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperHeightField::SaveFile(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HeightField* self = lctx.self(); - std::string fn = lctx.jstr_to_str(info[0]); - self->saveFile(fn.c_str()); -} - - diff --git a/Three.V8/models/AnimationMixer.hpp b/Three.V8/models/WrapperAnimationMixer.cpp similarity index 63% rename from Three.V8/models/AnimationMixer.hpp rename to Three.V8/models/WrapperAnimationMixer.cpp index 5ea9b121..73c6d45f 100644 --- a/Three.V8/models/AnimationMixer.hpp +++ b/Three.V8/models/WrapperAnimationMixer.cpp @@ -1,66 +1,31 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include "WrapperAnimationMixer.h" - -class WrapperAnimationMixer -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void GetAnimations(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetAnimation(const v8::FunctionCallbackInfo& info); - static void GetAnimations(const v8::FunctionCallbackInfo& info); - - static void AddAnimation(const v8::FunctionCallbackInfo& info); - static void AddAnimations(const v8::FunctionCallbackInfo& info); - - static void StartAnimation(const v8::FunctionCallbackInfo& info); - static void StopAnimation(const v8::FunctionCallbackInfo& info); - - static void GetCurrentPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetWeights(const v8::FunctionCallbackInfo& info); - - static void GetFrame(const v8::FunctionCallbackInfo& info); - -}; - -v8::Local WrapperAnimationMixer::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperAnimationMixer::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "animations").ToLocalChecked(), GetAnimations, 0); - templ->InstanceTemplate()->Set(isolate, "getAnimation", v8::FunctionTemplate::New(isolate, GetAnimation)); - templ->InstanceTemplate()->Set(isolate, "getAnimations", v8::FunctionTemplate::New(isolate, GetAnimations)); - - templ->InstanceTemplate()->Set(isolate, "addAnimation", v8::FunctionTemplate::New(isolate, AddAnimation)); - templ->InstanceTemplate()->Set(isolate, "addAnimations", v8::FunctionTemplate::New(isolate, AddAnimations)); - - templ->InstanceTemplate()->Set(isolate, "startAnimation", v8::FunctionTemplate::New(isolate, StartAnimation)); - templ->InstanceTemplate()->Set(isolate, "stopAnimation", v8::FunctionTemplate::New(isolate, StopAnimation)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "currentPlaying").ToLocalChecked(), GetCurrentPlaying, 0); - templ->InstanceTemplate()->Set(isolate, "setWeights", v8::FunctionTemplate::New(isolate, SetWeights)); - - templ->InstanceTemplate()->Set(isolate, "getFrame", v8::FunctionTemplate::New(isolate, GetFrame)); - - return templ; + cls.name = "AnimationMixer"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "animations", GetAnimations }, + { "currentPlaying", GetCurrentPlaying }, + }; + cls.methods = { + {"getAnimation", GetAnimation }, + {"getAnimations", GetAnimations }, + {"addAnimation", AddAnimation }, + {"addAnimations", AddAnimations }, + {"startAnimation", StartAnimation }, + {"stopAnimation", StopAnimation }, + {"setWeights", SetWeights }, + {"getFrame", GetFrame }, + }; } - -void WrapperAnimationMixer::New(const v8::FunctionCallbackInfo& info) +void* WrapperAnimationMixer::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - AnimationMixer* self = new AnimationMixer(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperAnimationMixer::dtor); + return new AnimationMixer; } void WrapperAnimationMixer::dtor(void* ptr, GameContext* ctx) @@ -68,8 +33,6 @@ void WrapperAnimationMixer::dtor(void* ptr, GameContext* ctx) delete (AnimationMixer*)ptr; } - - void WrapperAnimationMixer::GetAnimations(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); @@ -218,7 +181,7 @@ void WrapperAnimationMixer::GetFrame(const v8::FunctionCallbackInfo& AnimationMixer* self = lctx.self(); AnimationFrame frame; self->getFrame(frame); - v8::Local jframe = v8::Object::New(lctx.isolate); + v8::Local jframe = v8::Object::New(lctx.isolate); lctx.frame_to_jframe(frame, jframe); info.GetReturnValue().Set(jframe); } diff --git a/Three.V8/models/WrapperAnimationMixer.h b/Three.V8/models/WrapperAnimationMixer.h new file mode 100644 index 00000000..2aa2a6d1 --- /dev/null +++ b/Three.V8/models/WrapperAnimationMixer.h @@ -0,0 +1,31 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperAnimationMixer +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetAnimations(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetAnimation(const v8::FunctionCallbackInfo& info); + static void GetAnimations(const v8::FunctionCallbackInfo& info); + + static void AddAnimation(const v8::FunctionCallbackInfo& info); + static void AddAnimations(const v8::FunctionCallbackInfo& info); + + static void StartAnimation(const v8::FunctionCallbackInfo& info); + static void StopAnimation(const v8::FunctionCallbackInfo& info); + + static void GetCurrentPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetWeights(const v8::FunctionCallbackInfo& info); + + static void GetFrame(const v8::FunctionCallbackInfo& info); + +}; diff --git a/Three.V8/models/GLTFModel.hpp b/Three.V8/models/WrapperGLTFModel.cpp similarity index 67% rename from Three.V8/models/GLTFModel.hpp rename to Three.V8/models/WrapperGLTFModel.cpp index a67ba927..3ec08610 100644 --- a/Three.V8/models/GLTFModel.hpp +++ b/Three.V8/models/WrapperGLTFModel.cpp @@ -1,7 +1,5 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include #if THREE_MM #include @@ -13,86 +11,46 @@ #include #include -class WrapperGLTFModel -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetMinPos(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetMaxPos(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void GetMeshes(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void SetTexture(const v8::FunctionCallbackInfo& info); - - static void BatchPrimitives(const v8::FunctionCallbackInfo& info); - - static void SetAnimationFrame(const v8::FunctionCallbackInfo& info); - - static void GetAnimations(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetAnimation(const v8::FunctionCallbackInfo& info); - static void GetAnimations(const v8::FunctionCallbackInfo& info); +#include "WrapperGLTFModel.h" - static void AddAnimation(const v8::FunctionCallbackInfo& info); - static void AddAnimations(const v8::FunctionCallbackInfo& info); - static void PlayAnimation(const v8::FunctionCallbackInfo& info); - static void StopAnimation(const v8::FunctionCallbackInfo& info); - static void UpdateAnimation(const v8::FunctionCallbackInfo& info); - - static void SetToonShading(const v8::FunctionCallbackInfo& info); - - // lightmaps - static void GetIsBakable(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetLightmap(const v8::FunctionCallbackInfo& info); - static void GetLightmap(const v8::FunctionCallbackInfo& info); - static void InitializeLightmap(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperGLTFModel::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperGLTFModel::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "minPos").ToLocalChecked(), GetMinPos, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "maxPos").ToLocalChecked(), GetMaxPos, 0); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "meshes").ToLocalChecked(), GetMeshes, 0); - - templ->InstanceTemplate()->Set(isolate, "setTexture", v8::FunctionTemplate::New(isolate, SetTexture)); - - templ->InstanceTemplate()->Set(isolate, "batchPrimitives", v8::FunctionTemplate::New(isolate, BatchPrimitives)); - - templ->InstanceTemplate()->Set(isolate, "setAnimationFrame", v8::FunctionTemplate::New(isolate, SetAnimationFrame)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "animations").ToLocalChecked(), GetAnimations, 0); - templ->InstanceTemplate()->Set(isolate, "getAnimation", v8::FunctionTemplate::New(isolate, GetAnimation)); - templ->InstanceTemplate()->Set(isolate, "getAnimations", v8::FunctionTemplate::New(isolate, GetAnimations)); - - templ->InstanceTemplate()->Set(isolate, "addAnimation", v8::FunctionTemplate::New(isolate, AddAnimation)); - templ->InstanceTemplate()->Set(isolate, "addAnimations", v8::FunctionTemplate::New(isolate, AddAnimations)); - - templ->InstanceTemplate()->Set(isolate, "playAnimation", v8::FunctionTemplate::New(isolate, PlayAnimation)); - templ->InstanceTemplate()->Set(isolate, "stopAnimation", v8::FunctionTemplate::New(isolate, StopAnimation)); - templ->InstanceTemplate()->Set(isolate, "updateAnimation", v8::FunctionTemplate::New(isolate, UpdateAnimation)); - - templ->InstanceTemplate()->Set(isolate, "setToonShading", v8::FunctionTemplate::New(isolate, SetToonShading)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isBakable").ToLocalChecked(), GetIsBakable, 0); - templ->InstanceTemplate()->Set(isolate, "setLightmap", v8::FunctionTemplate::New(isolate, SetLightmap)); - templ->InstanceTemplate()->Set(isolate, "getLightmap", v8::FunctionTemplate::New(isolate, GetLightmap)); - templ->InstanceTemplate()->Set(isolate, "initializeLightmap", v8::FunctionTemplate::New(isolate, InitializeLightmap)); - - return templ; + WrapperObject3D::define(cls); + cls.name = "GLTFModel"; + cls.ctor = ctor; + + std::vector props = { + { "minPos", GetMinPos }, + { "maxPos", GetMaxPos }, + { "meshes", GetMeshes }, + { "animations", GetAnimations }, + { "isBakable", GetIsBakable }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"setTexture", SetTexture }, + {"batchPrimitives", BatchPrimitives }, + {"setAnimationFrame", SetAnimationFrame }, + {"getAnimation", GetAnimation }, + {"getAnimations", GetAnimations }, + {"addAnimation", AddAnimation }, + {"addAnimations", AddAnimations }, + {"playAnimation", PlayAnimation }, + {"stopAnimation", StopAnimation }, + {"updateAnimation", UpdateAnimation }, + {"setToonShading", SetToonShading }, + {"setLightmap", SetLightmap }, + {"getLightmap", GetLightmap }, + {"initializeLightmap", InitializeLightmap }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperGLTFModel::New(const v8::FunctionCallbackInfo& info) +void* WrapperGLTFModel::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - GLTFModel* self = new GLTFModel(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new GLTFModel; } void WrapperGLTFModel::GetMinPos(v8::Local property, const v8::PropertyCallbackInfo& info) @@ -137,7 +95,7 @@ void WrapperGLTFModel::GetMeshes(v8::Local property, const v8::Prope v8::Local jprimitive = v8::Object::New(lctx.isolate); lctx.set_property(jprimitive, "vertices", lctx.num_to_jnum(primitive.num_pos)); lctx.set_property(jprimitive, "triangles", lctx.num_to_jnum(primitive.num_face)); - lctx.set_property(jprimitive, "targets", lctx.num_to_jnum(primitive.num_targets)); + lctx.set_property(jprimitive, "targets", lctx.num_to_jnum(primitive.num_targets)); jprimitives->Set(lctx.context, (unsigned)j, jprimitive); } lctx.set_property(jmesh, "primitives", jprimitives); @@ -187,11 +145,11 @@ void WrapperGLTFModel::SetTexture(const v8::FunctionCallbackInfo& inf } else if (clsname == "GLRenderTarget") { - GLRenderTarget* target = lctx.jobj_to_obj(holder_image); + GLRenderTarget* target = lctx.jobj_to_obj(holder_image); if (target != nullptr) { self->m_repl_textures[idx] = target->m_tex_video.get(); - } + } } #if THREE_MM else if (clsname == "MMCamera") @@ -229,7 +187,7 @@ void WrapperGLTFModel::BatchPrimitives(const v8::FunctionCallbackInfo } void WrapperGLTFModel::SetAnimationFrame(const v8::FunctionCallbackInfo& info) -{ +{ LocalContext lctx(info); GLTFModel* self = lctx.self(); @@ -242,7 +200,7 @@ void WrapperGLTFModel::GetAnimations(v8::Local property, const v8::P { LocalContext lctx(info); GLTFModel* self = lctx.self(); - + v8::Local janims = v8::Array::New(lctx.isolate, (int)self->m_animations.size()); for (size_t i = 0; i < self->m_animations.size(); i++) @@ -261,7 +219,7 @@ void WrapperGLTFModel::GetAnimations(v8::Local property, const v8::P v8::Local jmorph = v8::Object::New(lctx.isolate); lctx.set_property(jmorph, "name", lctx.str_to_jstr(morph.name.c_str())); lctx.set_property(jmorph, "targets", lctx.num_to_jnum(morph.num_targets)); - lctx.set_property(jmorph, "frames", lctx.num_to_jnum(morph.times.size())); + lctx.set_property(jmorph, "frames", lctx.num_to_jnum(morph.times.size())); jmorphs->Set(lctx.context, (unsigned)j, jmorph); } lctx.set_property(janim, "morphs", jmorphs); @@ -291,7 +249,7 @@ void WrapperGLTFModel::GetAnimations(const v8::FunctionCallbackInfo& { LocalContext lctx(info); GLTFModel* self = lctx.self(); - + v8::Local janims = v8::Array::New(lctx.isolate, (int)self->m_animations.size()); for (size_t i = 0; i < self->m_animations.size(); i++) @@ -301,7 +259,7 @@ void WrapperGLTFModel::GetAnimations(const v8::FunctionCallbackInfo& lctx.anim_to_janim(anim, janim); janims->Set(lctx.context, (unsigned)i, janim); } - + info.GetReturnValue().Set(janims); } @@ -333,14 +291,14 @@ void WrapperGLTFModel::AddAnimations(const v8::FunctionCallbackInfo& void WrapperGLTFModel::PlayAnimation(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - GLTFModel* self = lctx.self(); + GLTFModel* self = lctx.self(); self->playAnimation(lctx.jstr_to_str(info[0]).c_str()); } void WrapperGLTFModel::StopAnimation(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - GLTFModel* self = lctx.self(); + GLTFModel* self = lctx.self(); self->stopAnimation(lctx.jstr_to_str(info[0]).c_str()); } @@ -383,7 +341,7 @@ void WrapperGLTFModel::SetLightmap(const v8::FunctionCallbackInfo& in LocalContext lctx(info); GLTFModel* self = lctx.self(); - v8::Local holder_image = info[0].As(); + v8::Local holder_image = info[0].As(); std::string clsname = lctx.jstr_to_str(holder_image->GetConstructorName()); if (clsname == "HDRImage") { diff --git a/Three.V8/models/WrapperGLTFModel.h b/Three.V8/models/WrapperGLTFModel.h new file mode 100644 index 00000000..9202dc8e --- /dev/null +++ b/Three.V8/models/WrapperGLTFModel.h @@ -0,0 +1,44 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperGLTFModel +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetMinPos(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetMaxPos(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void GetMeshes(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void SetTexture(const v8::FunctionCallbackInfo& info); + + static void BatchPrimitives(const v8::FunctionCallbackInfo& info); + + static void SetAnimationFrame(const v8::FunctionCallbackInfo& info); + + static void GetAnimations(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetAnimation(const v8::FunctionCallbackInfo& info); + static void GetAnimations(const v8::FunctionCallbackInfo& info); + + static void AddAnimation(const v8::FunctionCallbackInfo& info); + static void AddAnimations(const v8::FunctionCallbackInfo& info); + + static void PlayAnimation(const v8::FunctionCallbackInfo& info); + static void StopAnimation(const v8::FunctionCallbackInfo& info); + static void UpdateAnimation(const v8::FunctionCallbackInfo& info); + + static void SetToonShading(const v8::FunctionCallbackInfo& info); + + // lightmaps + static void GetIsBakable(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetLightmap(const v8::FunctionCallbackInfo& info); + static void GetLightmap(const v8::FunctionCallbackInfo& info); + static void InitializeLightmap(const v8::FunctionCallbackInfo& info); +}; + + diff --git a/Three.V8/models/WrapperHeightField.cpp b/Three.V8/models/WrapperHeightField.cpp new file mode 100644 index 00000000..e539e41f --- /dev/null +++ b/Three.V8/models/WrapperHeightField.cpp @@ -0,0 +1,41 @@ +#include "WrapperUtils.hpp" +#include +#include "WrapperHeightField.h" + +void WrapperHeightField::define(ClassDefinition& cls) +{ + cls.name = "HeightField"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"saveFile", SaveFile } + }; +} + +void* WrapperHeightField::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + + glm::vec3 min_pos, max_pos; + lctx.jvec3_to_vec3(info[0], min_pos); + lctx.jvec3_to_vec3(info[1], max_pos); + int width, height; + lctx.jnum_to_num(info[2], width); + lctx.jnum_to_num(info[3], height); + + return new HeightField(min_pos, max_pos, width, height); +} + +void WrapperHeightField::dtor(void* ptr, GameContext* ctx) +{ + delete (HeightField*)ptr; +} + +void WrapperHeightField::SaveFile(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + HeightField* self = lctx.self(); + std::string fn = lctx.jstr_to_str(info[0]); + self->saveFile(fn.c_str()); +} + diff --git a/Three.V8/models/WrapperHeightField.h b/Three.V8/models/WrapperHeightField.h new file mode 100644 index 00000000..f3c16c6a --- /dev/null +++ b/Three.V8/models/WrapperHeightField.h @@ -0,0 +1,18 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperHeightField +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void SaveFile(const v8::FunctionCallbackInfo& info); + +}; diff --git a/Three.V8/models/SimpleModel.hpp b/Three.V8/models/WrapperSimpleModel.cpp similarity index 62% rename from Three.V8/models/SimpleModel.hpp rename to Three.V8/models/WrapperSimpleModel.cpp index 6b174986..e5b4b4d0 100644 --- a/Three.V8/models/SimpleModel.hpp +++ b/Three.V8/models/WrapperSimpleModel.cpp @@ -1,7 +1,7 @@ #pragma once #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include #if THREE_MM #include @@ -12,60 +12,36 @@ #include #include -class WrapperSimpleModel -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void CreateBox(const v8::FunctionCallbackInfo& info); - static void CreateSphere(const v8::FunctionCallbackInfo& info); - static void CreatePlane(const v8::FunctionCallbackInfo& info); - - static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetColor(const v8::FunctionCallbackInfo& info); - static void SetColor(const v8::FunctionCallbackInfo& info); - - static void SetColorTexture(const v8::FunctionCallbackInfo& info); - - static void GetMetalness(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetMetalness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetRoughness(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetRoughness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void SetToonShading(const v8::FunctionCallbackInfo& info); -}; - +#include "WrapperSimpleModel.h" -v8::Local WrapperSimpleModel::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperSimpleModel::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->Set(isolate, "createBox", v8::FunctionTemplate::New(isolate, CreateBox)); - templ->InstanceTemplate()->Set(isolate, "createSphere", v8::FunctionTemplate::New(isolate, CreateSphere)); - templ->InstanceTemplate()->Set(isolate, "createPlane", v8::FunctionTemplate::New(isolate, CreatePlane)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "color").ToLocalChecked(), GetColor, 0); - templ->InstanceTemplate()->Set(isolate, "getColor", v8::FunctionTemplate::New(isolate, GetColor)); - templ->InstanceTemplate()->Set(isolate, "setColor", v8::FunctionTemplate::New(isolate, SetColor)); - - templ->InstanceTemplate()->Set(isolate, "setColorTexture", v8::FunctionTemplate::New(isolate, SetColorTexture)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "metalness").ToLocalChecked(), GetMetalness, SetMetalness); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "roughness").ToLocalChecked(), GetRoughness, SetRoughness); - - templ->InstanceTemplate()->Set(isolate, "setToonShading", v8::FunctionTemplate::New(isolate, SetToonShading)); - - return templ; + WrapperObject3D::define(cls); + cls.name = "SimpleModel"; + cls.ctor = ctor; + + std::vector props = { + { "color", GetColor }, + { "metalness", GetMetalness, SetMetalness }, + { "roughness", GetRoughness, SetRoughness }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"createBox", CreateBox }, + {"createSphere", CreateSphere }, + {"createPlane", CreatePlane }, + {"getColor", GetColor }, + {"setColor", SetColor }, + {"setColorTexture", SetColorTexture }, + {"setToonShading", SetToonShading }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperSimpleModel::New(const v8::FunctionCallbackInfo& info) +void* WrapperSimpleModel::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - SimpleModel* self = new SimpleModel(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new SimpleModel; } void WrapperSimpleModel::CreateBox(const v8::FunctionCallbackInfo& info) @@ -105,7 +81,7 @@ void WrapperSimpleModel::CreatePlane(const v8::FunctionCallbackInfo& SimpleModel* self = lctx.self(); float width, height; lctx.jnum_to_num(info[0], width); - lctx.jnum_to_num(info[1], height); + lctx.jnum_to_num(info[1], height); GeometryCreator::CreatePlane(&self->geometry, width, height); } @@ -157,10 +133,10 @@ void WrapperSimpleModel::SetColorTexture(const v8::FunctionCallbackInfo holder_image = info[0].As(); + v8::Local holder_image = info[0].As(); std::string clsname = lctx.jstr_to_str(holder_image->GetConstructorName()); - if (clsname== "Image") + if (clsname == "Image") { Image* image = lctx.jobj_to_obj(holder_image); if (image != nullptr) @@ -171,7 +147,7 @@ void WrapperSimpleModel::SetColorTexture(const v8::FunctionCallbackInfo(holder_image); + GLRenderTarget* target = lctx.jobj_to_obj(holder_image); if (target != nullptr) { self->repl_texture = target->m_tex_video.get(); @@ -209,7 +185,7 @@ void WrapperSimpleModel::SetColorTexture(const v8::FunctionCallbackInfo property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - SimpleModel* self = lctx.self(); + SimpleModel* self = lctx.self(); info.GetReturnValue().Set(lctx.num_to_jnum(self->material.metallicFactor)); } diff --git a/Three.V8/models/WrapperSimpleModel.h b/Three.V8/models/WrapperSimpleModel.h new file mode 100644 index 00000000..e1ea5866 --- /dev/null +++ b/Three.V8/models/WrapperSimpleModel.h @@ -0,0 +1,31 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperSimpleModel +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void CreateBox(const v8::FunctionCallbackInfo& info); + static void CreateSphere(const v8::FunctionCallbackInfo& info); + static void CreatePlane(const v8::FunctionCallbackInfo& info); + + static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetColor(const v8::FunctionCallbackInfo& info); + static void SetColor(const v8::FunctionCallbackInfo& info); + + static void SetColorTexture(const v8::FunctionCallbackInfo& info); + + static void GetMetalness(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetMetalness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetRoughness(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetRoughness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void SetToonShading(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/multimedia/AVCPlayer.hpp b/Three.V8/multimedia/AVCPlayer.hpp deleted file mode 100644 index 2189ba76..00000000 --- a/Three.V8/multimedia/AVCPlayer.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperAVCPlayer -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void AddPacket(const v8::FunctionCallbackInfo& info); - - static void UpdateTexture(const v8::FunctionCallbackInfo& info); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperAVCPlayer::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "addPacket", v8::FunctionTemplate::New(isolate, AddPacket)); - templ->InstanceTemplate()->Set(isolate, "updateTexture", v8::FunctionTemplate::New(isolate, UpdateTexture)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - - -void WrapperAVCPlayer::dtor(void* ptr, GameContext* ctx) -{ - delete (AVCPlayer*)ptr; -} - -void WrapperAVCPlayer::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - AVCPlayer* self = new AVCPlayer; - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - -void WrapperAVCPlayer::AddPacket(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - AVCPlayer* self = lctx.self(); - - v8::Local arr = info[0].As(); - size_t size = arr->ByteLength(); - const uint8_t* data = (const uint8_t*)arr->GetBackingStore()->Data(); - self->AddPacket(size, data); - -} - -void WrapperAVCPlayer::UpdateTexture(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - AVCPlayer* self = lctx.self(); - self->update_texture(); -} - -void WrapperAVCPlayer::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - AVCPlayer* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); -} - -void WrapperAVCPlayer::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - AVCPlayer* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); -} - diff --git a/Three.V8/multimedia/MMCamera.hpp b/Three.V8/multimedia/MMCamera.hpp deleted file mode 100644 index 049a1074..00000000 --- a/Three.V8/multimedia/MMCamera.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperMMCamera -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void UpdateTexture(const v8::FunctionCallbackInfo& info); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperMMCamera::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "updateTexture", v8::FunctionTemplate::New(isolate, UpdateTexture)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - -void WrapperMMCamera::dtor(void* ptr, GameContext* ctx) -{ - delete (MMCamera*)ptr; -} - -void WrapperMMCamera::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - int idx = 0; - if (info.Length() > 0) - { - lctx.jnum_to_num(info[0], idx); - } - - MMCamera* self = new MMCamera(idx); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperMMCamera::UpdateTexture(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - MMCamera* self = lctx.self(); - self->update_texture(); -} - - -void WrapperMMCamera::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMCamera* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); -} - -void WrapperMMCamera::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMCamera* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); -} - diff --git a/Three.V8/multimedia/MMLazyVideo.hpp b/Three.V8/multimedia/MMLazyVideo.hpp deleted file mode 100644 index da5c2634..00000000 --- a/Three.V8/multimedia/MMLazyVideo.hpp +++ /dev/null @@ -1,147 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperMMLazyVideo -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void UpdateTexture(const v8::FunctionCallbackInfo& info); - static void GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); - static void IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); - static void Play(const v8::FunctionCallbackInfo& info); - static void Pause(const v8::FunctionCallbackInfo& info); - static void SetPosition(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperMMLazyVideo::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "updateTexture", v8::FunctionTemplate::New(isolate, UpdateTexture)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "looping").ToLocalChecked(), GetLooping, SetLooping); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isPlaying").ToLocalChecked(), IsPlaying, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "duration").ToLocalChecked(), GetDuration, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "position").ToLocalChecked(), GetPosition, 0); - templ->InstanceTemplate()->Set(isolate, "play", v8::FunctionTemplate::New(isolate, Play)); - templ->InstanceTemplate()->Set(isolate, "pause", v8::FunctionTemplate::New(isolate, Pause)); - templ->InstanceTemplate()->Set(isolate, "setPosition", v8::FunctionTemplate::New(isolate, SetPosition)); - return templ; -} - -void WrapperMMLazyVideo::dtor(void* ptr, GameContext* ctx) -{ - delete (MMLazyVideo*)ptr; -} - - -void WrapperMMLazyVideo::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - std::string filename = lctx.jstr_to_str(info[0]); - double speed = 1.0; - if (info.Length() > 1) - { - lctx.jnum_to_num(info[1], speed); - } - - MMLazyVideo* self = new MMLazyVideo(filename.c_str(), speed); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperMMLazyVideo::UpdateTexture(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - self->update_texture(); -} - -void WrapperMMLazyVideo::GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - info.GetReturnValue().Set(v8::Boolean::New(lctx.isolate, self->m_is_loop)); -} - -void WrapperMMLazyVideo::SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - self->m_is_loop = value.As()->Value(); -} - - -void WrapperMMLazyVideo::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); -} - -void WrapperMMLazyVideo::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); -} - -void WrapperMMLazyVideo::IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - info.GetReturnValue().Set(v8::Boolean::New(lctx.isolate, self->is_playing())); -} - -void WrapperMMLazyVideo::GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->get_total_duration_s())); -} - -void WrapperMMLazyVideo::GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->get_current_pos_s())); -} - -void WrapperMMLazyVideo::Play(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - self->play(); -} - -void WrapperMMLazyVideo::Pause(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - self->pause(); -} - -void WrapperMMLazyVideo::SetPosition(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - MMLazyVideo* self = lctx.self(); - double pos; - lctx.jnum_to_num(info[0], pos); - self->set_pos_s(pos); -} - - - diff --git a/Three.V8/multimedia/OpusPlayer.hpp b/Three.V8/multimedia/OpusPlayer.hpp deleted file mode 100644 index 98621237..00000000 --- a/Three.V8/multimedia/OpusPlayer.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperOpusPlayer -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void AddPacket(const v8::FunctionCallbackInfo& info); -}; - - -v8::Local WrapperOpusPlayer::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "addPacket", v8::FunctionTemplate::New(isolate, AddPacket)); - return templ; -} - - -void WrapperOpusPlayer::dtor(void* ptr, GameContext* ctx) -{ - delete (OpusPlayer*)ptr; -} - -void WrapperOpusPlayer::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - - int id_device = -1; - if (info.Length() > 0) - { - lctx.jnum_to_num(info[0], id_device); - } - - OpusPlayer* self = new OpusPlayer(id_device); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - -void WrapperOpusPlayer::AddPacket(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - OpusPlayer* self = lctx.self(); - - v8::Local arr = info[0].As(); - size_t size = arr->ByteLength(); - const uint8_t* data = (const uint8_t *)arr->GetBackingStore()->Data(); - self->AddPacket(size, data); - -} \ No newline at end of file diff --git a/Three.V8/multimedia/WrapperAVCPlayer.cpp b/Three.V8/multimedia/WrapperAVCPlayer.cpp new file mode 100644 index 00000000..464524e9 --- /dev/null +++ b/Three.V8/multimedia/WrapperAVCPlayer.cpp @@ -0,0 +1,70 @@ +#if THREE_MM + +#include "WrapperUtils.hpp" +#include + +#include "WrapperAVCPlayer.h" + + +void WrapperAVCPlayer::define(ClassDefinition& cls) +{ + cls.name = "AVCPlayer"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; + cls.methods = { + {"addPacket", AddPacket }, + {"updateTexture", UpdateTexture }, + }; +} + +void* WrapperAVCPlayer::ctor(const v8::FunctionCallbackInfo& info) +{ + return new AVCPlayer; +} + +void WrapperAVCPlayer::dtor(void* ptr, GameContext* ctx) +{ + delete (AVCPlayer*)ptr; +} + +void WrapperAVCPlayer::AddPacket(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + AVCPlayer* self = lctx.self(); + + v8::Local arr = info[0].As(); + size_t size = arr->ByteLength(); + const uint8_t* data = (const uint8_t*)arr->GetBackingStore()->Data(); + self->AddPacket(size, data); + +} + +void WrapperAVCPlayer::UpdateTexture(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + AVCPlayer* self = lctx.self(); + self->update_texture(); +} + +void WrapperAVCPlayer::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + AVCPlayer* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); +} + +void WrapperAVCPlayer::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + AVCPlayer* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); +} + + + +#endif + diff --git a/Three.V8/multimedia/WrapperAVCPlayer.h b/Three.V8/multimedia/WrapperAVCPlayer.h new file mode 100644 index 00000000..ad7da3f0 --- /dev/null +++ b/Three.V8/multimedia/WrapperAVCPlayer.h @@ -0,0 +1,22 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperAVCPlayer +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void AddPacket(const v8::FunctionCallbackInfo& info); + + static void UpdateTexture(const v8::FunctionCallbackInfo& info); + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; + diff --git a/Three.V8/multimedia/AVCRecorder.hpp b/Three.V8/multimedia/WrapperAVCRecorder.cpp similarity index 61% rename from Three.V8/multimedia/AVCRecorder.hpp rename to Three.V8/multimedia/WrapperAVCRecorder.cpp index 84d9a74b..e9cb949f 100644 --- a/Three.V8/multimedia/AVCRecorder.hpp +++ b/Three.V8/multimedia/WrapperAVCRecorder.cpp @@ -1,34 +1,21 @@ -#pragma once +#if THREE_MM #include "WrapperUtils.hpp" #include -class WrapperAVCRecorder -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void GetCallback(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetCallback(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; +#include "WrapperAVCRecorder.h" - -v8::Local WrapperAVCRecorder::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperAVCRecorder::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "callback").ToLocalChecked(), GetCallback, SetCallback); - - return templ; + cls.name = "AVCRecorder"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "callback", GetCallback, SetCallback }, + }; } + typedef v8::Persistent> CallbackT; struct AVCRecorderCallbackData @@ -38,6 +25,19 @@ struct AVCRecorderCallbackData }; +void* WrapperAVCRecorder::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + + int id_device = 0; + if (info.Length() > 0) + { + lctx.jnum_to_num(info[0], id_device); + } + + return new AVCRecorder(id_device); +} + void WrapperAVCRecorder::dtor(void* ptr, GameContext* ctx) { AVCRecorder* self = (AVCRecorder*)ptr; @@ -53,22 +53,6 @@ void WrapperAVCRecorder::dtor(void* ptr, GameContext* ctx) } -void WrapperAVCRecorder::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - - int id_device = 0; - if (info.Length() > 0) - { - lctx.jnum_to_num(info[0], id_device); - } - - AVCRecorder* self = new AVCRecorder(id_device); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - static void AVCRecorderCallback(const void* msg_data, size_t msg_size, void* ptr) { AVCRecorderCallbackData* data = (AVCRecorderCallbackData*)ptr; @@ -82,7 +66,7 @@ static void AVCRecorderCallback(const void* msg_data, size_t msg_size, void* ptr v8::Local buf = v8::ArrayBuffer::New(isolate, msg_size); memcpy(buf->GetBackingStore()->Data(), msg_data, msg_size); - std::vector> args = { buf }; + std::vector> args = { buf }; ctx->InvokeCallback(*callback, args); } @@ -115,4 +99,7 @@ void WrapperAVCRecorder::SetCallback(v8::Local property, v8::Localcallback = CallbackT(lctx.isolate, callback); self->SetCallback(AVCRecorderCallback, data); -} \ No newline at end of file +} + +#endif + diff --git a/Three.V8/multimedia/WrapperAVCRecorder.h b/Three.V8/multimedia/WrapperAVCRecorder.h new file mode 100644 index 00000000..56152225 --- /dev/null +++ b/Three.V8/multimedia/WrapperAVCRecorder.h @@ -0,0 +1,19 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperAVCRecorder +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetCallback(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetCallback(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; diff --git a/Three.V8/multimedia/MMAudio.hpp b/Three.V8/multimedia/WrapperMMAudio.cpp similarity index 50% rename from Three.V8/multimedia/MMAudio.hpp rename to Three.V8/multimedia/WrapperMMAudio.cpp index 0f953db5..d45c1dad 100644 --- a/Three.V8/multimedia/MMAudio.hpp +++ b/Three.V8/multimedia/WrapperMMAudio.cpp @@ -1,52 +1,33 @@ -#pragma once +#if THREE_MM #include "WrapperUtils.hpp" #include -class WrapperMMAudio -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void CheckEof(const v8::FunctionCallbackInfo& info); - static void GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); - static void Play(const v8::FunctionCallbackInfo& info); - static void Pause(const v8::FunctionCallbackInfo& info); - static void SetPosition(const v8::FunctionCallbackInfo& info); - static void SetAudioDevice(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperMMAudio::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "checkEof", v8::FunctionTemplate::New(isolate, CheckEof)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "looping").ToLocalChecked(), GetLooping, SetLooping); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isPlaying").ToLocalChecked(), IsPlaying, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "duration").ToLocalChecked(), GetDuration, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "position").ToLocalChecked(), GetPosition, 0); - templ->InstanceTemplate()->Set(isolate, "play", v8::FunctionTemplate::New(isolate, Play)); - templ->InstanceTemplate()->Set(isolate, "pause", v8::FunctionTemplate::New(isolate, Pause)); - templ->InstanceTemplate()->Set(isolate, "setPosition", v8::FunctionTemplate::New(isolate, SetPosition)); - templ->InstanceTemplate()->Set(isolate, "setAudioDevice", v8::FunctionTemplate::New(isolate, SetAudioDevice)); - return templ; -} +#include "WrapperMMAudio.h" -void WrapperMMAudio::dtor(void* ptr, GameContext* ctx) +void WrapperMMAudio::define(ClassDefinition& cls) { - delete (MMAudio*)ptr; + cls.name = "MMAudio"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "looping", GetLooping, SetLooping }, + { "isPlaying", IsPlaying }, + { "duration", GetDuration }, + { "position", GetPosition }, + }; + cls.methods = { + {"checkEof", CheckEof }, + {"play", Play }, + {"pause", Pause }, + {"setPosition", SetPosition }, + {"setAudioDevice", SetAudioDevice }, + }; } -void WrapperMMAudio::New(const v8::FunctionCallbackInfo& info) + +void* WrapperMMAudio::ctor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); std::string filename = lctx.jstr_to_str(info[0]); @@ -57,7 +38,7 @@ void WrapperMMAudio::New(const v8::FunctionCallbackInfo& info) } int device = -1; - int speed = 1; + int speed = 1; if (info.Length() > 1) { lctx.jnum_to_num(info[1], device); @@ -70,19 +51,23 @@ void WrapperMMAudio::New(const v8::FunctionCallbackInfo& info) MMAudio* self; if (http) - { - HttpClient* http = lctx.ctx()->GetHttpClient(); + { + v8::Local holder_http = lctx.get_global("http"); + HttpClient* http = lctx.jobj_to_obj(holder_http); self = new MMAudio(http, filename.c_str(), device, speed); } else { self = new MMAudio(filename.c_str(), device, speed); } - - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + + return self; } +void WrapperMMAudio::dtor(void* ptr, GameContext* ctx) +{ + delete (MMAudio*)ptr; +} void WrapperMMAudio::CheckEof(const v8::FunctionCallbackInfo& info) { @@ -163,3 +148,4 @@ void WrapperMMAudio::SetAudioDevice(const v8::FunctionCallbackInfo& i } +#endif diff --git a/Three.V8/multimedia/WrapperMMAudio.h b/Three.V8/multimedia/WrapperMMAudio.h new file mode 100644 index 00000000..409bc599 --- /dev/null +++ b/Three.V8/multimedia/WrapperMMAudio.h @@ -0,0 +1,27 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperMMAudio +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void CheckEof(const v8::FunctionCallbackInfo& info); + static void GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); + static void Play(const v8::FunctionCallbackInfo& info); + static void Pause(const v8::FunctionCallbackInfo& info); + static void SetPosition(const v8::FunctionCallbackInfo& info); + static void SetAudioDevice(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/multimedia/WrapperMMCamera.cpp b/Three.V8/multimedia/WrapperMMCamera.cpp new file mode 100644 index 00000000..bf76211b --- /dev/null +++ b/Three.V8/multimedia/WrapperMMCamera.cpp @@ -0,0 +1,64 @@ +#if THREE_MM + +#include "WrapperUtils.hpp" +#include + +#include "WrapperMMCamera.h" + +void WrapperMMCamera::define(ClassDefinition& cls) +{ + cls.name = "MMCamera"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; + cls.methods = { + {"updateTexture", UpdateTexture }, + }; +} + +void* WrapperMMCamera::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + int idx = 0; + if (info.Length() > 0) + { + lctx.jnum_to_num(info[0], idx); + } + return new MMCamera(idx); +} + +void WrapperMMCamera::dtor(void* ptr, GameContext* ctx) +{ + delete (MMCamera*)ptr; +} + +void WrapperMMCamera::UpdateTexture(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + MMCamera* self = lctx.self(); + self->update_texture(); +} + + +void WrapperMMCamera::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMCamera* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); +} + +void WrapperMMCamera::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMCamera* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); +} + + + + +#endif + diff --git a/Three.V8/multimedia/WrapperMMCamera.h b/Three.V8/multimedia/WrapperMMCamera.h new file mode 100644 index 00000000..7f264b49 --- /dev/null +++ b/Three.V8/multimedia/WrapperMMCamera.h @@ -0,0 +1,20 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperMMCamera +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void UpdateTexture(const v8::FunctionCallbackInfo& info); + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; + diff --git a/Three.V8/multimedia/WrapperMMLazyVideo.cpp b/Three.V8/multimedia/WrapperMMLazyVideo.cpp new file mode 100644 index 00000000..2935237d --- /dev/null +++ b/Three.V8/multimedia/WrapperMMLazyVideo.cpp @@ -0,0 +1,127 @@ +#if THREE_MM + +#include "WrapperUtils.hpp" +#include + +#include "WrapperMMLazyVideo.h" + +void WrapperMMLazyVideo::define(ClassDefinition& cls) +{ + cls.name = "MMLazyVideo"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "looping", GetLooping, SetLooping }, + { "width", GetWidth }, + { "height", GetHeight }, + { "isPlaying", IsPlaying }, + { "duration", GetDuration }, + { "position", GetPosition }, + }; + cls.methods = { + {"updateTexture", UpdateTexture }, + {"play", Play }, + {"pause", Pause }, + {"setPosition", SetPosition }, + }; +} + +void* WrapperMMLazyVideo::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + std::string filename = lctx.jstr_to_str(info[0]); + double speed = 1.0; + if (info.Length() > 1) + { + lctx.jnum_to_num(info[1], speed); + } + + return new MMLazyVideo(filename.c_str(), speed); +} + +void WrapperMMLazyVideo::dtor(void* ptr, GameContext* ctx) +{ + delete (MMLazyVideo*)ptr; +} + +void WrapperMMLazyVideo::UpdateTexture(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + self->update_texture(); +} + +void WrapperMMLazyVideo::GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + info.GetReturnValue().Set(v8::Boolean::New(lctx.isolate, self->m_is_loop)); +} + +void WrapperMMLazyVideo::SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + self->m_is_loop = value.As()->Value(); +} + + +void WrapperMMLazyVideo::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); +} + +void WrapperMMLazyVideo::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); +} + +void WrapperMMLazyVideo::IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + info.GetReturnValue().Set(v8::Boolean::New(lctx.isolate, self->is_playing())); +} + +void WrapperMMLazyVideo::GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->get_total_duration_s())); +} + +void WrapperMMLazyVideo::GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->get_current_pos_s())); +} + +void WrapperMMLazyVideo::Play(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + self->play(); +} + +void WrapperMMLazyVideo::Pause(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + self->pause(); +} + +void WrapperMMLazyVideo::SetPosition(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + MMLazyVideo* self = lctx.self(); + double pos; + lctx.jnum_to_num(info[0], pos); + self->set_pos_s(pos); +} + +#endif \ No newline at end of file diff --git a/Three.V8/multimedia/WrapperMMLazyVideo.h b/Three.V8/multimedia/WrapperMMLazyVideo.h new file mode 100644 index 00000000..4c417f64 --- /dev/null +++ b/Three.V8/multimedia/WrapperMMLazyVideo.h @@ -0,0 +1,28 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperMMLazyVideo +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void UpdateTexture(const v8::FunctionCallbackInfo& info); + static void GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); + static void IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); + static void Play(const v8::FunctionCallbackInfo& info); + static void Pause(const v8::FunctionCallbackInfo& info); + static void SetPosition(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/multimedia/MMVideo.hpp b/Three.V8/multimedia/WrapperMMVideo.cpp similarity index 52% rename from Three.V8/multimedia/MMVideo.hpp rename to Three.V8/multimedia/WrapperMMVideo.cpp index 911bb89f..fcff274c 100644 --- a/Three.V8/multimedia/MMVideo.hpp +++ b/Three.V8/multimedia/WrapperMMVideo.cpp @@ -1,55 +1,34 @@ -#pragma once +#if THREE_MM #include "WrapperUtils.hpp" #include -class WrapperMMVideo -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void UpdateTexture(const v8::FunctionCallbackInfo& info); - static void GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); - static void IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); - static void Play(const v8::FunctionCallbackInfo& info); - static void Pause(const v8::FunctionCallbackInfo& info); - static void SetPosition(const v8::FunctionCallbackInfo& info); - static void SetAudioDevice(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperMMVideo::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "updateTexture", v8::FunctionTemplate::New(isolate, UpdateTexture)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "looping").ToLocalChecked(), GetLooping, SetLooping); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isPlaying").ToLocalChecked(), IsPlaying, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "duration").ToLocalChecked(), GetDuration, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "position").ToLocalChecked(), GetPosition, 0); - templ->InstanceTemplate()->Set(isolate, "play", v8::FunctionTemplate::New(isolate, Play)); - templ->InstanceTemplate()->Set(isolate, "pause", v8::FunctionTemplate::New(isolate, Pause)); - templ->InstanceTemplate()->Set(isolate, "setPosition", v8::FunctionTemplate::New(isolate, SetPosition)); - templ->InstanceTemplate()->Set(isolate, "setAudioDevice", v8::FunctionTemplate::New(isolate, SetAudioDevice)); - return templ; +#include "WrapperMMVideo.h" + +void WrapperMMVideo::define(ClassDefinition& cls) +{ + cls.name = "MMVideo"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "looping", GetLooping, SetLooping }, + { "width", GetWidth }, + { "height", GetHeight }, + { "isPlaying", IsPlaying }, + { "duration", GetDuration }, + { "position", GetPosition }, + }; + cls.methods = { + {"updateTexture", UpdateTexture }, + {"play", Play }, + {"pause", Pause }, + {"setPosition", SetPosition }, + {"setAudioDevice", SetAudioDevice }, + }; } -void WrapperMMVideo::dtor(void* ptr, GameContext* ctx) -{ - delete (MMVideo*)ptr; -} -void WrapperMMVideo::New(const v8::FunctionCallbackInfo& info) +void* WrapperMMVideo::ctor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); std::string filename = lctx.jstr_to_str(info[0]); @@ -79,15 +58,21 @@ void WrapperMMVideo::New(const v8::FunctionCallbackInfo& info) MMVideo* self; if (http) { - HttpClient* http = lctx.ctx()->GetHttpClient(); + v8::Local holder_http = lctx.get_global("http"); + HttpClient* http = lctx.jobj_to_obj(holder_http); self = new MMVideo(http, filename.c_str(), play_audio, device, speed); } else { self = new MMVideo(filename.c_str(), play_audio, device, speed); } - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + + return self; +} + +void WrapperMMVideo::dtor(void* ptr, GameContext* ctx) +{ + delete (MMVideo*)ptr; } void WrapperMMVideo::UpdateTexture(const v8::FunctionCallbackInfo& info) @@ -182,3 +167,5 @@ void WrapperMMVideo::SetAudioDevice(const v8::FunctionCallbackInfo& i } +#endif + diff --git a/Three.V8/multimedia/WrapperMMVideo.h b/Three.V8/multimedia/WrapperMMVideo.h new file mode 100644 index 00000000..ece281c4 --- /dev/null +++ b/Three.V8/multimedia/WrapperMMVideo.h @@ -0,0 +1,28 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperMMVideo +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void UpdateTexture(const v8::FunctionCallbackInfo& info); + static void GetLooping(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetLooping(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); + static void IsPlaying(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetDuration(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetPosition(v8::Local property, const v8::PropertyCallbackInfo& info); + static void Play(const v8::FunctionCallbackInfo& info); + static void Pause(const v8::FunctionCallbackInfo& info); + static void SetPosition(const v8::FunctionCallbackInfo& info); + static void SetAudioDevice(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/multimedia/WrapperOpusPlayer.cpp b/Three.V8/multimedia/WrapperOpusPlayer.cpp new file mode 100644 index 00000000..b147e53d --- /dev/null +++ b/Three.V8/multimedia/WrapperOpusPlayer.cpp @@ -0,0 +1,47 @@ +#if THREE_MM + +#include "WrapperUtils.hpp" +#include + +#include "WrapperOpusPlayer.h" + +void WrapperOpusPlayer::define(ClassDefinition& cls) +{ + cls.name = "OpusPlayer"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"addPacket", AddPacket }, + }; +} + +void* WrapperOpusPlayer::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + + int id_device = -1; + if (info.Length() > 0) + { + lctx.jnum_to_num(info[0], id_device); + } + + return new OpusPlayer(id_device); +} + +void WrapperOpusPlayer::dtor(void* ptr, GameContext* ctx) +{ + delete (OpusPlayer*)ptr; +} + +void WrapperOpusPlayer::AddPacket(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + OpusPlayer* self = lctx.self(); + + v8::Local arr = info[0].As(); + size_t size = arr->ByteLength(); + const uint8_t* data = (const uint8_t*)arr->GetBackingStore()->Data(); + self->AddPacket(size, data); +} + +#endif diff --git a/Three.V8/multimedia/WrapperOpusPlayer.h b/Three.V8/multimedia/WrapperOpusPlayer.h new file mode 100644 index 00000000..bae454bb --- /dev/null +++ b/Three.V8/multimedia/WrapperOpusPlayer.h @@ -0,0 +1,17 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperOpusPlayer +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void AddPacket(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/multimedia/OpusRecorder.hpp b/Three.V8/multimedia/WrapperOpusRecorder.cpp similarity index 61% rename from Three.V8/multimedia/OpusRecorder.hpp rename to Three.V8/multimedia/WrapperOpusRecorder.cpp index 6ecebad0..f831772e 100644 --- a/Three.V8/multimedia/OpusRecorder.hpp +++ b/Three.V8/multimedia/WrapperOpusRecorder.cpp @@ -1,34 +1,21 @@ -#pragma once +#if THREE_MM #include "WrapperUtils.hpp" #include -class WrapperOpusRecorder -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void GetCallback(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetCallback(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; +#include "WrapperOpusRecorder.h" - -v8::Local WrapperOpusRecorder::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperOpusRecorder::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "callback").ToLocalChecked(), GetCallback, SetCallback); - - return templ; + cls.name = "OpusRecorder"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "callback", GetCallback, SetCallback }, + }; } + typedef v8::Persistent> CallbackT; struct OpusRecorderCallbackData @@ -38,6 +25,19 @@ struct OpusRecorderCallbackData }; +void* WrapperOpusRecorder::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + + int id_device = -1; + if (info.Length() > 0) + { + lctx.jnum_to_num(info[0], id_device); + } + + return new OpusRecorder(id_device); +} + void WrapperOpusRecorder::dtor(void* ptr, GameContext* ctx) { OpusRecorder* self = (OpusRecorder*)ptr; @@ -48,24 +48,8 @@ void WrapperOpusRecorder::dtor(void* ptr, GameContext* ctx) delete data; self->SetCallback(nullptr, nullptr); } - } - delete self; -} - - -void WrapperOpusRecorder::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - - int id_device = -1; - if (info.Length() > 0) - { - lctx.jnum_to_num(info[0], id_device); } - - OpusRecorder* self = new OpusRecorder(id_device); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + delete self; } @@ -78,11 +62,11 @@ static void OpusRecorderCallback(const void* msg_data, size_t msg_size, void* pt v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); v8::Local callback = data->callback.Get(isolate); - + v8::Local buf = v8::ArrayBuffer::New(isolate, msg_size); memcpy(buf->GetBackingStore()->Data(), msg_data, msg_size); - std::vector> args = { buf }; + std::vector> args = { buf }; ctx->InvokeCallback(*callback, args); } @@ -115,4 +99,7 @@ void WrapperOpusRecorder::SetCallback(v8::Local property, v8::Local< data->callback = CallbackT(lctx.isolate, callback); self->SetCallback(OpusRecorderCallback, data); -} \ No newline at end of file +} + +#endif + diff --git a/Three.V8/multimedia/WrapperOpusRecorder.h b/Three.V8/multimedia/WrapperOpusRecorder.h new file mode 100644 index 00000000..2e02f457 --- /dev/null +++ b/Three.V8/multimedia/WrapperOpusRecorder.h @@ -0,0 +1,19 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperOpusRecorder +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetCallback(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetCallback(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; diff --git a/Three.V8/network/HttpClient.hpp b/Three.V8/network/WrapperHttpClient.cpp similarity index 72% rename from Three.V8/network/HttpClient.hpp rename to Three.V8/network/WrapperHttpClient.cpp index 25b157c5..94c47ac5 100644 --- a/Three.V8/network/HttpClient.hpp +++ b/Three.V8/network/WrapperHttpClient.cpp @@ -1,28 +1,29 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include "WrapperHttpClient.h" -class WrapperHttpClient -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void Get(const v8::FunctionCallbackInfo& info); - static void GetAsync(const v8::FunctionCallbackInfo& info); -}; +void WrapperHttpClient::define(ObjectDefinition& object) +{ + object.name = "http"; + object.ctor = ctor; + object.dtor = dtor; + object.methods = { + { "get", Get}, + { "getAsync", GetAsync}, + }; +} -v8::Local WrapperHttpClient::create_template(v8::Isolate* isolate) +void* WrapperHttpClient::ctor() { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->SetInternalFieldCount(1); - templ->Set(isolate, "get", v8::FunctionTemplate::New(isolate, Get)); - templ->Set(isolate, "getAsync", v8::FunctionTemplate::New(isolate, GetAsync)); - return templ; + return new HttpClient; +} + +void WrapperHttpClient::dtor(void* ptr, GameContext* ctx) +{ + delete (HttpClient*)ptr; } void WrapperHttpClient::Get(const v8::FunctionCallbackInfo& info) @@ -43,7 +44,7 @@ void WrapperHttpClient::Get(const v8::FunctionCallbackInfo& info) if (is_string) { std::vector str(data.size() + 1, 0); - memcpy(str.data(), data.data(), data.size()); + memcpy(str.data(), data.data(), data.size()); info.GetReturnValue().Set(lctx.str_to_jstr(str.data())); } else @@ -68,7 +69,7 @@ struct V8GetData static void HttpGetCallback(const GetResult& result, void* userData) { V8GetData* v8data = (V8GetData*)(userData); - GameContext* ctx = v8data->ctx; + GameContext* ctx = v8data->ctx; v8::Isolate* isolate = ctx->m_vm->m_isolate; LocalContext lctx(isolate); @@ -83,8 +84,8 @@ static void HttpGetCallback(const GetResult& result, void* userData) if (v8data->is_string) { std::vector str(result.data.size() + 1, 0); - memcpy(str.data(), result.data.data(), result.data.size()); - args[1] = lctx.str_to_jstr(str.data()); + memcpy(str.data(), result.data.data(), result.data.size()); + args[1] = lctx.str_to_jstr(str.data()); } else { @@ -98,7 +99,7 @@ static void HttpGetCallback(const GetResult& result, void* userData) { args[1] = v8::Null(isolate); } - ctx->InvokeCallback(callback, args); + ctx->InvokeCallback(callback, args); delete v8data; } diff --git a/Three.V8/network/WrapperHttpClient.h b/Three.V8/network/WrapperHttpClient.h new file mode 100644 index 00000000..cab6a1b0 --- /dev/null +++ b/Three.V8/network/WrapperHttpClient.h @@ -0,0 +1,16 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; +class WrapperHttpClient +{ +public: + static void define(ObjectDefinition& object); + +private: + static void* ctor(); + static void dtor(void* ptr, GameContext* ctx); + static void Get(const v8::FunctionCallbackInfo& info); + static void GetAsync(const v8::FunctionCallbackInfo& info); +}; \ No newline at end of file diff --git a/Three.V8/network/WSClient.hpp b/Three.V8/network/WrapperWSClient.cpp similarity index 70% rename from Three.V8/network/WSClient.hpp rename to Three.V8/network/WrapperWSClient.cpp index 246d3a17..de236dbc 100644 --- a/Three.V8/network/WSClient.hpp +++ b/Three.V8/network/WrapperWSClient.cpp @@ -1,42 +1,22 @@ -#pragma once - #include "WrapperUtils.hpp" #include +#include "WrapperWSClient.h" -class WrapperWSClient -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - - static void Send(const v8::FunctionCallbackInfo& info); - - static void GetOnOpen(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnOpen(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetOnMessage(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetOnMessage(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; - -v8::Local WrapperWSClient::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperWSClient::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->Set(isolate, "send", v8::FunctionTemplate::New(isolate, Send)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onOpen").ToLocalChecked(), GetOnOpen, SetOnOpen); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "onMessage").ToLocalChecked(), GetOnMessage, SetOnMessage); - - - return templ; + cls.name = "WSClient"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "onOpen", GetOnOpen, SetOnOpen }, + { "onMessage", GetOnMessage, SetOnMessage }, + }; + cls.methods = { + {"send", Send }, + }; } + typedef v8::Persistent> CallbackT; struct WSClientCallbackData @@ -45,6 +25,14 @@ struct WSClientCallbackData CallbackT callback; }; +void* WrapperWSClient::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + std::string url = lctx.jstr_to_str(info[0]); + + return new WSClient(url.c_str()); +} + void WrapperWSClient::dtor(void* ptr, GameContext* ctx) { WSClient* self = (WSClient*)ptr; @@ -63,21 +51,10 @@ void WrapperWSClient::dtor(void* ptr, GameContext* ctx) delete data; self->SetMessageCallback(nullptr, nullptr); } - } + } delete self; } - -void WrapperWSClient::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - std::string url = lctx.jstr_to_str(info[0]); - - WSClient* self = new WSClient(url.c_str()); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - void WrapperWSClient::Send(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); @@ -106,7 +83,7 @@ static void WSClientOpenCallback(void* ptr) v8::Local callback = data->callback.Get(isolate); std::vector> args; ctx->InvokeCallback(*callback, args); - + } @@ -126,7 +103,7 @@ void WrapperWSClient::SetOnOpen(v8::Local property, v8::LocalGetOpenCallbackData(); if (data != nullptr) - { + { delete data; } @@ -148,15 +125,15 @@ static void WSClientMessageCallback(const void* msg_data, size_t msg_size, bool v8::HandleScope handle_scope(isolate); v8::Local context = ctx->m_context.Get(isolate); v8::Context::Scope context_scope(context); - v8::Local callback = data->callback.Get(isolate); + v8::Local callback = data->callback.Get(isolate); if (is_binary) { v8::Local buf = v8::ArrayBuffer::New(isolate, msg_size); memcpy(buf->GetBackingStore()->Data(), msg_data, msg_size); - std::vector> args = { buf }; + std::vector> args = { buf }; ctx->InvokeCallback(*callback, args); - + } else { @@ -195,4 +172,6 @@ void WrapperWSClient::SetOnMessage(v8::Local property, v8::Localcallback = CallbackT(lctx.isolate, callback); self->SetMessageCallback(WSClientMessageCallback, data); -} \ No newline at end of file +} + + diff --git a/Three.V8/network/WrapperWSClient.h b/Three.V8/network/WrapperWSClient.h new file mode 100644 index 00000000..29753113 --- /dev/null +++ b/Three.V8/network/WrapperWSClient.h @@ -0,0 +1,24 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperWSClient +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void Send(const v8::FunctionCallbackInfo& info); + + static void GetOnOpen(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnOpen(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetOnMessage(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetOnMessage(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; diff --git a/Three.V8/renderers/CubeRenderTarget.hpp b/Three.V8/renderers/CubeRenderTarget.hpp deleted file mode 100644 index fec6fe1e..00000000 --- a/Three.V8/renderers/CubeRenderTarget.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - - -class WrapperCubeRenderTarget -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void GetCubeImage(const v8::FunctionCallbackInfo& info); - static void GetHDRCubeImage(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperCubeRenderTarget::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "getCubeImage", v8::FunctionTemplate::New(isolate, GetCubeImage)); - templ->InstanceTemplate()->Set(isolate, "getHDRCubeImage", v8::FunctionTemplate::New(isolate, GetHDRCubeImage)); - return templ; -} - -void WrapperCubeRenderTarget::dtor(void* ptr, GameContext* ctx) -{ - delete (CubeRenderTarget*)ptr; -} - -void WrapperCubeRenderTarget::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - int width, height; - lctx.jnum_to_num(info[0], width); - lctx.jnum_to_num(info[1], height); - - CubeRenderTarget* self = new CubeRenderTarget(); - self->update_framebuffers(width, height); - - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperCubeRenderTarget::GetCubeImage(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - CubeRenderTarget* self = lctx.self(); - v8::Local holder_image = lctx.instantiate("CubeImage"); - CubeImage* image = lctx.jobj_to_obj(holder_image); - self->GetCubeImage(*image); - info.GetReturnValue().Set(holder_image); -} - -void WrapperCubeRenderTarget::GetHDRCubeImage(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - CubeRenderTarget* self = lctx.self(); - v8::Local holder_image = lctx.instantiate("HDRCubeImage"); - HDRCubeImage* image = lctx.jobj_to_obj(holder_image); - self->GetHDRCubeImage(*image); - info.GetReturnValue().Set(holder_image); -} diff --git a/Three.V8/renderers/GLRenderTarget.hpp b/Three.V8/renderers/GLRenderTarget.hpp deleted file mode 100644 index e6a72278..00000000 --- a/Three.V8/renderers/GLRenderTarget.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - - -class WrapperGLRenderTarget -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void SetSize(const v8::FunctionCallbackInfo& info); - static void GetImage(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperGLRenderTarget::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "setSize", v8::FunctionTemplate::New(isolate, SetSize)); - templ->InstanceTemplate()->Set(isolate, "getImage", v8::FunctionTemplate::New(isolate, GetImage)); - return templ; -} - -void WrapperGLRenderTarget::dtor(void* ptr, GameContext* ctx) -{ - delete (GLRenderTarget*)ptr; -} - -void WrapperGLRenderTarget::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - int width, height; - lctx.jnum_to_num(info[0], width); - lctx.jnum_to_num(info[1], height); - - bool msaa = true; - if (info.Length() > 2) - { - msaa = info[2].As()->Value(); - } - - GLRenderTarget* self = new GLRenderTarget(false, msaa); - self->update_framebuffers(width, height); - - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperGLRenderTarget::SetSize(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - GLRenderTarget* self = lctx.self(); - int width, height; - lctx.jnum_to_num(info[0], width); - lctx.jnum_to_num(info[1], height); - self->update_framebuffers(width, height); -} - - -void WrapperGLRenderTarget::GetImage(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - GLRenderTarget* self = lctx.self(); - v8::Local holder_image = lctx.instantiate("Image"); - Image* image = lctx.jobj_to_obj(holder_image); - self->GetImage(*image); - info.GetReturnValue().Set(holder_image); -} diff --git a/Three.V8/renderers/WrapperCubeRenderTarget.cpp b/Three.V8/renderers/WrapperCubeRenderTarget.cpp new file mode 100644 index 00000000..ffcc5f08 --- /dev/null +++ b/Three.V8/renderers/WrapperCubeRenderTarget.cpp @@ -0,0 +1,54 @@ +#include "WrapperUtils.hpp" +#include +#include "WrapperCubeRenderTarget.h" + + +void WrapperCubeRenderTarget::define(ClassDefinition& cls) +{ + cls.name = "CubeRenderTarget"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"getCubeImage", GetCubeImage }, + {"getHDRCubeImage", GetHDRCubeImage }, + }; +} + +void* WrapperCubeRenderTarget::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + int width, height; + lctx.jnum_to_num(info[0], width); + lctx.jnum_to_num(info[1], height); + + CubeRenderTarget* self = new CubeRenderTarget(); + self->update_framebuffers(width, height); + return self; +} + +void WrapperCubeRenderTarget::dtor(void* ptr, GameContext* ctx) +{ + delete (CubeRenderTarget*)ptr; +} + +void WrapperCubeRenderTarget::GetCubeImage(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + CubeRenderTarget* self = lctx.self(); + v8::Local holder_image = lctx.instantiate("CubeImage"); + CubeImage* image = lctx.jobj_to_obj(holder_image); + self->GetCubeImage(*image); + info.GetReturnValue().Set(holder_image); +} + +void WrapperCubeRenderTarget::GetHDRCubeImage(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + CubeRenderTarget* self = lctx.self(); + v8::Local holder_image = lctx.instantiate("HDRCubeImage"); + HDRCubeImage* image = lctx.jobj_to_obj(holder_image); + self->GetHDRCubeImage(*image); + info.GetReturnValue().Set(holder_image); +} + + diff --git a/Three.V8/renderers/WrapperCubeRenderTarget.h b/Three.V8/renderers/WrapperCubeRenderTarget.h new file mode 100644 index 00000000..ecf1fae0 --- /dev/null +++ b/Three.V8/renderers/WrapperCubeRenderTarget.h @@ -0,0 +1,19 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperCubeRenderTarget +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetCubeImage(const v8::FunctionCallbackInfo& info); + static void GetHDRCubeImage(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/renderers/WrapperGLRenderTarget.cpp b/Three.V8/renderers/WrapperGLRenderTarget.cpp new file mode 100644 index 00000000..d761feff --- /dev/null +++ b/Three.V8/renderers/WrapperGLRenderTarget.cpp @@ -0,0 +1,60 @@ +#include "WrapperUtils.hpp" +#include +#include "WrapperGLRenderTarget.h" + + +void WrapperGLRenderTarget::define(ClassDefinition& cls) +{ + cls.name = "GLRenderTarget"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.methods = { + {"setSize", SetSize }, + {"getImage", GetImage }, + }; +} + +void* WrapperGLRenderTarget::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + int width, height; + lctx.jnum_to_num(info[0], width); + lctx.jnum_to_num(info[1], height); + + bool msaa = true; + if (info.Length() > 2) + { + msaa = info[2].As()->Value(); + } + + GLRenderTarget* self = new GLRenderTarget(false, msaa); + self->update_framebuffers(width, height); + return self; +} + +void WrapperGLRenderTarget::dtor(void* ptr, GameContext* ctx) +{ + delete (GLRenderTarget*)ptr; +} + +void WrapperGLRenderTarget::SetSize(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + GLRenderTarget* self = lctx.self(); + int width, height; + lctx.jnum_to_num(info[0], width); + lctx.jnum_to_num(info[1], height); + self->update_framebuffers(width, height); +} + + +void WrapperGLRenderTarget::GetImage(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + GLRenderTarget* self = lctx.self(); + v8::Local holder_image = lctx.instantiate("Image"); + Image* image = lctx.jobj_to_obj(holder_image); + self->GetImage(*image); + info.GetReturnValue().Set(holder_image); +} + diff --git a/Three.V8/renderers/WrapperGLRenderTarget.h b/Three.V8/renderers/WrapperGLRenderTarget.h new file mode 100644 index 00000000..177009ed --- /dev/null +++ b/Three.V8/renderers/WrapperGLRenderTarget.h @@ -0,0 +1,18 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperGLRenderTarget +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void SetSize(const v8::FunctionCallbackInfo& info); + static void GetImage(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/renderers/GLRenderer.hpp b/Three.V8/renderers/WrapperGLRenderer.cpp similarity index 73% rename from Three.V8/renderers/GLRenderer.hpp rename to Three.V8/renderers/WrapperGLRenderer.cpp index 9baf270c..b5ed5326 100644 --- a/Three.V8/renderers/GLRenderer.hpp +++ b/Three.V8/renderers/WrapperGLRenderer.cpp @@ -1,9 +1,8 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include #include +#include #include #if THREE_MM #include @@ -12,67 +11,36 @@ #include #endif -class WrapperGLRenderer -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void Render(const v8::FunctionCallbackInfo& info); - static void RenderCube(const v8::FunctionCallbackInfo& info); - static void UpdateProbe(const v8::FunctionCallbackInfo& info); - static void UpdateProbes(const v8::FunctionCallbackInfo& info); - - static void UpdateLightmap(const v8::FunctionCallbackInfo& info); - static void FilterLightmap(const v8::FunctionCallbackInfo& info); -// static void CompressLightmap(const v8::FunctionCallbackInfo& info); -// static void DecompressLightmap(const v8::FunctionCallbackInfo& info); - - static void GetUseSSAO(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetUseSSAO(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void RenderTexture(const v8::FunctionCallbackInfo& info); - - static void CreateHeight(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperGLRenderer::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +#include "WrapperGLRenderer.h" + +void WrapperGLRenderer::define(ClassDefinition& cls) { - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->Set(isolate, "render", v8::FunctionTemplate::New(isolate, Render)); - templ->InstanceTemplate()->Set(isolate, "renderCube", v8::FunctionTemplate::New(isolate, RenderCube)); - templ->InstanceTemplate()->Set(isolate, "updateProbe", v8::FunctionTemplate::New(isolate, UpdateProbe)); - templ->InstanceTemplate()->Set(isolate, "updateProbes", v8::FunctionTemplate::New(isolate, UpdateProbes)); - - templ->InstanceTemplate()->Set(isolate, "updateLightmap", v8::FunctionTemplate::New(isolate, UpdateLightmap)); - templ->InstanceTemplate()->Set(isolate, "filterLightmap", v8::FunctionTemplate::New(isolate, FilterLightmap)); -// templ->InstanceTemplate()->Set(isolate, "compressLightmap", v8::FunctionTemplate::New(isolate, CompressLightmap)); -// templ->InstanceTemplate()->Set(isolate, "decompressLightmap", v8::FunctionTemplate::New(isolate, DecompressLightmap)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "useSSAO").ToLocalChecked(), GetUseSSAO, SetUseSSAO); - - templ->InstanceTemplate()->Set(isolate, "renderTexture", v8::FunctionTemplate::New(isolate, RenderTexture)); - - templ->InstanceTemplate()->Set(isolate, "createHeight", v8::FunctionTemplate::New(isolate, CreateHeight)); - - return templ; + cls.name = "GLRenderer"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "useSSAO", GetUseSSAO, SetUseSSAO }, + }; + cls.methods = { + {"render", Render }, + {"renderCube", RenderCube }, + {"updateProbe", UpdateProbe }, + {"updateProbes", UpdateProbes }, + {"updateLightmap", UpdateLightmap }, + {"filterLightmap", FilterLightmap }, + {"renderTexture", RenderTexture }, + {"createHeight", CreateHeight }, + }; } -void WrapperGLRenderer::dtor(void* ptr, GameContext* ctx) +void* WrapperGLRenderer::ctor(const v8::FunctionCallbackInfo& info) { - delete (GLRenderer*)ptr; + return new GLRenderer; } -void WrapperGLRenderer::New(const v8::FunctionCallbackInfo& info) +void WrapperGLRenderer::dtor(void* ptr, GameContext* ctx) { - LocalContext lctx(info); - GLRenderer* self = new GLRenderer(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); + delete (GLRenderer*)ptr; } void WrapperGLRenderer::Render(const v8::FunctionCallbackInfo& info) @@ -83,8 +51,8 @@ void WrapperGLRenderer::Render(const v8::FunctionCallbackInfo& info) Camera* camera = lctx.jobj_to_obj(info[1]); if (info.Length() < 3) - { - GamePlayer* player = lctx.player(); + { + GamePlayer* player = lctx.player(); self->render(*scene, *camera, player->renderTarget()); if (player->Picking()) @@ -103,7 +71,7 @@ void WrapperGLRenderer::Render(const v8::FunctionCallbackInfo& info) } else if (clsname == "GLRenderTarget") { - GLRenderTarget* target = lctx.jobj_to_obj(holder_viewer); + GLRenderTarget* target = lctx.jobj_to_obj(holder_viewer); self->render(*scene, *camera, *target); } } @@ -209,7 +177,7 @@ void WrapperGLRenderer::UpdateProbes(const v8::FunctionCallbackInfo& { ProbeGrid* probe_grid = lctx.jobj_to_obj(holder_grid); num_probes = self->updateProbes(*scene, *probe_grid, start_idx, num_directions, rate_vis, rate_irr); - + } else if (clsname == "LODProbeGrid") { @@ -250,8 +218,8 @@ void WrapperGLRenderer::UpdateLightmap(const v8::FunctionCallbackInfo void WrapperGLRenderer::FilterLightmap(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - GLRenderer* self = lctx.self(); - GLTFModel* model = lctx.jobj_to_obj(info[0]); + GLRenderer* self = lctx.self(); + GLTFModel* model = lctx.jobj_to_obj(info[0]); self->filterLightmap(*model->lightmap, *model->lightmap_target, model->matrixWorld); } @@ -383,7 +351,7 @@ void WrapperGLRenderer::RenderTexture(const v8::FunctionCallbackInfo& target = lctx.jobj_to_obj(holder_viewer); } } - + self->renderTexture(tex, x, y, width, height, *target, flipY, alpha); } diff --git a/Three.V8/renderers/WrapperGLRenderer.h b/Three.V8/renderers/WrapperGLRenderer.h new file mode 100644 index 00000000..1bab2ddf --- /dev/null +++ b/Three.V8/renderers/WrapperGLRenderer.h @@ -0,0 +1,33 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperGLRenderer +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void Render(const v8::FunctionCallbackInfo& info); + static void RenderCube(const v8::FunctionCallbackInfo& info); + static void UpdateProbe(const v8::FunctionCallbackInfo& info); + static void UpdateProbes(const v8::FunctionCallbackInfo& info); + + static void UpdateLightmap(const v8::FunctionCallbackInfo& info); + static void FilterLightmap(const v8::FunctionCallbackInfo& info); + // static void CompressLightmap(const v8::FunctionCallbackInfo& info); + // static void DecompressLightmap(const v8::FunctionCallbackInfo& info); + + static void GetUseSSAO(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetUseSSAO(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void RenderTexture(const v8::FunctionCallbackInfo& info); + + static void CreateHeight(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/savers/FileSaver.hpp b/Three.V8/savers/WrapperFileSaver.cpp similarity index 59% rename from Three.V8/savers/FileSaver.hpp rename to Three.V8/savers/WrapperFileSaver.cpp index e099c681..9ed6b45a 100644 --- a/Three.V8/savers/FileSaver.hpp +++ b/Three.V8/savers/WrapperFileSaver.cpp @@ -1,26 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include -class WrapperFileSaver -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void SaveBinaryFile(const v8::FunctionCallbackInfo& info); - static void SaveTextFile(const v8::FunctionCallbackInfo& info); - -}; +#include "WrapperFileSaver.h" -v8::Local WrapperFileSaver::create_template(v8::Isolate* isolate) +void WrapperFileSaver::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "saveBinaryFile", v8::FunctionTemplate::New(isolate, SaveBinaryFile)); - templ->Set(isolate, "saveTextFile", v8::FunctionTemplate::New(isolate, SaveTextFile)); - return templ; + object.name = "fileSaver"; + object.methods = { + { "saveBinaryFile", SaveBinaryFile}, + { "saveTextFile", SaveTextFile}, + }; } void WrapperFileSaver::SaveBinaryFile(const v8::FunctionCallbackInfo& info) @@ -35,7 +25,7 @@ void WrapperFileSaver::SaveBinaryFile(const v8::FunctionCallbackInfo& } v8::Local data = info[1].As(); - const unsigned char* p_data = (const unsigned char* )data->GetBackingStore()->Data(); + const unsigned char* p_data = (const unsigned char*)data->GetBackingStore()->Data(); size_t size = data->ByteLength(); ::SaveBinaryFile(filename.c_str(), p_data, size); diff --git a/Three.V8/savers/WrapperFileSaver.h b/Three.V8/savers/WrapperFileSaver.h new file mode 100644 index 00000000..a7e10a5e --- /dev/null +++ b/Three.V8/savers/WrapperFileSaver.h @@ -0,0 +1,14 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperFileSaver +{ +public: + static void define(ObjectDefinition& object); + +private: + static void SaveBinaryFile(const v8::FunctionCallbackInfo& info); + static void SaveTextFile(const v8::FunctionCallbackInfo& info); + +}; diff --git a/Three.V8/savers/HDRImageSaver.hpp b/Three.V8/savers/WrapperHDRImageSaver.cpp similarity index 67% rename from Three.V8/savers/HDRImageSaver.hpp rename to Three.V8/savers/WrapperHDRImageSaver.cpp index 9abaef85..ec3de431 100644 --- a/Three.V8/savers/HDRImageSaver.hpp +++ b/Three.V8/savers/WrapperHDRImageSaver.cpp @@ -1,26 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include -class WrapperHDRImageSaver -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void SaveFile(const v8::FunctionCallbackInfo& info); - static void SaveCubeToFile(const v8::FunctionCallbackInfo& info); -}; - +#include "WrapperHDRImageSaver.h" -v8::Local WrapperHDRImageSaver::create_template(v8::Isolate* isolate) +void WrapperHDRImageSaver::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "saveFile", v8::FunctionTemplate::New(isolate, SaveFile)); - templ->Set(isolate, "saveCubeToFile", v8::FunctionTemplate::New(isolate, SaveCubeToFile)); - return templ; + object.name = "HDRImageSaver"; + object.methods = { + { "saveFile", SaveFile}, + { "saveCubeToFile", SaveCubeToFile}, + }; } void WrapperHDRImageSaver::SaveFile(const v8::FunctionCallbackInfo& info) @@ -53,7 +43,7 @@ void WrapperHDRImageSaver::SaveCubeToFile(const v8::FunctionCallbackInfo& info); + static void SaveCubeToFile(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/savers/ImageSaver.hpp b/Three.V8/savers/WrapperImageSaver.cpp similarity index 63% rename from Three.V8/savers/ImageSaver.hpp rename to Three.V8/savers/WrapperImageSaver.cpp index 7d1d6239..d4ee6b2b 100644 --- a/Three.V8/savers/ImageSaver.hpp +++ b/Three.V8/savers/WrapperImageSaver.cpp @@ -1,26 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include -class WrapperImageSaver -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void SaveFile(const v8::FunctionCallbackInfo& info); - static void SaveCubeToFile(const v8::FunctionCallbackInfo& info); -}; - +#include "WrapperImageSaver.h" -v8::Local WrapperImageSaver::create_template(v8::Isolate* isolate) +void WrapperImageSaver::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "saveFile", v8::FunctionTemplate::New(isolate, SaveFile)); - templ->Set(isolate, "saveCubeToFile", v8::FunctionTemplate::New(isolate, SaveCubeToFile)); - return templ; + object.name = "imageSaver"; + object.methods = { + { "saveFile", SaveFile}, + { "saveCubeToFile", SaveCubeToFile}, + }; } void WrapperImageSaver::SaveFile(const v8::FunctionCallbackInfo& info) @@ -43,7 +33,7 @@ void WrapperImageSaver::SaveFile(const v8::FunctionCallbackInfo& info void WrapperImageSaver::SaveCubeToFile(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - CubeImage* self = lctx.jobj_to_obj(info[0]); + CubeImage* self = lctx.jobj_to_obj(info[0]); std::string filenames[6] = { lctx.jstr_to_str(info[1]), @@ -53,7 +43,7 @@ void WrapperImageSaver::SaveCubeToFile(const v8::FunctionCallbackInfo lctx.jstr_to_str(info[5]), lctx.jstr_to_str(info[6]) }; - + for (int i = 0; i < 6; i++) { if (!writable_test(filenames[i].c_str())) @@ -63,9 +53,8 @@ void WrapperImageSaver::SaveCubeToFile(const v8::FunctionCallbackInfo } } - ImageSaver::SaveCubeToFile(self, filenames[0].c_str(), filenames[1].c_str(), + ImageSaver::SaveCubeToFile(self, filenames[0].c_str(), filenames[1].c_str(), filenames[2].c_str(), filenames[3].c_str(), filenames[4].c_str(), filenames[5].c_str()); info.GetReturnValue().Set(v8::Boolean::New(lctx.isolate, true)); } - diff --git a/Three.V8/savers/WrapperImageSaver.h b/Three.V8/savers/WrapperImageSaver.h new file mode 100644 index 00000000..1f1552d7 --- /dev/null +++ b/Three.V8/savers/WrapperImageSaver.h @@ -0,0 +1,13 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperImageSaver +{ +public: + static void define(ObjectDefinition& object); + +private: + static void SaveFile(const v8::FunctionCallbackInfo& info); + static void SaveCubeToFile(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/savers/LODProbeGridSaver.hpp b/Three.V8/savers/WrapperLODProbeGridSaver.cpp similarity index 54% rename from Three.V8/savers/LODProbeGridSaver.hpp rename to Three.V8/savers/WrapperLODProbeGridSaver.cpp index 5deccb0f..48c15309 100644 --- a/Three.V8/savers/LODProbeGridSaver.hpp +++ b/Three.V8/savers/WrapperLODProbeGridSaver.cpp @@ -1,25 +1,15 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include -class WrapperLODProbeGridSaver -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void SaveFile(const v8::FunctionCallbackInfo& info); -}; - - +#include "WrapperLODProbeGridSaver.h" -v8::Local WrapperLODProbeGridSaver::create_template(v8::Isolate* isolate) +void WrapperLODProbeGridSaver::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "saveFile", v8::FunctionTemplate::New(isolate, SaveFile)); - return templ; + object.name = "LODProbeGridSaver"; + object.methods = { + { "saveFile", SaveFile}, + }; } void WrapperLODProbeGridSaver::SaveFile(const v8::FunctionCallbackInfo& info) diff --git a/Three.V8/savers/WrapperLODProbeGridSaver.h b/Three.V8/savers/WrapperLODProbeGridSaver.h new file mode 100644 index 00000000..d978487e --- /dev/null +++ b/Three.V8/savers/WrapperLODProbeGridSaver.h @@ -0,0 +1,12 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperLODProbeGridSaver +{ +public: + static void define(ObjectDefinition& object); + +private: + static void SaveFile(const v8::FunctionCallbackInfo& info); +}; diff --git a/Three.V8/savers/ProbeGridSaver.hpp b/Three.V8/savers/WrapperProbeGridSaver.cpp similarity index 54% rename from Three.V8/savers/ProbeGridSaver.hpp rename to Three.V8/savers/WrapperProbeGridSaver.cpp index 52addf24..774300dd 100644 --- a/Three.V8/savers/ProbeGridSaver.hpp +++ b/Three.V8/savers/WrapperProbeGridSaver.cpp @@ -1,24 +1,15 @@ -#pragma once - #include "WrapperUtils.hpp" #include #include -class WrapperProbeGridSaver -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void SaveFile(const v8::FunctionCallbackInfo& info); -}; +#include "WrapperProbeGridSaver.h" - -v8::Local WrapperProbeGridSaver::create_template(v8::Isolate* isolate) +void WrapperProbeGridSaver::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "saveFile", v8::FunctionTemplate::New(isolate, SaveFile)); - return templ; + object.name = "probeGridSaver"; + object.methods = { + { "saveFile", SaveFile}, + }; } void WrapperProbeGridSaver::SaveFile(const v8::FunctionCallbackInfo& info) @@ -38,3 +29,4 @@ void WrapperProbeGridSaver::SaveFile(const v8::FunctionCallbackInfo& info.GetReturnValue().Set(v8::Boolean::New(lctx.isolate, true)); } + diff --git a/Three.V8/savers/WrapperProbeGridSaver.h b/Three.V8/savers/WrapperProbeGridSaver.h new file mode 100644 index 00000000..a970a47a --- /dev/null +++ b/Three.V8/savers/WrapperProbeGridSaver.h @@ -0,0 +1,13 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperProbeGridSaver +{ +public: + static void define(ObjectDefinition& object); + +private: + static void SaveFile(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/scenes/Fog.hpp b/Three.V8/scenes/Fog.hpp deleted file mode 100644 index b6d505c5..00000000 --- a/Three.V8/scenes/Fog.hpp +++ /dev/null @@ -1,136 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include "scenes/Fog.h" - -class WrapperFog -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetColor(const v8::FunctionCallbackInfo& info); - static void SetColor(const v8::FunctionCallbackInfo& info); - - static void GetDensity(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetDensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetMaxNumSteps(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetMaxNumSteps(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetMinStep(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetMinStep(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - -}; - - -v8::Local WrapperFog::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "color").ToLocalChecked(), GetColor, 0); - templ->InstanceTemplate()->Set(isolate, "getColor", v8::FunctionTemplate::New(isolate, GetColor)); - templ->InstanceTemplate()->Set(isolate, "setColor", v8::FunctionTemplate::New(isolate, SetColor)); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "density").ToLocalChecked(), GetDensity, SetDensity); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "maxNumSteps").ToLocalChecked(), GetMaxNumSteps, SetMaxNumSteps); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "minStep").ToLocalChecked(), GetMinStep, SetMinStep); - - return templ; -} - -void WrapperFog::dtor(void* ptr, GameContext* ctx) -{ - delete (Fog*)ptr; -} - - -void WrapperFog::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = new Fog(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperFog::dtor); -} - -void WrapperFog::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - v8::Local position = v8::Object::New(lctx.isolate); - lctx.vec3_to_jvec3(self->color, position); - info.GetReturnValue().Set(position); -} - -void WrapperFog::GetColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - lctx.vec3_to_jvec3(self->color, info[0]); - info.GetReturnValue().Set(info[0]); -} - -void WrapperFog::SetColor(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - if (info[0]->IsNumber()) - { - lctx.jnum_to_num(info[0], self->color.x); - lctx.jnum_to_num(info[1], self->color.y); - lctx.jnum_to_num(info[2], self->color.z); - } - else - { - lctx.jvec3_to_vec3(info[0], self->color); - } -} - -void WrapperFog::GetDensity(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->density)); -} - -void WrapperFog::SetDensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - lctx.jnum_to_num(value, self->density); -} - - -void WrapperFog::GetMaxNumSteps(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->max_num_steps)); -} - -void WrapperFog::SetMaxNumSteps(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - lctx.jnum_to_num(value, self->max_num_steps); -} - - -void WrapperFog::GetMinStep(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->min_step)); -} - -void WrapperFog::SetMinStep(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Fog* self = lctx.self(); - lctx.jnum_to_num(value, self->min_step); -} diff --git a/Three.V8/scenes/WrapperFog.cpp b/Three.V8/scenes/WrapperFog.cpp new file mode 100644 index 00000000..2fc350e0 --- /dev/null +++ b/Three.V8/scenes/WrapperFog.cpp @@ -0,0 +1,108 @@ +#include "WrapperUtils.hpp" +#include "scenes/Fog.h" +#include "WrapperFog.h" + +void WrapperFog::define(ClassDefinition& cls) +{ + cls.name = "Fog"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "color", GetColor }, + { "density", GetDensity, SetDensity }, + { "maxNumSteps", GetMaxNumSteps, SetMaxNumSteps }, + { "minStep", GetMinStep, SetMinStep }, + }; + cls.methods = { + {"getColor", GetColor }, + {"setColor", SetColor }, + }; +} + +void* WrapperFog::ctor(const v8::FunctionCallbackInfo& info) +{ + return new Fog; +} + +void WrapperFog::dtor(void* ptr, GameContext* ctx) +{ + delete (Fog*)ptr; +} + +void WrapperFog::GetColor(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + v8::Local position = v8::Object::New(lctx.isolate); + lctx.vec3_to_jvec3(self->color, position); + info.GetReturnValue().Set(position); +} + +void WrapperFog::GetColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + lctx.vec3_to_jvec3(self->color, info[0]); + info.GetReturnValue().Set(info[0]); +} + +void WrapperFog::SetColor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + if (info[0]->IsNumber()) + { + lctx.jnum_to_num(info[0], self->color.x); + lctx.jnum_to_num(info[1], self->color.y); + lctx.jnum_to_num(info[2], self->color.z); + } + else + { + lctx.jvec3_to_vec3(info[0], self->color); + } +} + +void WrapperFog::GetDensity(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->density)); +} + +void WrapperFog::SetDensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + lctx.jnum_to_num(value, self->density); +} + + +void WrapperFog::GetMaxNumSteps(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->max_num_steps)); +} + +void WrapperFog::SetMaxNumSteps(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + lctx.jnum_to_num(value, self->max_num_steps); +} + + +void WrapperFog::GetMinStep(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->min_step)); +} + +void WrapperFog::SetMinStep(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Fog* self = lctx.self(); + lctx.jnum_to_num(value, self->min_step); +} + diff --git a/Three.V8/scenes/WrapperFog.h b/Three.V8/scenes/WrapperFog.h new file mode 100644 index 00000000..a368baec --- /dev/null +++ b/Three.V8/scenes/WrapperFog.h @@ -0,0 +1,31 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + + +class WrapperFog +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetColor(const v8::FunctionCallbackInfo& info); + static void SetColor(const v8::FunctionCallbackInfo& info); + + static void GetDensity(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetDensity(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetMaxNumSteps(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetMaxNumSteps(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetMinStep(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetMinStep(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + +}; + diff --git a/Three.V8/scenes/Scene.hpp b/Three.V8/scenes/WrapperScene.cpp similarity index 62% rename from Three.V8/scenes/Scene.hpp rename to Three.V8/scenes/WrapperScene.cpp index 6d301e51..42e56c9b 100644 --- a/Three.V8/scenes/Scene.hpp +++ b/Three.V8/scenes/WrapperScene.cpp @@ -1,62 +1,42 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include #include #include #include -class WrapperScene -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void GetBackground(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetBackground(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetIndirectLight(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetIndirectLight(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetFog(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetFog(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +#include "WrapperScene.h" - static void GetWidgets(v8::Local property, const v8::PropertyCallbackInfo& info); - - static void AddWidget(const v8::FunctionCallbackInfo& info); - static void RemoveWidget(const v8::FunctionCallbackInfo& info); - static void ClearWidgets(const v8::FunctionCallbackInfo& info); - - static void GetBoundingBox(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperScene::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperScene::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "background").ToLocalChecked(), GetBackground, SetBackground); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "indirectLight").ToLocalChecked(), GetIndirectLight, SetIndirectLight); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "fog").ToLocalChecked(), GetFog, SetFog); - - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "widgets").ToLocalChecked(), GetWidgets, 0); - templ->InstanceTemplate()->Set(isolate, "addWidget", v8::FunctionTemplate::New(isolate, AddWidget)); - templ->InstanceTemplate()->Set(isolate, "removeWidget", v8::FunctionTemplate::New(isolate, RemoveWidget)); - templ->InstanceTemplate()->Set(isolate, "clearWidget", v8::FunctionTemplate::New(isolate, ClearWidgets)); - - templ->InstanceTemplate()->Set(isolate, "getBoundingBox", v8::FunctionTemplate::New(isolate, GetBoundingBox)); - - return templ; + WrapperObject3D::define(cls); + cls.name = "Scene"; + cls.ctor = ctor; + + std::vector props = { + { "background", GetBackground, SetBackground }, + { "indirectLight", GetIndirectLight, SetIndirectLight }, + { "fog", GetFog, SetFog }, + { "widgets", GetWidgets }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"addWidget", AddWidget }, + {"removeWidget", RemoveWidget }, + {"clearWidget", ClearWidgets }, + {"getBoundingBox", GetBoundingBox }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperScene::New(const v8::FunctionCallbackInfo& info) + +void* WrapperScene::ctor(const v8::FunctionCallbackInfo& info) { - LocalContext lctx(info); - Scene* self = new Scene(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new Scene; } + void WrapperScene::GetBackground(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); @@ -79,7 +59,7 @@ void WrapperScene::SetBackground(v8::Local property, v8::Localbackground = nullptr; } lctx.set_property(info.Holder(), "_background", value); - + } @@ -119,10 +99,10 @@ void WrapperScene::SetFog(v8::Local property, v8::Local v const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); - Scene* self = lctx.self(); + Scene* self = lctx.self(); if (!value->IsNull()) { - Fog* fog = lctx.jobj_to_obj(value); + Fog* fog = lctx.jobj_to_obj(value); self->fog = fog; } else @@ -177,7 +157,7 @@ void WrapperScene::RemoveWidget(const v8::FunctionCallbackInfo& info) { v8::Local obj_i = widgets->Get(lctx.context, i).ToLocalChecked().As(); if (obj_i == holder_object) - { + { for (unsigned j = i; j < widgets->Length() - 1; j++) { widgets->Set(lctx.context, j, widgets->Get(lctx.context, j + 1).ToLocalChecked()); @@ -193,7 +173,7 @@ void WrapperScene::RemoveWidget(const v8::FunctionCallbackInfo& info) void WrapperScene::ClearWidgets(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); - Scene* self = lctx.self(); + Scene* self = lctx.self(); self->clear_widgets(); v8::Local holder = info.Holder(); @@ -201,7 +181,7 @@ void WrapperScene::ClearWidgets(const v8::FunctionCallbackInfo& info) for (unsigned i = 0; i < widgets->Length(); i++) { - v8::Local obj_i = widgets->Get(lctx.context, i).ToLocalChecked().As(); + v8::Local obj_i = widgets->Get(lctx.context, i).ToLocalChecked().As(); widgets->Delete(lctx.context, i); } lctx.set_property(widgets, "length", lctx.num_to_jnum(0)); diff --git a/Three.V8/scenes/WrapperScene.h b/Three.V8/scenes/WrapperScene.h new file mode 100644 index 00000000..64743e92 --- /dev/null +++ b/Three.V8/scenes/WrapperScene.h @@ -0,0 +1,30 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperScene +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetBackground(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetBackground(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetIndirectLight(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetIndirectLight(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetFog(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetFog(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetWidgets(v8::Local property, const v8::PropertyCallbackInfo& info); + + static void AddWidget(const v8::FunctionCallbackInfo& info); + static void RemoveWidget(const v8::FunctionCallbackInfo& info); + static void ClearWidgets(const v8::FunctionCallbackInfo& info); + + static void GetBoundingBox(const v8::FunctionCallbackInfo& info); +}; + diff --git a/Three.V8/utils/DDSImage.hpp b/Three.V8/utils/DDSImage.hpp deleted file mode 100644 index 878d02b5..00000000 --- a/Three.V8/utils/DDSImage.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperDDSImage -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - -v8::Local WrapperDDSImage::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - -void WrapperDDSImage::dtor(void* ptr, GameContext* ctx) -{ - delete (DDSImage*)ptr; -} - -void WrapperDDSImage::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - DDSImage* self = new DDSImage(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperDDSImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - DDSImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); -} - -void WrapperDDSImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - DDSImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); -} diff --git a/Three.V8/utils/HDRImage.hpp b/Three.V8/utils/HDRImage.hpp deleted file mode 100644 index 54eed29e..00000000 --- a/Three.V8/utils/HDRImage.hpp +++ /dev/null @@ -1,115 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperHDRImage -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - -v8::Local WrapperHDRImage::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - -void WrapperHDRImage::dtor(void* ptr, GameContext* ctx) -{ - delete (HDRImage*)ptr; -} - -void WrapperHDRImage::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HDRImage* self = nullptr; - if (info.Length() > 1) - { - int width, height; - lctx.jnum_to_num(info[0], width); - lctx.jnum_to_num(info[1], height); - self = new HDRImage(width, height); - } - else - { - self = new HDRImage(); - } - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperHDRImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - HDRImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); -} - -void WrapperHDRImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - HDRImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); -} - -class WrapperHDRCubeImage -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperHDRCubeImage::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - - -void WrapperHDRCubeImage::dtor(void* ptr, GameContext* ctx) -{ - delete (HDRCubeImage*)ptr; -} - -void WrapperHDRCubeImage::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - HDRCubeImage* self = new HDRCubeImage(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperHDRCubeImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - HDRCubeImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].width())); -} - -void WrapperHDRCubeImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - HDRCubeImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].height())); -} diff --git a/Three.V8/utils/Image.hpp b/Three.V8/utils/Image.hpp deleted file mode 100644 index 8cb667b4..00000000 --- a/Three.V8/utils/Image.hpp +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperImage -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperImage::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - -void WrapperImage::dtor(void* ptr, GameContext* ctx) -{ - delete (Image*)ptr; -} - -void WrapperImage::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - Image* self = nullptr; - if (info.Length() > 1) - { - int width, height; - lctx.jnum_to_num(info[0], width); - lctx.jnum_to_num(info[1], height); - self = new Image(width, height); - } - else - { - self = new Image(); - } - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Image* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); -} - -void WrapperImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - Image* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); -} - -class WrapperCubeImage -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - -private: - static void dtor(void* ptr, GameContext* ctx); - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperCubeImage::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - return templ; -} - - -void WrapperCubeImage::dtor(void* ptr, GameContext* ctx) -{ - delete (CubeImage*)ptr; -} - -void WrapperCubeImage::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - CubeImage* self = new CubeImage(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - -void WrapperCubeImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - CubeImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].width())); -} - -void WrapperCubeImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - CubeImage* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].height())); -} diff --git a/Three.V8/utils/WrapperDDSImage.cpp b/Three.V8/utils/WrapperDDSImage.cpp new file mode 100644 index 00000000..232cf5c2 --- /dev/null +++ b/Three.V8/utils/WrapperDDSImage.cpp @@ -0,0 +1,40 @@ +#include "WrapperUtils.hpp" +#include +#include "WrapperDDSImage.h" + +void WrapperDDSImage::define(ClassDefinition& cls) +{ + cls.name = "DDSImage"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; + +} + +void* WrapperDDSImage::ctor(const v8::FunctionCallbackInfo& info) +{ + return new DDSImage; +} + +void WrapperDDSImage::dtor(void* ptr, GameContext* ctx) +{ + delete (DDSImage*)ptr; +} + +void WrapperDDSImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + DDSImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); +} + +void WrapperDDSImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + DDSImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); +} + diff --git a/Three.V8/utils/WrapperDDSImage.h b/Three.V8/utils/WrapperDDSImage.h new file mode 100644 index 00000000..d115a8f5 --- /dev/null +++ b/Three.V8/utils/WrapperDDSImage.h @@ -0,0 +1,20 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperDDSImage +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; + + diff --git a/Three.V8/utils/WrapperHDRImage.cpp b/Three.V8/utils/WrapperHDRImage.cpp new file mode 100644 index 00000000..fe7145a0 --- /dev/null +++ b/Three.V8/utils/WrapperHDRImage.cpp @@ -0,0 +1,88 @@ +#include "WrapperUtils.hpp" +#include +#include "WrapperHDRImage.h" + +void WrapperHDRImage::define(ClassDefinition& cls) +{ + cls.name = "HDRImage"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; + +} + +void* WrapperHDRImage::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + HDRImage* self = nullptr; + if (info.Length() > 1) + { + int width, height; + lctx.jnum_to_num(info[0], width); + lctx.jnum_to_num(info[1], height); + self = new HDRImage(width, height); + } + else + { + self = new HDRImage(); + } + return self; +} + +void WrapperHDRImage::dtor(void* ptr, GameContext* ctx) +{ + delete (HDRImage*)ptr; +} + +void WrapperHDRImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + HDRImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); +} + +void WrapperHDRImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + HDRImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); +} + +void WrapperHDRCubeImage::define(ClassDefinition& cls) +{ + cls.name = "HDRCubeImage"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; +} + +void* WrapperHDRCubeImage::ctor(const v8::FunctionCallbackInfo& info) +{ + return new HDRCubeImage; +} + +void WrapperHDRCubeImage::dtor(void* ptr, GameContext* ctx) +{ + delete (HDRCubeImage*)ptr; +} + + +void WrapperHDRCubeImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + HDRCubeImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].width())); +} + +void WrapperHDRCubeImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + HDRCubeImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].height())); +} diff --git a/Three.V8/utils/WrapperHDRImage.h b/Three.V8/utils/WrapperHDRImage.h new file mode 100644 index 00000000..870b34df --- /dev/null +++ b/Three.V8/utils/WrapperHDRImage.h @@ -0,0 +1,31 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperHDRImage +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; + +class WrapperHDRCubeImage +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/utils/WrapperImage.cpp b/Three.V8/utils/WrapperImage.cpp new file mode 100644 index 00000000..bdf18b91 --- /dev/null +++ b/Three.V8/utils/WrapperImage.cpp @@ -0,0 +1,88 @@ +#include "WrapperUtils.hpp" +#include +#include "WrapperImage.h" + +void WrapperImage::define(ClassDefinition& cls) +{ + cls.name = "Image"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; + +} + +void* WrapperImage::ctor(const v8::FunctionCallbackInfo& info) +{ + LocalContext lctx(info); + Image* self = nullptr; + if (info.Length() > 1) + { + int width, height; + lctx.jnum_to_num(info[0], width); + lctx.jnum_to_num(info[1], height); + self = new Image(width, height); + } + else + { + self = new Image(); + } + return self; +} + +void WrapperImage::dtor(void* ptr, GameContext* ctx) +{ + delete (Image*)ptr; +} + +void WrapperImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Image* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->width())); +} + +void WrapperImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + Image* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->height())); +} + +void WrapperCubeImage::define(ClassDefinition& cls) +{ + cls.name = "CubeImage"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + }; + +} + +void* WrapperCubeImage::ctor(const v8::FunctionCallbackInfo& info) +{ + return new CubeImage; +} + +void WrapperCubeImage::dtor(void* ptr, GameContext* ctx) +{ + delete (CubeImage*)ptr; +} + +void WrapperCubeImage::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + CubeImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].width())); +} + +void WrapperCubeImage::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + CubeImage* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->images[0].height())); +} diff --git a/Three.V8/utils/WrapperImage.h b/Three.V8/utils/WrapperImage.h new file mode 100644 index 00000000..6b0a873b --- /dev/null +++ b/Three.V8/utils/WrapperImage.h @@ -0,0 +1,32 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperImage +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; + + +class WrapperCubeImage +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); +}; diff --git a/Three.V8/utils/Text.hpp b/Three.V8/utils/WrapperText.cpp similarity index 55% rename from Three.V8/utils/Text.hpp rename to Three.V8/utils/WrapperText.cpp index 08e50709..0242371b 100644 --- a/Three.V8/utils/Text.hpp +++ b/Three.V8/utils/WrapperText.cpp @@ -1,24 +1,14 @@ -#pragma once - #include "WrapperUtils.hpp" +#include "WrapperText.h" -class WrapperText -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void ToUTF8Buffer(const v8::FunctionCallbackInfo& info); - static void FromUTF8Buffer(const v8::FunctionCallbackInfo& info); -}; - -v8::Local WrapperText::create_template(v8::Isolate* isolate) +void WrapperText::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "toUTF8Buffer", v8::FunctionTemplate::New(isolate, ToUTF8Buffer)); - templ->Set(isolate, "fromUTF8Buffer", v8::FunctionTemplate::New(isolate, FromUTF8Buffer)); - return templ; + object.name = "text"; + object.methods = { + { "toUTF8Buffer", ToUTF8Buffer}, + { "fromUTF8Buffer", FromUTF8Buffer}, + }; } void WrapperText::ToUTF8Buffer(const v8::FunctionCallbackInfo& info) @@ -28,7 +18,7 @@ void WrapperText::ToUTF8Buffer(const v8::FunctionCallbackInfo& info) v8::Local buf = v8::ArrayBuffer::New(lctx.isolate, text.length()); memcpy(buf->GetBackingStore()->Data(), text.data(), text.length()); - + info.GetReturnValue().Set(buf); } diff --git a/Three.V8/utils/WrapperText.h b/Three.V8/utils/WrapperText.h new file mode 100644 index 00000000..82cb2ae3 --- /dev/null +++ b/Three.V8/utils/WrapperText.h @@ -0,0 +1,15 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperText +{ +public: + static void define(ObjectDefinition& object); + +private: + static void ToUTF8Buffer(const v8::FunctionCallbackInfo& info); + static void FromUTF8Buffer(const v8::FunctionCallbackInfo& info); + +}; + diff --git a/Three.V8/volume/VolumeData.hpp b/Three.V8/volume/VolumeData.hpp deleted file mode 100644 index 2c1d0103..00000000 --- a/Three.V8/volume/VolumeData.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include "WrapperUtils.hpp" -#include - -class WrapperVolumeData -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - static void dtor(void* ptr, GameContext* ctx); - -private: - static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetDepth(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetSpacing(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetBytesPerPixel(v8::Local property, const v8::PropertyCallbackInfo& info); - -}; - -v8::Local WrapperVolumeData::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) -{ - v8::Local templ = v8::FunctionTemplate::New(isolate, constructor); - templ->InstanceTemplate()->SetInternalFieldCount(2); - - templ->InstanceTemplate()->Set(isolate, "dispose", v8::FunctionTemplate::New(isolate, GeneralDispose)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "width").ToLocalChecked(), GetWidth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "height").ToLocalChecked(), GetHeight, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "depth").ToLocalChecked(), GetDepth, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "spacing").ToLocalChecked(), GetSpacing, 0); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "bytesPerPixel").ToLocalChecked(), GetBytesPerPixel, 0); - - return templ; -} - - -void WrapperVolumeData::dtor(void* ptr, GameContext* ctx) -{ - delete (VolumeData*)ptr; -} - -void WrapperVolumeData::New(const v8::FunctionCallbackInfo& info) -{ - LocalContext lctx(info); - VolumeData* self = new VolumeData(); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), dtor); -} - - -void WrapperVolumeData::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - VolumeData* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->size.x)); -} - -void WrapperVolumeData::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - VolumeData* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->size.y)); -} - -void WrapperVolumeData::GetDepth(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - VolumeData* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->size.z)); -} - -void WrapperVolumeData::GetSpacing(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - VolumeData* self = lctx.self(); - - v8::Local obj = v8::Object::New(lctx.isolate); - lctx.vec3_to_jvec3(self->spacing, obj); - info.GetReturnValue().Set(obj); -} - - -void WrapperVolumeData::GetBytesPerPixel(v8::Local property, const v8::PropertyCallbackInfo& info) -{ - LocalContext lctx(info); - VolumeData* self = lctx.self(); - info.GetReturnValue().Set(lctx.num_to_jnum(self->bytes_per_pixel)); -} diff --git a/Three.V8/volume/WrapperVolumeData.cpp b/Three.V8/volume/WrapperVolumeData.cpp new file mode 100644 index 00000000..5a739bec --- /dev/null +++ b/Three.V8/volume/WrapperVolumeData.cpp @@ -0,0 +1,68 @@ +#include "WrapperUtils.hpp" +#include + +#include "WrapperVolumeData.h" + +void WrapperVolumeData::define(ClassDefinition& cls) +{ + cls.name = "VolumeData"; + cls.ctor = ctor; + cls.dtor = dtor; + cls.properties = { + { "width", GetWidth }, + { "height", GetHeight }, + { "depth", GetDepth }, + { "spacing", GetSpacing }, + { "bytesPerPixel", GetBytesPerPixel }, + }; + +} + +void* WrapperVolumeData::ctor(const v8::FunctionCallbackInfo& info) +{ + return new VolumeData; +} + +void WrapperVolumeData::dtor(void* ptr, GameContext* ctx) +{ + delete (VolumeData*)ptr; +} + +void WrapperVolumeData::GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + VolumeData* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->size.x)); +} + +void WrapperVolumeData::GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + VolumeData* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->size.y)); +} + +void WrapperVolumeData::GetDepth(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + VolumeData* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->size.z)); +} + +void WrapperVolumeData::GetSpacing(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + VolumeData* self = lctx.self(); + + v8::Local obj = v8::Object::New(lctx.isolate); + lctx.vec3_to_jvec3(self->spacing, obj); + info.GetReturnValue().Set(obj); +} + + +void WrapperVolumeData::GetBytesPerPixel(v8::Local property, const v8::PropertyCallbackInfo& info) +{ + LocalContext lctx(info); + VolumeData* self = lctx.self(); + info.GetReturnValue().Set(lctx.num_to_jnum(self->bytes_per_pixel)); +} diff --git a/Three.V8/volume/WrapperVolumeData.h b/Three.V8/volume/WrapperVolumeData.h new file mode 100644 index 00000000..9c7da2c3 --- /dev/null +++ b/Three.V8/volume/WrapperVolumeData.h @@ -0,0 +1,22 @@ +#pragma once + +#include "definitions.hpp" + +class GameContext; + +class WrapperVolumeData +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + static void dtor(void* ptr, GameContext* ctx); + + static void GetWidth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetHeight(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetDepth(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetSpacing(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetBytesPerPixel(v8::Local property, const v8::PropertyCallbackInfo& info); + +}; \ No newline at end of file diff --git a/Three.V8/volume/VolumeDataLoader.hpp b/Three.V8/volume/WrapperVolumeDataLoader.cpp similarity index 60% rename from Three.V8/volume/VolumeDataLoader.hpp rename to Three.V8/volume/WrapperVolumeDataLoader.cpp index 138f0ce5..08de32ad 100644 --- a/Three.V8/volume/VolumeDataLoader.hpp +++ b/Three.V8/volume/WrapperVolumeDataLoader.cpp @@ -1,26 +1,16 @@ -#pragma once - #include "WrapperUtils.hpp" #include -class WrapperVolumeDataLoader -{ -public: - static v8::Local create_template(v8::Isolate* isolate); - -private: - static void LoadRawVolumeFile(const v8::FunctionCallbackInfo& info); - -}; +#include "WrapperVolumeDataLoader.h" -v8::Local WrapperVolumeDataLoader::create_template(v8::Isolate* isolate) +void WrapperVolumeDataLoader::define(ObjectDefinition& object) { - v8::Local templ = v8::ObjectTemplate::New(isolate); - templ->Set(isolate, "loadRawVolumeFile", v8::FunctionTemplate::New(isolate, LoadRawVolumeFile)); - return templ; + object.name = "volumeDataLoader"; + object.methods = { + { "loadRawVolumeFile", LoadRawVolumeFile}, + }; } - void WrapperVolumeDataLoader::LoadRawVolumeFile(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); @@ -41,3 +31,5 @@ void WrapperVolumeDataLoader::LoadRawVolumeFile(const v8::FunctionCallbackInfo& info); + +}; + diff --git a/Three.V8/volume/VolumeIsosurfaceModel.hpp b/Three.V8/volume/WrapperVolumeIsosurfaceModel.cpp similarity index 56% rename from Three.V8/volume/VolumeIsosurfaceModel.hpp rename to Three.V8/volume/WrapperVolumeIsosurfaceModel.cpp index 0e399990..2124c8bd 100644 --- a/Three.V8/volume/VolumeIsosurfaceModel.hpp +++ b/Three.V8/volume/WrapperVolumeIsosurfaceModel.cpp @@ -1,57 +1,40 @@ -#pragma once - #include "WrapperUtils.hpp" -#include "core/Object3D.hpp" +#include "core/WrapperObject3D.h" #include "volume/VolumeData.h" #include "volume/VolumeIsosurfaceModel.h" +#include "WrapperVolumeIsosurfaceModel.h" -class WrapperVolumeIsosurfaceModel -{ -public: - static v8::Local create_template(v8::Isolate* isolate, v8::FunctionCallback constructor = New); - static void New(const v8::FunctionCallbackInfo& info); - - static void GetIsovalue(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetIsovalue(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - - static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); - static void GetColor(const v8::FunctionCallbackInfo& info); - static void SetColor(const v8::FunctionCallbackInfo& info); - - static void GetMetalness(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetMetalness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); - static void GetRoughness(v8::Local property, const v8::PropertyCallbackInfo& info); - static void SetRoughness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); -}; - - -v8::Local WrapperVolumeIsosurfaceModel::create_template(v8::Isolate* isolate, v8::FunctionCallback constructor) +void WrapperVolumeIsosurfaceModel::define(ClassDefinition& cls) { - v8::Local templ = WrapperObject3D::create_template(isolate, constructor); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "isovalue").ToLocalChecked(), GetIsovalue, SetIsovalue); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "color").ToLocalChecked(), GetColor, 0); - templ->InstanceTemplate()->Set(isolate, "getColor", v8::FunctionTemplate::New(isolate, GetColor)); - templ->InstanceTemplate()->Set(isolate, "setColor", v8::FunctionTemplate::New(isolate, SetColor)); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "metalness").ToLocalChecked(), GetMetalness, SetMetalness); - templ->InstanceTemplate()->SetAccessor(v8::String::NewFromUtf8(isolate, "roughness").ToLocalChecked(), GetRoughness, SetRoughness); - - return templ; + WrapperObject3D::define(cls); + cls.name = "VolumeIsosurfaceModel"; + cls.ctor = ctor; + + std::vector props = { + { "isovalue", GetIsovalue, SetIsovalue }, + { "color", GetColor }, + { "metalness", GetMetalness, SetMetalness }, + { "roughness", GetRoughness, SetRoughness }, + }; + cls.properties.insert(cls.properties.end(), props.begin(), props.end()); + + std::vector methods = { + {"getColor", GetColor }, + {"setColor", SetColor }, + }; + cls.methods.insert(cls.methods.end(), methods.begin(), methods.end()); } -void WrapperVolumeIsosurfaceModel::New(const v8::FunctionCallbackInfo& info) +void* WrapperVolumeIsosurfaceModel::ctor(const v8::FunctionCallbackInfo& info) { LocalContext lctx(info); lctx.set_property(info.Holder(), "_data", info[0]); VolumeData* data = lctx.jobj_to_obj(info[0]); - VolumeIsosurfaceModel* self = new VolumeIsosurfaceModel(data); - info.This()->SetAlignedPointerInInternalField(0, self); - lctx.ctx()->regiter_object(info.This(), WrapperObject3D::dtor); + return new VolumeIsosurfaceModel(data); } - - void WrapperVolumeIsosurfaceModel::GetIsovalue(v8::Local property, const v8::PropertyCallbackInfo& info) { LocalContext lctx(info); diff --git a/Three.V8/volume/WrapperVolumeIsosurfaceModel.h b/Three.V8/volume/WrapperVolumeIsosurfaceModel.h new file mode 100644 index 00000000..30efb2a0 --- /dev/null +++ b/Three.V8/volume/WrapperVolumeIsosurfaceModel.h @@ -0,0 +1,25 @@ +#pragma once + +#include "definitions.hpp" + +class WrapperVolumeIsosurfaceModel +{ +public: + static void define(ClassDefinition& cls); + +private: + static void* ctor(const v8::FunctionCallbackInfo& info); + + static void GetIsovalue(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetIsovalue(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetColor(v8::Local property, const v8::PropertyCallbackInfo& info); + static void GetColor(const v8::FunctionCallbackInfo& info); + static void SetColor(const v8::FunctionCallbackInfo& info); + + static void GetMetalness(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetMetalness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); + + static void GetRoughness(v8::Local property, const v8::PropertyCallbackInfo& info); + static void SetRoughness(v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info); +}; diff --git a/ThreeEngine/ThreeEngine.vcxproj b/ThreeEngine/ThreeEngine.vcxproj index a5d57b52..838a5a84 100644 --- a/ThreeEngine/ThreeEngine.vcxproj +++ b/ThreeEngine/ThreeEngine.vcxproj @@ -263,6 +263,7 @@ + @@ -415,6 +416,7 @@ + diff --git a/ThreeEngine/ThreeEngine.vcxproj.filters b/ThreeEngine/ThreeEngine.vcxproj.filters index 0659dbbe..8f63043d 100644 --- a/ThreeEngine/ThreeEngine.vcxproj.filters +++ b/ThreeEngine/ThreeEngine.vcxproj.filters @@ -540,6 +540,9 @@ Source Files\utils + + Source Files\utils + @@ -1001,6 +1004,9 @@ Header Files\utils + + Header Files\utils +