Skip to content

Commit

Permalink
module version of ARnft
Browse files Browse the repository at this point in the history
- flamingo and basic example with new three.module.js
- all required libs in the repository
  • Loading branch information
kalwalt committed Oct 30, 2024
1 parent caea518 commit ff6aa3c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 53 deletions.
3 changes: 1 addition & 2 deletions dist/ARnft.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/ARnft.module.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions examples/arNFT_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/",
"arnft-threejs": "./js/ARnftThreejs.module.js"
"arnft-threejs": "./js/ARnftThreejs.module.js",
"arnft": "./../dist/ARnft.module.js"
}
}
</script>
<script src="../dist/ARnft.js"></script>

<script type="module">
import * as THREE from 'three'
import arnft from 'arnft'
const { ARnft } = arnft
import ARnftThreejs from 'arnft-threejs'
const { SceneRendererTJS, NFTaddTJS } = ARnftThreejs;

let width = 640;
let height = 480;
ARnft.ARnft.init(width, height, [["examples/DataNFT/pinball"]], [['pinball']], 'config.json', true)
ARnft.init(width, height, [["examples/DataNFT/pinball"]], [['pinball']], 'config.json', true)
.then((nft) => {
let mat = new THREE.MeshLambertMaterial({
color: 0xff0000
Expand Down
27 changes: 20 additions & 7 deletions examples/arNFT_gltf_flamingo_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@
🖼 Marker Image
</a>

<script src="js/third_party/three.js/three.min.js"></script>
<script src="js/ARnftThreejs.js"></script>
<script src="../dist/ARnft.js"></script>
<script type="importmap">
{
"imports": {
"three": "./js/third_party/three.js/three.module.min.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/",
"arnft-threejs": "./js/ARnftThreejs.module.js",
"arnft": "./../dist/ARnft.module.js"
}
}
</script>

<script type="module">
import * as THREE from 'three'
import arnft from 'arnft'
const { ARnft } = arnft
import ARnftThreejs from 'arnft-threejs'
const { SceneRendererTJS, NFTaddTJS } = ARnftThreejs;

<script>
let width = 640;
let height = 480;
ARnft.ARnft.init(width, height, [["examples/DataNFT/pinball"]], [["pinball"]], "config.json", true)
ARnft.init(width, height, [["examples/DataNFT/pinball"]], [["pinball"]], "config.json", true)
.then((nft) => {
document.addEventListener("containerEvent", function (ev) {
let canvas = document.getElementById("canvas");
Expand All @@ -48,7 +61,7 @@
},
};

let sceneThreejs = new ARnftThreejs.SceneRendererTJS(config, canvas, nft.uuid, true);
let sceneThreejs = new SceneRendererTJS(config, canvas, nft.uuid, true);
sceneThreejs.initRenderer();

const renderer = sceneThreejs.getRenderer();
Expand All @@ -59,7 +72,7 @@
directionalLight.position.set(0.5, 0, 0.866);
scene.add(directionalLight);

let nftAddTJS = new ARnftThreejs.NFTaddTJS(nft.uuid);
let nftAddTJS = new NFTaddTJS(nft.uuid);
let mixers = [];
let clock = new THREE.Clock();
function modelAnimation(gltf) {
Expand Down
3 changes: 1 addition & 2 deletions examples/js/ARnftThreejs.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/js/ARnftThreejs.module.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/js/third_party/three.js/three.module.min.js

Large diffs are not rendered by default.

112 changes: 73 additions & 39 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
const path = require('path')
const TerserPlugin = require("terser-webpack-plugin");

module.exports = {
entry: './src/index.ts',
devtool: 'inline-source-map',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'ARnft.js',
library: 'ARnft',
libraryTarget: 'umd',
// @see: https://github.com/webpack/webpack/issues/3929
libraryExport: 'default',
// @see: https://github.com/webpack/webpack/issues/6522
globalObject: "typeof self !== 'undefined' ? self : this",
publicPath: "auto"
},
externals: {
stats: {
commonjs: 'stats.js',
commonjs2: 'stats.js',
amd: 'stats.js',
root: 'Stats' // indicates global variable
}
},
module: {
module.exports = (env, argv) => {
let devtool = false;
if (argv.mode === 'development') {
devtool = 'inline-source-map';
}
console.log(`${argv.mode} build`);
const module= {
rules: [
{
test: /\.worker\.(c|m)?ts$/i,
Expand All @@ -32,26 +16,76 @@ module.exports = {
options: { inline: 'no-fallback' }
}
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
},
resolve: {
};
const resolve = {
alias: {
jsartoolkitnft: '@webarkit/jsartoolkit-nft'
},
extensions: ['.tsx', '.ts', '.js'],
};
const optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
extractComments: false
}),
],
};
return [{
name: "ARnft",
entry: './src/index.ts',
devtool,
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'ARnft.js',
library: 'ARnft',
libraryTarget: 'umd',
// @see: https://github.com/webpack/webpack/issues/3929
libraryExport: 'default',
// @see: https://github.com/webpack/webpack/issues/6522
globalObject: "typeof self !== 'undefined' ? self : this",
publicPath: "auto"
},
externals: {
stats: {
commonjs: 'stats.js',
commonjs2: 'stats.js',
amd: 'stats.js',
root: 'Stats' // indicates global variable
}
},
module,
resolve,
optimization,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
extractComments: false
}),
],
},
{
name: "ARnft.module",
entry: './src/index.ts',
devtool,
experiments: {
outputModule: true,
},
output: {
library: {
type: 'module',
},
path: path.resolve(__dirname, 'dist'),
filename: 'ARnft.module.js',
},
externalsType: 'module',
externals: {
three: 'three',
},
module,
resolve,
optimization,
},
]
}

0 comments on commit ff6aa3c

Please sign in to comment.