@@ -50,6 +50,18 @@ const savedHtmlElementListeners: {
5050 listener : EventListenerOrEventListenerObject ;
5151} [ ] = [ ] ;
5252
53+ function normalizeUrl ( url : string ) {
54+ if ( url . startsWith ( "scene/" ) ) {
55+ url = url . substring ( "scene/" . length ) ;
56+ }
57+
58+ if ( url . startsWith ( "/scene/" ) ) {
59+ url = url . substring ( "/scene/" . length ) ;
60+ }
61+
62+ return url ;
63+ }
64+
5365/**
5466 * To play scene inline in the editor, we need to override some methods.
5567 * This function restores all the orignal methods for all object that have been overridden.
@@ -135,6 +147,7 @@ export function applyOverrides(editor: Editor) {
135147 // Fetch
136148 window . fetch = async ( input : string | URL | Request , init ?: RequestInit ) => {
137149 if ( ! isAbsolute ( input . toString ( ) ) ) {
150+ input = normalizeUrl ( input . toString ( ) ) ;
138151 input = join ( publicDir , input . toString ( ) ) ;
139152 }
140153
@@ -171,6 +184,7 @@ export function applyOverrides(editor: Editor) {
171184 // WebRequest
172185 WebRequest . prototype . open = function ( method : string , url : string ) {
173186 if ( url && ! isAbsolute ( url ) ) {
187+ url = normalizeUrl ( url ) ;
174188 url = join ( publicDir , url ) ;
175189 }
176190
@@ -184,6 +198,11 @@ export function applyOverrides(editor: Editor) {
184198
185199 // Engine
186200 Engine . prototype . createTexture = ( url : string , ...args : any [ ] ) => {
201+ if ( ! isAbsolute ( url ) && ! url . startsWith ( "data:" ) ) {
202+ url = normalizeUrl ( url ) ;
203+ url = join ( publicScene , url ) ;
204+ }
205+
187206 const temporaryTextureIndex = url ?. indexOf ( ".bjseditor" ) ?? - 1 ;
188207
189208 if ( temporaryTextureIndex !== - 1 ) {
0 commit comments