Basic rotating phone model

This commit is contained in:
2022-01-29 13:13:35 +03:00
parent 10e90d7faa
commit 6c8e85b381
13 changed files with 72521 additions and 104 deletions

View File

@@ -13,5 +13,7 @@ module.exports = {
rules: { rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'global-require': 'off',
'no-param-reassign': 'off',
}, },
}; };

141
package-lock.json generated
View File

@@ -8,6 +8,7 @@
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"core-js": "^3.6.5", "core-js": "^3.6.5",
"three": "^0.137.5",
"vue": "^3.0.0" "vue": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
@@ -19,7 +20,8 @@
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2", "eslint-plugin-import": "^2.20.2",
"eslint-plugin-vue": "^7.0.0" "eslint-plugin-vue": "^7.0.0",
"file-loader": "^6.2.0"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
@@ -2421,6 +2423,22 @@
} }
} }
}, },
"node_modules/@vue/cli-service/node_modules/file-loader": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/file-loader/-/file-loader-4.3.0.tgz",
"integrity": "sha512-aKrYPYjF1yG3oX0kWRrqrSMfgftm7oJW5M+m4owoldH5C51C0RkIwB++JbRvEW3IU6/ZG5n8UvEcdgwOt2UOWA==",
"dev": true,
"dependencies": {
"loader-utils": "^1.2.3",
"schema-utils": "^2.5.0"
},
"engines": {
"node": ">= 8.9.0"
},
"peerDependencies": {
"webpack": "^4.0.0"
}
},
"node_modules/@vue/cli-shared-utils": { "node_modules/@vue/cli-shared-utils": {
"version": "4.5.15", "version": "4.5.15",
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/download/@vue/cli-shared-utils-4.5.15.tgz", "resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/download/@vue/cli-shared-utils-4.5.15.tgz",
@@ -7003,19 +7021,55 @@
} }
}, },
"node_modules/file-loader": { "node_modules/file-loader": {
"version": "4.3.0", "version": "6.2.0",
"resolved": "https://registry.npmmirror.com/file-loader/download/file-loader-4.3.0.tgz", "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-6.2.0.tgz",
"integrity": "sha512-aKrYPYjF1yG3oX0kWRrqrSMfgftm7oJW5M+m4owoldH5C51C0RkIwB++JbRvEW3IU6/ZG5n8UvEcdgwOt2UOWA==", "integrity": "sha512-qo3glqyTa61Ytg4u73GultjHGjdRyig3tG6lPtyX/jOEJvHif9uB0/OCI2Kif6ctF3caQTW2G5gym21oAsI4pw==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"loader-utils": "^1.2.3", "loader-utils": "^2.0.0",
"schema-utils": "^2.5.0" "schema-utils": "^3.0.0"
},
"engines": {
"node": ">= 10.13.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"peerDependencies": {
"webpack": "^4.0.0 || ^5.0.0"
}
},
"node_modules/file-loader/node_modules/loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"dependencies": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}, },
"engines": { "engines": {
"node": ">=8.9.0" "node": ">=8.9.0"
}
}, },
"peerDependencies": { "node_modules/file-loader/node_modules/schema-utils": {
"webpack": "^4.0.0" "version": "3.1.1",
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz",
"integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==",
"dev": true,
"dependencies": {
"@types/json-schema": "^7.0.8",
"ajv": "^6.12.5",
"ajv-keywords": "^3.5.2"
},
"engines": {
"node": ">= 10.13.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
} }
}, },
"node_modules/file-uri-to-path": { "node_modules/file-uri-to-path": {
@@ -13512,6 +13566,11 @@
"webpack": "^2.0.0 || ^3.0.0 || ^4.0.0" "webpack": "^2.0.0 || ^3.0.0 || ^4.0.0"
} }
}, },
"node_modules/three": {
"version": "0.137.5",
"resolved": "https://registry.npmjs.org/three/-/three-0.137.5.tgz",
"integrity": "sha512-rTyr+HDFxjnN8+N/guZjDgfVxgHptZQpf6xfL/Mo7a5JYIFwK6tAq3bzxYYB4Ae0RosDZlDuP+X5aXDXz+XnHQ=="
},
"node_modules/through": { "node_modules/through": {
"version": "2.3.8", "version": "2.3.8",
"resolved": "https://registry.npm.taobao.org/through/download/through-2.3.8.tgz", "resolved": "https://registry.npm.taobao.org/through/download/through-2.3.8.tgz",
@@ -17182,7 +17241,8 @@
"version": "4.5.15", "version": "4.5.15",
"resolved": "https://registry.npmmirror.com/@vue/cli-plugin-vuex/download/@vue/cli-plugin-vuex-4.5.15.tgz", "resolved": "https://registry.npmmirror.com/@vue/cli-plugin-vuex/download/@vue/cli-plugin-vuex-4.5.15.tgz",
"integrity": "sha512-fqap+4HN+w+InDxlA3hZTOGE0tzBTgXhKLoDydhywqgmhQ1D9JA6Feh94ze6tG8DsWX58/ujYUqA8jAz17FJtg==", "integrity": "sha512-fqap+4HN+w+InDxlA3hZTOGE0tzBTgXhKLoDydhywqgmhQ1D9JA6Feh94ze6tG8DsWX58/ujYUqA8jAz17FJtg==",
"dev": true "dev": true,
"requires": {}
}, },
"@vue/cli-service": { "@vue/cli-service": {
"version": "4.5.15", "version": "4.5.15",
@@ -17246,6 +17306,18 @@
"webpack-chain": "^6.4.0", "webpack-chain": "^6.4.0",
"webpack-dev-server": "^3.11.0", "webpack-dev-server": "^3.11.0",
"webpack-merge": "^4.2.2" "webpack-merge": "^4.2.2"
},
"dependencies": {
"file-loader": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/file-loader/-/file-loader-4.3.0.tgz",
"integrity": "sha512-aKrYPYjF1yG3oX0kWRrqrSMfgftm7oJW5M+m4owoldH5C51C0RkIwB++JbRvEW3IU6/ZG5n8UvEcdgwOt2UOWA==",
"dev": true,
"requires": {
"loader-utils": "^1.2.3",
"schema-utils": "^2.5.0"
}
}
} }
}, },
"@vue/cli-shared-utils": { "@vue/cli-shared-utils": {
@@ -17406,7 +17478,8 @@
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npm.taobao.org/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fpreload-webpack-plugin%2Fdownload%2F%40vue%2Fpreload-webpack-plugin-1.1.2.tgz", "resolved": "https://registry.npm.taobao.org/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fpreload-webpack-plugin%2Fdownload%2F%40vue%2Fpreload-webpack-plugin-1.1.2.tgz",
"integrity": "sha1-zrkktOyzucQ4ccekKaAvhCPmIas=", "integrity": "sha1-zrkktOyzucQ4ccekKaAvhCPmIas=",
"dev": true "dev": true,
"requires": {}
}, },
"@vue/reactivity": { "@vue/reactivity": {
"version": "3.2.29", "version": "3.2.29",
@@ -17674,7 +17747,8 @@
"version": "5.3.2", "version": "5.3.2",
"resolved": "https://registry.npmmirror.com/acorn-jsx/download/acorn-jsx-5.3.2.tgz", "resolved": "https://registry.npmmirror.com/acorn-jsx/download/acorn-jsx-5.3.2.tgz",
"integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==",
"dev": true "dev": true,
"requires": {}
}, },
"acorn-walk": { "acorn-walk": {
"version": "7.2.0", "version": "7.2.0",
@@ -17704,13 +17778,15 @@
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npm.taobao.org/ajv-errors/download/ajv-errors-1.0.1.tgz?cache=0&sync_timestamp=1616886041666&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv-errors%2Fdownload%2Fajv-errors-1.0.1.tgz", "resolved": "https://registry.npm.taobao.org/ajv-errors/download/ajv-errors-1.0.1.tgz?cache=0&sync_timestamp=1616886041666&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fajv-errors%2Fdownload%2Fajv-errors-1.0.1.tgz",
"integrity": "sha1-81mGrOuRr63sQQL72FAUlQzvpk0=", "integrity": "sha1-81mGrOuRr63sQQL72FAUlQzvpk0=",
"dev": true "dev": true,
"requires": {}
}, },
"ajv-keywords": { "ajv-keywords": {
"version": "3.5.2", "version": "3.5.2",
"resolved": "https://registry.npmmirror.com/ajv-keywords/download/ajv-keywords-3.5.2.tgz?cache=0&sync_timestamp=1637523970307&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fajv-keywords%2Fdownload%2Fajv-keywords-3.5.2.tgz", "resolved": "https://registry.npmmirror.com/ajv-keywords/download/ajv-keywords-3.5.2.tgz?cache=0&sync_timestamp=1637523970307&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fajv-keywords%2Fdownload%2Fajv-keywords-3.5.2.tgz",
"integrity": "sha1-MfKdpatuANHC0yms97WSlhTVAU0=", "integrity": "sha1-MfKdpatuANHC0yms97WSlhTVAU0=",
"dev": true "dev": true,
"requires": {}
}, },
"alphanum-sort": { "alphanum-sort": {
"version": "1.0.2", "version": "1.0.2",
@@ -21081,13 +21157,37 @@
} }
}, },
"file-loader": { "file-loader": {
"version": "4.3.0", "version": "6.2.0",
"resolved": "https://registry.npmmirror.com/file-loader/download/file-loader-4.3.0.tgz", "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-6.2.0.tgz",
"integrity": "sha512-aKrYPYjF1yG3oX0kWRrqrSMfgftm7oJW5M+m4owoldH5C51C0RkIwB++JbRvEW3IU6/ZG5n8UvEcdgwOt2UOWA==", "integrity": "sha512-qo3glqyTa61Ytg4u73GultjHGjdRyig3tG6lPtyX/jOEJvHif9uB0/OCI2Kif6ctF3caQTW2G5gym21oAsI4pw==",
"dev": true, "dev": true,
"requires": { "requires": {
"loader-utils": "^1.2.3", "loader-utils": "^2.0.0",
"schema-utils": "^2.5.0" "schema-utils": "^3.0.0"
},
"dependencies": {
"loader-utils": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.2.tgz",
"integrity": "sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==",
"dev": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"schema-utils": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.1.1.tgz",
"integrity": "sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==",
"dev": true,
"requires": {
"@types/json-schema": "^7.0.8",
"ajv": "^6.12.5",
"ajv-keywords": "^3.5.2"
}
}
} }
}, },
"file-uri-to-path": { "file-uri-to-path": {
@@ -26483,6 +26583,11 @@
"neo-async": "^2.6.0" "neo-async": "^2.6.0"
} }
}, },
"three": {
"version": "0.137.5",
"resolved": "https://registry.npmjs.org/three/-/three-0.137.5.tgz",
"integrity": "sha512-rTyr+HDFxjnN8+N/guZjDgfVxgHptZQpf6xfL/Mo7a5JYIFwK6tAq3bzxYYB4Ae0RosDZlDuP+X5aXDXz+XnHQ=="
},
"through": { "through": {
"version": "2.3.8", "version": "2.3.8",
"resolved": "https://registry.npm.taobao.org/through/download/through-2.3.8.tgz", "resolved": "https://registry.npm.taobao.org/through/download/through-2.3.8.tgz",

View File

@@ -2,13 +2,22 @@
"name": "vue-three-d-mockup", "name": "vue-three-d-mockup",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"author": "Anatoly Kopyl <akopyl@radner.ru>",
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"build-bundle": "vue-cli-service build --target lib --name vue-three-d-mockup ./src/index.js",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
"files": [
"dist/*",
"src/*",
"*.json",
"*.js"
],
"dependencies": { "dependencies": {
"core-js": "^3.6.5", "core-js": "^3.6.5",
"three": "^0.137.5",
"vue": "^3.0.0" "vue": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
@@ -20,6 +29,7 @@
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2", "eslint-plugin-import": "^2.20.2",
"eslint-plugin-vue": "^7.0.0" "eslint-plugin-vue": "^7.0.0",
"file-loader": "^6.2.0"
} }
} }

