Skip to content

Commit f29192d

Browse files
committed
* readme, pkg.json, favicon, examples
vuejs/vue#681 (comment) vuejs/Discussion#354 (comment)
1 parent 4d157c1 commit f29192d

File tree

12 files changed

+46
-41
lines changed

12 files changed

+46
-41
lines changed

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
# vue-threejs
22

33
> [WIP] Simplest bindings between [Vue][react] & [Three.js][threejs]
4+
45
> Migrated from [react-threejs](https://github.com/fritx/react-threejs)
56
67
<img width="400" src="https://github.com/fritx/react-threejs/raw/dev/debugging.jpg">
78

9+
```js
10+
import VueThreejs from 'vue-threejs'
11+
Vue.use(VueThreejs)
12+
```
13+
814
```vue
915
<template>
10-
<renderer :size="size">
16+
<renderer :dim="dim">
1117
<scene>
12-
<camera :size="size" :position="camPos"></camera>
13-
<ocean :position="oceanPos"></ocean>
18+
<camera :dim="dim" :position="{ z: 15 }"></camera>
19+
<object3d :obj="mesh" :position="{ y: -200 }"></object3d>
1420
</scene>
1521
</renderer>
1622
</template>
1723
```
1824

1925
**Study Notes**
2026

21-
- [v-ref is not working with ~~<template>~~(dom) element](https://github.com/vuejs/vue/issues/681#issuecomment-75802646)
27+
- [v-ref is not working with <template> element](https://github.com/vuejs/vue/issues/681#issuecomment-75802646)
2228
- [Can I use a compoent inherit other compoent?](https://github.com/vuejs/Discussion/issues/354#issuecomment-133019536)
2329

2430
[react-threejs]: https://github.com/fritx/react-threejs

build/webpack.base.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var projectRoot = path.resolve(__dirname, '../')
55

66
module.exports = {
77
entry: {
8-
app: './src/main.js'
8+
app: './src/examples/main.js'
99
},
1010
output: {
1111
path: config.build.assetsRoot,

config/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
index: path.resolve(__dirname, '../dist/index.html'),
88
assetsRoot: path.resolve(__dirname, '../dist'),
99
assetsSubDirectory: 'static',
10-
assetsPublicPath: '/',
10+
// assetsPublicPath: '/',
11+
assetsPublicPath: '',
1112
productionSourceMap: true
1213
},
1314
dev: {

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<title>vue-threejs</title>
6+
<link rel="icon" href="static/vue.png" type="image/x-icon">
67
</head>
78
<body>
89
<app></app>

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
"version": "0.0.0",
44
"description": "Simplest bindings between Vue & Three.js",
55
"author": "Fritz Lin <[email protected]>",
6-
"private": true,
76
"scripts": {
87
"dev": "node build/dev-server.js",
98
"build": "node build/build.js",
109
"test": "",
1110
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
1211
},
1312
"dependencies": {
14-
"babel-runtime": "^6.0.0",
15-
"vue": "^1.0.21"
13+
"babel-runtime": "^6.0.0"
1614
},
1715
"peerDependencies": {
18-
"three": "^0.76.1"
16+
"three": "^0.76.1",
17+
"vue": "^1.0.21"
1918
},
2019
"devDependencies": {
2120
"babel-core": "^6.0.0",

src/components/Camera.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
mixins: [Object3D],
1111
1212
props: {
13-
size: {
13+
dim: {
1414
type: Object, // { width, height }
1515
required: true
1616
},
@@ -20,7 +20,7 @@ export default {
2020
},
2121
2222
created () {
23-
const { width, height } = this.size
23+
const { width, height } = this.dim
2424
if (!(this.obj instanceof Camera)) {
2525
this.obj = new PerspectiveCamera(75, width / height, 0.1, 1000)
2626
}

src/components/Renderer.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { WebGLRenderer } from 'three'
99
1010
export default {
1111
props: {
12-
size: {
12+
dim: {
1313
type: Object, // { width, height }
1414
required: true
1515
},
@@ -22,7 +22,7 @@ export default {
2222
this.obj = new WebGLRenderer({ antialias: true })
2323
}
2424
this.obj.name = this.obj.name || this.constructor.name
25-
this.obj.setSize(this.size.width, this.size.height)
25+
this.obj.setSize(this.dim.width, this.dim.height)
2626
this.obj.setClearColor(0x000000)
2727
},
2828

src/App.vue src/examples/App.vue

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33
</style>
44

55
<template>
6-
<renderer :size="size">
6+
<renderer :dim="dim">
77
<scene>
8-
<camera :size="size" :position="camPos"></camera>
9-
<ocean :position="oceanPos"></ocean>
8+
<camera :dim="dim" :position="{ z: 15 }"></camera>
9+
<ocean :position="{ y: -200 }"></ocean>
1010
</scene>
1111
</renderer>
1212
</template>
1313

1414
<script>
15-
import Ocean from './examples/Ocean'
15+
import Ocean from './Ocean'
1616
1717
export default {
1818
components: { Ocean },
1919
2020
data () {
2121
return {
22-
size: {
22+
dim: {
2323
width: window.innerWidth,
2424
height: window.innerHeight
25-
},
26-
oceanPos: { y: -200 },
27-
camPos: { z: 15 }
25+
}
2826
}
2927
}
3028
}

src/examples/Ocean.vue

+18-18
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ import Object3D from '../components/Object3D'
1111
export default {
1212
mixins: [Object3D],
1313
14-
data () {
15-
return { mesh: null }
16-
},
17-
1814
created () {
1915
this.animate = this.animate.bind(this)
2016
this.clock = new THREE.Clock()
21-
22-
const geometry = this.geometry = new THREE.PlaneGeometry(10000, 10000, 40, 40)
23-
geometry.rotateX(-Math.PI / 2)
24-
for (var i = 0, l = geometry.vertices.length; i < l; i++) {
25-
geometry.vertices[ i ].y = 10 * Math.sin(i / 2)
26-
}
27-
28-
const texture = new THREE.TextureLoader().load(require('./water.jpg'))
29-
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
30-
texture.repeat.set(5, 5)
31-
const material = new THREE.MeshBasicMaterial({ color: 0x0044ff, map: texture })
32-
33-
this.mesh = new THREE.Mesh(geometry, material)
34-
this.mesh.name = 'Ocean'
17+
this.mesh = this.createOcean()
3518
},
3619
3720
ready () {
3821
this.animate()
3922
},
4023
4124
methods: {
25+
createOcean () {
26+
const geometry = this.geometry = new THREE.PlaneGeometry(10000, 10000, 40, 40)
27+
geometry.rotateX(-Math.PI / 2)
28+
for (var i = 0, l = geometry.vertices.length; i < l; i++) {
29+
geometry.vertices[ i ].y = 10 * Math.sin(i / 2)
30+
}
31+
32+
const texture = new THREE.TextureLoader().load(require('./water.jpg'))
33+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
34+
texture.repeat.set(5, 5)
35+
const material = new THREE.MeshBasicMaterial({ color: 0x0044ff, map: texture })
36+
37+
const mesh = new THREE.Mesh(geometry, material)
38+
mesh.name = 'Ocean'
39+
return mesh
40+
},
41+
4242
animate () {
4343
requestAnimationFrame(this.animate)
4444
const time = this.clock.getElapsedTime() * 5

src/main.js src/examples/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import App from './App'
3-
import VueThreejs from './'
3+
import VueThreejs from '../'
44

55
Vue.use(VueThreejs)
66

static/.gitkeep

Whitespace-only changes.

static/vue.png

11.2 KB
Loading

0 commit comments

Comments
 (0)