Skip to content

Commit df5b753

Browse files
authored
lint fix & touch event support with demo (#20)
1 parent e0cadaf commit df5b753

File tree

13 files changed

+1325
-28
lines changed

13 files changed

+1325
-28
lines changed

example/app.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
{
2-
"pages": [
3-
"index/index"
4-
],
5-
"window": {
6-
"backgroundTextStyle": "light",
7-
"navigationBarBackgroundColor": "#fff",
8-
"navigationBarTitleText": "WeChat",
9-
"navigationBarTextStyle": "black"
10-
},
11-
"sitemapLocation": "sitemap.json"
1+
{
2+
"pages": [
3+
"index/index"
4+
],
5+
"window": {
6+
"backgroundTextStyle": "light",
7+
"navigationBarBackgroundColor": "#fff",
8+
"navigationBarTitleText": "WeChat",
9+
"navigationBarTextStyle": "black"
10+
},
11+
"sitemapLocation": "sitemap.json"
1212
}

example/app.wxss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**app.wxss**/
2+
page {
3+
width: 100%;
4+
height: 100%;
5+
margin: 0;
6+
padding: 0;
7+
}
8+
9+
.container {
10+
height: 100%;
11+
display: flex;
12+
flex-direction: column;
13+
align-items: center;
14+
justify-content: space-between;
15+
padding: 200rpx 0;
16+
box-sizing: border-box;
17+
}

example/index/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Page({
1616
.node()
1717
.exec((res) => {
1818
const canvas = res[0].node
19+
this.canvas = canvas
1920
const THREE = createScopedThreejs(canvas)
2021

2122
// renderSphere(canvas, THREE)
@@ -24,4 +25,13 @@ Page({
2425
renderModel(canvas, THREE)
2526
})
2627
},
28+
touchStart(e) {
29+
this.canvas.dispatchTouchEvent({...e, type:'touchstart'})
30+
},
31+
touchMove(e) {
32+
this.canvas.dispatchTouchEvent({...e, type:'touchmove'})
33+
},
34+
touchEnd(e) {
35+
this.canvas.dispatchTouchEvent({...e, type:'touchend'})
36+
}
2737
})

example/index/index.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"usingComponents": {}
2+
"usingComponents": {},
3+
"disableScroll": true
34
}

example/index/index.wxml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
type="webgl"
44
id="webgl"
55
style="width: 100%; height: 450px;"
6+
bindtouchstart="touchStart"
7+
bindtouchmove="touchMove"
8+
bindtouchend="touchEnd"
69
></canvas>
710
<canvas
811
type="webgl"

example/index/index.wxss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.intro {
2-
margin: 30px;
3-
text-align: center;
1+
.intro {
2+
margin: 30px;
3+
text-align: center;
44
}

example/miniprogram_npm/threejs-miniprogram/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/test-cases/model.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { registerGLTFLoader } from '../loaders/gltf-loader'
2+
import registerOrbit from "./orbit"
23

34
export function renderModel(canvas, THREE) {
45
registerGLTFLoader(THREE)
56

67
var container, stats, clock, gui, mixer, actions, activeAction, previousAction;
7-
var camera, scene, renderer, model, face;
8+
var camera, scene, renderer, model, face, controls;
89
var api = { state: 'Walking' };
910
init();
1011
animate();
@@ -45,6 +46,12 @@ export function renderModel(canvas, THREE) {
4546
renderer.setSize(canvas.width, canvas.height);
4647
renderer.gammaOutput = true;
4748
renderer.gammaFactor = 2.2;
49+
50+
const { OrbitControls } = registerOrbit(THREE)
51+
controls = new OrbitControls( camera, renderer.domElement );
52+
53+
camera.position.set( 5, 5, 10 );
54+
controls.update();
4855
}
4956

5057
function createGUI(model, animations) {
@@ -81,11 +88,11 @@ export function renderModel(canvas, THREE) {
8188
.fadeIn(duration)
8289
.play();
8390
}
84-
8591
function animate() {
8692
var dt = clock.getDelta();
8793
if (mixer) mixer.update(dt);
8894
canvas.requestAnimationFrame(animate);
95+
controls.update()
8996
renderer.render(scene, camera);
9097
}
9198
}

0 commit comments

Comments
 (0)