BIN
public/screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

View File

@@ -1,26 +0,0 @@
<template>
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue';
export default {
name: 'App',
components: {
HelloWorld,
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

35
src/Demo.vue Normal file
View File

@@ -0,0 +1,35 @@
<template>
<Mockup
class="mockup"
screenImg="screen.png"
/>
</template>
<script>
import Mockup from './Mockup.vue';
export default {
components: {
Mockup,
},
};
</script>
<style>
html, body {
height: 100%;
}
body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.mockup {
width: 500px;
height: 500px;
margin: auto;
}
</style>

95
src/Mockup.vue Normal file
View File

@@ -0,0 +1,95 @@
<template>
<div ref="canvas" />
</template>
<script>
import * as THREE from 'three';
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader';
import phoneObj from './assets/iphone.obj';
export default {
name: 'Mockup',
props: {
screenImg: {
type: String,
required: true,
},
lightClr: {
type: String,
default: 'hsl(0, 100%, 100%)',
},
},
data() {
return {
idle: true,
};
},
methods: {
init() {
const container = this.$refs.canvas;
const environmentInit = () => {
this.camera = new THREE.PerspectiveCamera(
45, container.clientWidth / container.clientHeight, 0.1, 10000,
);
this.scene = new THREE.Scene();
const light = new THREE.DirectionalLight(this.lightClr);
this.scene.add(light);
light.position.set(0, 0, 300);
this.camera.position.set(0, 0, 200);
};
const phoneInit = () => {
const loader = new OBJLoader();
const texture = new THREE.TextureLoader().load(this.screenImg);
const material = new THREE.MeshLambertMaterial({ map: texture });
const scale = 6;
const screen = new THREE.Mesh(
new THREE.PlaneGeometry(scale * 9, scale * 19.5), material,
);
screen.material.side = THREE.DoubleSide;
screen.translateZ(6);
this.phone = new THREE.Group();
this.phone.add(screen);
loader.load(
phoneObj,
(body) => {
body.position.y = -60;
this.phone.add(body);
this.scene.add(this.phone);
},
);
};
environmentInit();
phoneInit();
this.renderer = new THREE.WebGLRenderer({ antialias: true });
this.renderer.setSize(container.clientWidth, container.clientHeight);
container.appendChild(this.renderer.domElement);
},
animate() {
requestAnimationFrame(this.animate);
if (this.phone) {
this.idleAnimation();
}
this.renderer.render(this.scene, this.camera);
},
idleAnimation() {
this.phone.rotation.y += 0.02;
},
followAnimation() {
},
},
mounted() {
this.init();
this.animate();
},
};
</script>

72241
src/assets/iphone.obj Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

View File

@@ -1,58 +0,0 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br>
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
</ul>
<h3>Essential Links</h3>
<ul>
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String,
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

3
src/index.js Normal file
View File

@@ -0,0 +1,3 @@
import Mockup from './Mockup.vue';
export default Mockup;

View File

@@ -1,4 +1,4 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import App from './App.vue'; import App from './Demo.vue';
createApp(App).mount('#app'); createApp(App).mount('#app');

10
vue.config.js Normal file
View File

@@ -0,0 +1,10 @@
module.exports = {
chainWebpack: (config) => {
config.module
.rule('file-loader')
.test(/\.obj$/)
.use('file-loader')
.loader('file-loader')
.end();
},
};