-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ddb308
commit 3a2d482
Showing
7 changed files
with
134 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ node_modules/ | |
# Build-related directories | ||
dist/ | ||
docs/api/ | ||
test/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const replace = require('rollup-plugin-re'); | ||
|
||
// three modules to find-replace in | ||
const modules = [ | ||
'VRControls', | ||
'VREffect', | ||
'OrbitControls', | ||
'DeviceOrientationControls' | ||
]; | ||
|
||
const globalReplace = function(str, pattern, replacement) { | ||
return str.replace(new RegExp(pattern, 'g'), replacement); | ||
}; | ||
|
||
module.exports = replace({ | ||
include: ['node_modules/three/examples/js/**'], | ||
patterns: [ | ||
{transform(code, id) { | ||
modules.forEach((m) => { | ||
if (!(new RegExp(m)).test(id)) { | ||
return; | ||
} | ||
|
||
// trun the global modifiction into an import and a local variable definition | ||
code = code.replace(`THREE.${m} =`, `import * as THREE from 'three';\nvar ${m} =`); | ||
|
||
// change references from the global modification to the local variable | ||
code = globalReplace(code, `THREE.${m}`, m); | ||
|
||
// export that local variable as default from this module | ||
code += `\nexport default ${m};`; | ||
|
||
// expose private functions so that users can manually use controls | ||
// and we can add orientation controls | ||
if (m === 'OrbitControls') { | ||
code = globalReplace(code, 'function rotateLeft\\(', 'rotateLeft = function('); | ||
code = globalReplace(code, 'function rotateUp\\(', 'rotateUp = function('); | ||
|
||
code = globalReplace(code, 'rotateLeft', 'scope.rotateLeft'); | ||
code = globalReplace(code, 'rotateUp', 'scope.rotateUp'); | ||
// comment out the context menu prevent default line... | ||
code = globalReplace(code, | ||
"scope.domElement.addEventListener\\( 'contextmenu'", | ||
"\/\/scope.domElement.addEventListener\\( 'contextmenu'" | ||
); | ||
} | ||
}); | ||
return code; | ||
}} | ||
] | ||
}); |
Oops, something went wrong.