-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
746 additions
and
374 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
import { Engine } from '@babylonjs/core/Engines/engine'; | ||
import { Scene } from '@babylonjs/core/scene'; | ||
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera'; | ||
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight'; | ||
import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder' | ||
import { Vector3, Color3 } from '@babylonjs/core/Maths/math'; | ||
import { SkyMaterial } from '@babylonjs/materials/sky'; | ||
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial'; | ||
import { Texture } from '@babylonjs/core/Materials/Textures/texture'; | ||
import { Tools } from '@babylonjs/core/Misc/tools' | ||
|
||
import floor_tex from '../../assets/floortiles.png'; | ||
import floor_norm from '../../assets/floortiles_normal.png'; | ||
|
||
const canvas = document.createElement('canvas'); | ||
canvas.id = 'render-canvas'; | ||
canvas.style.width = '100%'; | ||
canvas.style.height = '100%'; | ||
document.body.appendChild(canvas); | ||
|
||
export function setupEngine() { | ||
|
||
const engine = new Engine(canvas, true); | ||
const scene = new Scene(engine); | ||
|
||
const setupCamera = async () => { | ||
const arcRotCamera = new ArcRotateCamera('camera1arc', Tools.ToRadians(-90), Tools.ToRadians(60), 10, Vector3.Zero(), scene); | ||
arcRotCamera.lowerRadiusLimit = 2; | ||
arcRotCamera.upperRadiusLimit = 45; | ||
arcRotCamera.upperBetaLimit = Tools.ToRadians(89.9); // todo: Adjust to mouse wheel ? like in unreal | ||
arcRotCamera.wheelDeltaPercentage = 0.01; | ||
arcRotCamera.speed = 1; | ||
arcRotCamera.attachControl(canvas, true); | ||
} | ||
|
||
const setupSky = async () => { | ||
const sunPosition = new Vector3(50, 120, -100); | ||
|
||
const skyMaterial = new SkyMaterial('skyMat', scene); | ||
skyMaterial.backFaceCulling = false; | ||
skyMaterial.useSunPosition = true; | ||
skyMaterial.sunPosition = sunPosition; | ||
|
||
const skybox = MeshBuilder.CreateBox('skyBox', { size: 1000.0 }, scene); | ||
skybox.material = skyMaterial; | ||
|
||
const light = new HemisphericLight('hemisphereLight', sunPosition, scene); | ||
} | ||
|
||
const setupFloor = async () => { | ||
const ground = MeshBuilder.CreateGround('ground', {width:15, height:15}, scene); | ||
const groundMat = new StandardMaterial('groundMat', scene); | ||
const tileTex = new Texture(floor_tex, scene); | ||
tileTex.uScale = ground._width; | ||
tileTex.vScale = ground._height; | ||
const tileNormal = new Texture(floor_norm, scene); | ||
tileNormal.uScale = ground._width; | ||
tileNormal.vScale = ground._height; | ||
groundMat.diffuseTexture = tileTex; | ||
groundMat.bumpTexture = tileNormal; | ||
groundMat.specularColor = new Color3(0.4, 0.4, 0.4); | ||
groundMat.backFaceCulling = false; | ||
ground.material = groundMat; | ||
|
||
} | ||
|
||
setupCamera(); | ||
setupSky(); | ||
setupFloor(); | ||
|
||
const cube = MeshBuilder.CreateBox('box', {size: 1}, scene); | ||
cube.translate(new Vector3(0, 1, 0), 0.5001); // avoid clipping with ground | ||
|
||
engine.runRenderLoop(() => { | ||
scene.render(); | ||
}); | ||
|
||
window.addEventListener('resize', () => { | ||
engine.resize(); | ||
}); | ||
|
||
} | ||
|
||
//setupEngine(); |
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,6 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import {setupEngine} from './components/main' | ||
|
||
setupEngine(); | ||
ReactDOM.render(<h1>React Test</h1>, document.getElementById('react-root')); |
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 |
---|---|---|
@@ -1,19 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Language and Environment */ | ||
"target": "es2016", | ||
// "lib": [], | ||
|
||
/* Modules */ | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"sourceMap": false, | ||
|
||
/* Type Checking */ | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"outDir": "./dist" | ||
"target": "es2016", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"skipLibCheck": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"sourceMap": false, | ||
"strict": true, | ||
"jsx": "react", | ||
"outDir": "./dist" | ||
}, | ||
"include": ["src", "assets"] | ||
} |
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 |
---|---|---|
@@ -1,51 +1,63 @@ | ||
const path = require('path'); | ||
const WebpackObfuscator = require('webpack-obfuscator'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
//const WebpackObfuscator = require('webpack-obfuscator'); | ||
//const webpack = require('webpack'); | ||
//new webpack.EnvironmentPlugin(['NODE_ENV', 'DEBUG']); | ||
|
||
module.exports = { | ||
entry: './src/index.ts', | ||
entry: './src/index.tsx', | ||
output: { | ||
filename: 'bundle.js', | ||
path: path.resolve(__dirname, 'dist') | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js'] | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
test: /\.(ts|tsx)$/, | ||
use: 'ts-loader', | ||
exclude: /node_modules/ | ||
}, | ||
{ | ||
test: /\.(png|svg|jpg|jpeg|gif)$/i, | ||
type: 'asset/resource', | ||
}, | ||
{ | ||
test: /\.js$/, | ||
exclude: [ | ||
path.resolve(__dirname, 'bundle.js') | ||
], | ||
enforce: 'post', | ||
use: { | ||
loader: WebpackObfuscator.loader, | ||
options: { | ||
rotateStringArray: true, | ||
compact: true, | ||
} | ||
} | ||
} | ||
//{ | ||
// test: /\.js$/, | ||
// exclude: [ | ||
// path.resolve(__dirname, 'bundle.js') | ||
// ], | ||
// enforce: 'post', | ||
// use: { | ||
// loader: WebpackObfuscator.loader, | ||
// options: { | ||
// rotateStringArray: true, | ||
// compact: true, | ||
// } | ||
// } | ||
// } | ||
] | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.tsx', '.js'] | ||
}, | ||
plugins: [ | ||
new WebpackObfuscator ({ | ||
rotateStringArray: true, | ||
compact: true, | ||
}, ['bundle.js']) | ||
new HtmlWebpackPlugin({ | ||
template: './public/index.html', | ||
}), | ||
//new WebpackObfuscator ({ | ||
// rotateStringArray: true, | ||
// compact: true, | ||
//}, ['bundle.js']), | ||
//new webpack.ProvidePlugin({ | ||
// process: 'process/browser', | ||
//}), | ||
], | ||
devServer: { | ||
contentBase: path.join(__dirname, 'dist'), | ||
static: { | ||
directory: path.join(__dirname, 'dist'), | ||
}, | ||
compress: true, | ||
port: 9000 | ||
port: 3000, | ||
open: true, | ||
}, | ||
}; |