Skip to content

Commit

Permalink
added ground with texture
Browse files Browse the repository at this point in the history
  • Loading branch information
99-Knots committed May 29, 2024
1 parent 359437e commit 82023b0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions assets/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.jpg' {
const value: any
export = value;
}
Binary file added assets/wood_floor_diff_4k.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as BABYLON from '@babylonjs/core';
import { SkyMaterial } from '@babylonjs/materials'
import { SkyMaterial } from '@babylonjs/materials';
import img from '../assets/wood_floor_diff_4k.jpg';

const canvas = document.createElement('canvas');
canvas.id = "render-canvas";
Expand All @@ -22,7 +23,17 @@ skybox.material = skyMaterial;

const light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(1, 1, 0), scene);

const cube = BABYLON.MeshBuilder.CreateBox('box', {}, scene);
const cube = BABYLON.MeshBuilder.CreateBox('box', {size: 1}, scene);
cube.translate(new BABYLON.Vector3(0, 1, 0), 0.5001);

const ground = BABYLON.MeshBuilder.CreateGround('ground', {width:15, height:15}, scene);
const groundMat = new BABYLON.StandardMaterial('groundMaterial', scene);
const woodTex = new BABYLON.Texture(img, scene);
woodTex.uScale = ground._width/2;
woodTex.vScale = ground._height/2;
groundMat.diffuseTexture = woodTex;
groundMat.backFaceCulling = false;
ground.material = groundMat;

engine.runRenderLoop(() => {
scene.render();
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"skipLibCheck": true,
"outDir": "./dist"
},
"include": ["src"]
"include": ["src", "assets"]
}
6 changes: 5 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ module.exports = {
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
]
},
resolve: {
Expand Down

0 comments on commit 82023b0

Please sign in to comment.