From 2667a4e54437221f7accff22a677ca687e6274b8 Mon Sep 17 00:00:00 2001 From: Frank Delaguila Date: Sun, 13 Mar 2022 19:48:00 -0600 Subject: [PATCH] Working on making floor texture look more realistic --- package.json | 3 +- server.js | 5 +- ...erfections003_1K_var1.jpg => texture1.jpg} | Bin ...s003_1K_Normal.jpg => texture1_normal.jpg} | Bin src/components/App.jsx | 106 ++++++++---------- src/styles/styles.scss | 1 - webpack.common.js | 19 +++- webpack.dev.js | 8 +- webpack.prod.js | 5 - 9 files changed, 69 insertions(+), 78 deletions(-) rename src/assets/textures/{SurfaceImperfections003_1K_var1.jpg => texture1.jpg} (100%) rename src/assets/textures/{SurfaceImperfections003_1K_Normal.jpg => texture1_normal.jpg} (100%) diff --git a/package.json b/package.json index 166b9d2..dc03ef7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "start": "node ./server.js", + "start": "npx webpack serve --config webpack.dev.js", "build": "NODE_ENV=production webpack --config webpack.prod.js", "test": "echo \"Error: no test specified\" && exit 1" }, @@ -37,6 +37,7 @@ "webpack": "^5.70.0", "webpack-cli": "^4.9.2", "webpack-dev-middleware": "^5.3.1", + "webpack-dev-server": "^4.7.4", "webpack-hot-middleware": "^2.25.1", "webpack-merge": "^5.8.0" }, diff --git a/server.js b/server.js index 5831149..c0c1fb0 100644 --- a/server.js +++ b/server.js @@ -13,13 +13,14 @@ const compiler = webpack(config); app.use( webpackDevMiddleware(compiler, { publicPath: config.output.publicPath, - writeToDisk: true, + writeToDisk: true }) ); app.use( webpackHotMiddleware(compiler, { noInfo: true, - quiet: true + quiet: true, + contentBase: '/dist' }) ); app.get( '/*', function(req, res) { diff --git a/src/assets/textures/SurfaceImperfections003_1K_var1.jpg b/src/assets/textures/texture1.jpg similarity index 100% rename from src/assets/textures/SurfaceImperfections003_1K_var1.jpg rename to src/assets/textures/texture1.jpg diff --git a/src/assets/textures/SurfaceImperfections003_1K_Normal.jpg b/src/assets/textures/texture1_normal.jpg similarity index 100% rename from src/assets/textures/SurfaceImperfections003_1K_Normal.jpg rename to src/assets/textures/texture1_normal.jpg diff --git a/src/components/App.jsx b/src/components/App.jsx index 00960a2..51c1568 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -1,76 +1,64 @@ import '../styles/styles.scss'; import * as THREE from 'three'; import { useRef, useState } from 'react'; -import { Canvas, useFrame, useThree } from '@react-three/fiber'; -import { MeshReflectorMaterial, Environment, ContactShadows, Text } from '@react-three/drei'; +import { Canvas, useFrame } from '@react-three/fiber'; +import { Text, Environment, MeshReflectorMaterial, useTexture } from '@react-three/drei'; import { gsap } from 'gsap'; -const Box = (props) => { - // This reference gives us direct access to the THREE.Mesh object - const ref = useRef(); - - // Hold state for hovered and clicked events - const [hovered, hover] = useState(false); - const [clicked, click] = useState(false); +import dreiVideo from '../assets/videos/drei.mp4'; +import floorTexture from '../assets/textures/texture1.jpg'; +import floorTextureNormal from '../assets/textures/texture1_normal.jpg'; - // Subscribe this component to the render-loop, rotate the mesh every frame - useFrame((state, delta) => { - gsap.to( ref.current.rotation, { - x: "+= 0.1" - }); - }); - - // Return the view, these are regular Threejs elements expressed in JSX +const Floor = () => { + const [floor, normal] = useTexture([floorTexture, floorTextureNormal]); return ( - click(!clicked)} - onPointerOver={(event) => hover(true)} - onPointerOut={(event) => hover(false)}> - - + // + + + - ) + ); }; const App = () => { - const [video] = useState(() => Object.assign(document.createElement('video'), { src: '../assets/videos/drei.mp4', crossOrigin: 'Anonymous', loop: true })) + const [video] = useState(() => { + const vid = document.createElement('video'); + vid.src = dreiVideo; + vid.crossOrigin = "Anonymous"; + vid.loop = true; + vid.muted = true; + vid.play(); + return vid; + }); return ( <> - - - - - - - drei - - - - - - {/* - */} - - - - + + + + + + Designer and Developer + + + + + - - + + + + ); diff --git a/src/styles/styles.scss b/src/styles/styles.scss index 2ea386b..a3250d7 100644 --- a/src/styles/styles.scss +++ b/src/styles/styles.scss @@ -1,4 +1,3 @@ -@tailwind preflight; @tailwind base; @tailwind components; @tailwind utilities; diff --git a/webpack.common.js b/webpack.common.js index 7c59bef..e623029 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -19,6 +19,22 @@ module.exports = { "querystring": require.resolve("querystring-es3") } }, + output: { + filename: 'js/[name].[contenthash].js', + path: path.join(__dirname, 'dist'), + publicPath: '/', + clean: true + }, + devServer: { + static: { + directory: path.join(__dirname, 'dist'), + }, + devMiddleware: { + writeToDisk: true + }, + port: 3000, + open: true + }, module: { rules: [ // HTML @@ -62,9 +78,6 @@ module.exports = { { test: /\.(png|svg|jpg|jpeg|gif|mp4)$/i, type: 'asset/resource', - generator: { - filename: 'assets/[name].[ext]' - }, }, // { diff --git a/webpack.dev.js b/webpack.dev.js index 8cf80b0..88df928 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -9,13 +9,7 @@ const hotMiddlewareScript = module.exports = merge(commonConfiguration, { mode: 'development', entry: { - portfolio: [hotMiddlewareScript, './src/scripts/app.js'], - }, - output: { - filename: 'js/[name].[contenthash].js', - path: path.resolve(__dirname, './dist'), - publicPath: '/', - clean: true + portfolio: ['./src/scripts/app.js'], }, devtool: 'source-map', plugins: [ diff --git a/webpack.prod.js b/webpack.prod.js index 7733312..0247ab5 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -10,11 +10,6 @@ module.exports = merge(commonConfiguration, { portfolio: path.resolve(__dirname, './src/scripts/app.js'), }, devtool: 'source-map', - output: { - filename: 'js/[name].[contenthash].js', - path: path.resolve(__dirname, './dist'), - clean: true - }, plugins: [ // new ImageMinimizerPlugin({ // minimizerOptions: {