Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Apps/Playground/Android/BabylonNative/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ target_link_libraries(BabylonNativeJNI
PRIVATE EGL
PRIVATE log
PRIVATE -lz
PRIVATE AbortController
PRIVATE AndroidExtensions
PRIVATE AppRuntime
PRIVATE Blob
Expand All @@ -40,9 +41,11 @@ target_link_libraries(BabylonNativeJNI
PRIVATE NativeTracing
PRIVATE NativeXr
PRIVATE Performance
PRIVATE PointerEvent
PRIVATE ScriptLoader
PRIVATE ShaderCache
PRIVATE TestUtils
PRIVATE TextDecoder
PRIVATE TextEncoder
PRIVATE Window
PRIVATE XMLHttpRequest)
3 changes: 3 additions & 0 deletions Apps/Playground/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ endif()
target_include_directories(Playground PRIVATE ".")

target_link_libraries(Playground
PRIVATE AbortController
PRIVATE AppRuntime
PRIVATE Blob
PRIVATE bx
Expand All @@ -149,10 +150,12 @@ target_link_libraries(Playground
PRIVATE NativeOptimizations
PRIVATE NativeTracing
PRIVATE Performance
PRIVATE PointerEvent
PRIVATE ScriptLoader
PRIVATE ShaderCache
PRIVATE TestUtils
PRIVATE TextDecoder
PRIVATE TextEncoder
PRIVATE Window
PRIVATE XMLHttpRequest
${ADDITIONAL_LIBRARIES}
Expand Down
2 changes: 0 additions & 2 deletions Apps/Playground/Scripts/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2376,8 +2376,6 @@
{
"title": "Serialize scene without materials",
"playgroundId": "#PH4DEZ#1",
"excludeFromAutomaticTesting": true,
"reason": "Pixel comparison fails (more than 20% pixels differ)",
"referenceImage": "serializeWithoutMaterials.png"
},
{
Expand Down
47 changes: 45 additions & 2 deletions Apps/Playground/Scripts/validation_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,52 @@
if (type === "canvas") {
return new OffscreenCanvas(64, 64);
}
return {};
// Generic element stub with a no-op dispatchEvent so serializer
// tests that simulate a click via createEvent/dispatchEvent run
// without throwing.
return {
style: {},
addEventListener: function () { },
removeEventListener: function () { },
dispatchEvent: function () { return true; },
appendChild: function (c) { return c; },
removeChild: function (c) { return c; },
setAttribute: function () { },
getAttribute: function () { return null; },
click: function () { },
};
},
createEvent: function (type) {
var ev = {
type: '',
bubbles: false,
cancelable: false,
defaultPrevented: false,
target: null,
currentTarget: null,
timeStamp: Date.now(),
detail: null,
preventDefault: function () { ev.defaultPrevented = true; },
stopPropagation: function () { },
stopImmediatePropagation: function () { },
};
ev.initEvent = function (t, bubbles, cancelable) {
ev.type = String(t || '');
ev.bubbles = !!bubbles;
ev.cancelable = !!cancelable;
};
ev.initCustomEvent = function (t, bubbles, cancelable, detail) {
ev.initEvent(t, bubbles, cancelable);
ev.detail = detail;
};
ev.initUIEvent = ev.initEvent;
ev.initMouseEvent = ev.initEvent;
return ev;
},
removeEventListener: function () { }
addEventListener: function () { },
removeEventListener: function () { },
dispatchEvent: function () { return true; },
body: { appendChild: function (c) { return c; }, removeChild: function (c) { return c; } },
}

const xhr = new XMLHttpRequest();
Expand Down
9 changes: 9 additions & 0 deletions Apps/Playground/Shared/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
#include <Babylon/Plugins/ShaderCache.h>
#include <Babylon/Plugins/TestUtils.h>

#include <Babylon/Polyfills/AbortController.h>
#include <Babylon/Polyfills/Blob.h>
#include <Babylon/Polyfills/Canvas.h>
#include <Babylon/Polyfills/Console.h>
#include <Babylon/Polyfills/Performance.h>
#include <Babylon/Polyfills/PointerEvent.h>
#include <Babylon/Polyfills/TextDecoder.h>
#include <Babylon/Polyfills/TextEncoder.h>
#include <Babylon/Polyfills/Window.h>
#include <Babylon/Polyfills/XMLHttpRequest.h>

Expand Down Expand Up @@ -183,8 +186,14 @@ AppContext::AppContext(

Babylon::Polyfills::Window::Initialize(env);

Babylon::Polyfills::AbortController::Initialize(env);

Babylon::Polyfills::TextDecoder::Initialize(env);

Babylon::Polyfills::TextEncoder::Initialize(env);

Babylon::Polyfills::PointerEvent::Initialize(env);

Babylon::Polyfills::XMLHttpRequest::Initialize(env);
m_canvas.emplace(Babylon::Polyfills::Canvas::Initialize(env));

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ option(BABYLON_NATIVE_PLUGIN_TESTUTILS "Include Babylon Native Plugin TestUtils.
# Polyfills
option(BABYLON_NATIVE_POLYFILL_WINDOW "Include Babylon Native Polyfill Window." ON)
option(BABYLON_NATIVE_POLYFILL_CANVAS "Include Babylon Native Polyfill Canvas." ON)
option(BABYLON_NATIVE_POLYFILL_TEXTENCODER "Include Babylon Native Polyfill TextEncoder." ON)
option(BABYLON_NATIVE_POLYFILL_POINTEREVENT "Include Babylon Native Polyfill PointerEvent." ON)

# Sanitizers
option(ENABLE_SANITIZERS "Enable AddressSanitizer and UBSan" OFF)
Expand Down
8 changes: 8 additions & 0 deletions Polyfills/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ endif()
if(BABYLON_NATIVE_POLYFILL_CANVAS)
add_subdirectory(Canvas)
endif()

if(BABYLON_NATIVE_POLYFILL_TEXTENCODER)
add_subdirectory(TextEncoder)
endif()

if(BABYLON_NATIVE_POLYFILL_POINTEREVENT)
add_subdirectory(PointerEvent)
endif()
15 changes: 15 additions & 0 deletions Polyfills/PointerEvent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(SOURCES
"Include/Babylon/Polyfills/PointerEvent.h"
"Source/PointerEvent.cpp")

add_library(PointerEvent ${SOURCES})
warnings_as_errors(PointerEvent)

target_include_directories(PointerEvent PUBLIC "Include")

target_link_libraries(PointerEvent
PUBLIC napi
PUBLIC Foundation)

set_property(TARGET PointerEvent PROPERTY FOLDER Polyfills)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES})
21 changes: 21 additions & 0 deletions Polyfills/PointerEvent/Include/Babylon/Polyfills/PointerEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't polyfill DOM types. BabylonNative isn't a browser; DeviceInputSystem already abstracts input. Let's discuss offline before adding this.


#include <napi/env.h>
#include <Babylon/Api.h>

namespace Babylon::Polyfills::PointerEvent
{
// Registers a global `PointerEvent` constructor on the supplied environment
// if the host runtime does not already expose one. Provides the W3C Pointer
// Events Level 3 surface (MouseEvent + PointerEvent properties and the
// standard Event methods preventDefault / stopPropagation /
// stopImmediatePropagation / getModifierState / getCoalescedEvents /
// getPredictedEvents).
//
// This polyfill exists for embeddings that lack a DOM (notably Babylon
// Native on Chakra-based hosts) so JS code that calls
// `new PointerEvent("pointerdown", {...})` can work uniformly. Modern V8 /
// JSC builds inside browsers already provide PointerEvent natively and
// Initialize() is a no-op there.
void BABYLON_API Initialize(Napi::Env env);
}
Loading