|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 O1 N9 d! h: L5 c
3 t' P% b$ E+ j) `7 Z' ^废话不多说,官网自己百度下, threejs.org ,入门很简单。
& R0 G" V: F" V6 _( j, _0 g/ m% c- G. e( L
创建的javascript脚本如下
$ v* Z/ `2 v \0 S1 [8 w4 u, u& U6 S# @ ?- f4 |
1 o. u* y! A9 o0 Z O[mw_shl_code=javascript,true]
# C% @# n! h% s" O" ]var scene = new THREE.Scene();
' J" m! c# J, D" n# f8 Y+ ~var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
5 R2 b: M* z+ A) }+ ?! d, [var renderer = new THREE.WebGLRenderer();' W& o7 N! p. ]* E5 p/ u6 D! o9 h
renderer.setSize(window.innerWidth, window.innerHeight);
% c4 o" M) c+ c. M3 Fdocument.body.appendChild(renderer.domElement);
+ g/ x o: ~9 C/ j9 P: H1 |4 b( ~( B( b* v4 x5 l
// Refresh Issue
) Q2 X; ?0 m7 d) i4 K1 H9 _window.addEventListener('resize', function () {
: N [! z V1 z. h/ v" |: i var width = this.window.innerWidth;. ^( U1 _1 q4 n4 ^3 R
var height = this.window.innerHeight;
2 D+ H$ g' J% g6 t0 H render.setSize(width, height);
, O! I, c) `! l5 P- g$ G2 v( K camera.aspect = width / height;. l6 p7 _$ }0 Y, l) ~$ c- T$ C
camera.updateProjectionMatrix();
# T; U# x( j( N})
5 Q6 ~5 e2 @ W
2 H5 a# e: N% O" Z! ?//orbit contorls1 B1 j9 j2 w# u# n
controls = new THREE.OrbiTControls(camera,renderer.domElement);+ |; f0 m3 c/ x; S/ I! I# [5 e
% i& e( h3 a) c% m7 N/ z
//create the shape
% W1 g ?8 R4 [2 Q2 G- P! Tvar geometry = new THREE.TorusGeometry(2, 1, 16, 100);
& x5 P- F3 H; {/ c//create a meterial
6 {% n9 C. ]2 _, F& F( ~5 [var material = new THREE.MeshBasicMaterial({ color: 0xffff00, wireframe: true, });
! l& M% h4 v4 B: J! [! r& R//var myMaterial = [new THREE.MeshBasicMaterial({map:new THREE.TextureLoader().load('image/plmhome.png'),side:THREE.DoubleSide}),];7 y& Z5 Q3 H1 }" M
//var material = new THREE.MeshFaceMaterial(myMaterial);) C/ I+ I( P2 Q/ Y& ~6 D3 R
1 O5 G8 d" d$ \1 Hvar cube = new THREE.Mesh(geometry, material);2 V9 |4 |) I7 Y9 w7 R
scene.add(cube);: |/ ^- t8 {; \9 Y `4 Q$ ~1 ]
camera.position.z = 5;
' b, ]& X! ]% C2 ]8 l: t: r4 Y9 `) I
5 l. |5 H3 F1 w8 D
1 X2 O; m3 ]4 ]3 S
3 h# t3 ~$ w1 N5 f) [
- O/ f0 e$ H% i' w. x" O' v0 P6 E1 l% q" \
//rotate
) u# t$ [( X. _8 tvar update = function () {
4 h7 x9 i; X& ]* A# T' F3 s: t cube.rotation.x += .01;& } V6 @0 c& U' [
cube.rotation.y += .02;! ?6 a9 r) _. h% a2 z
cube.rotation.z += .02;
+ C& h$ o3 ]6 n: { N}
( M1 `/ t) _8 a: |# p: l
- o# q0 e( e3 S4 I( L* N" D0 ^) Avar render = function () {6 A) Z# w/ G4 g2 I
renderer.render(scene, camera);
3 c$ P2 {$ t/ t}+ H. | r2 x1 r* z" @* K
( o/ t) D! k( Z/ W! i' [
2 T" \* ~( R; Y7 c7 ^3 ]: Q
4 ?& ?; d3 V. J& Z
var Gameloop = function () {
6 X/ {, P! C/ Q% a+ x1 S requestAnimationFrame(Gameloop);
& k W; F, @# W) o update();
' E1 o9 l% n5 O: C; D6 P6 d render();
, G5 G9 ]* T( k# w7 k Z}
; W! A' X( G/ [1 f' t
# y$ m- h1 O$ d8 m OGameloop();: L6 c' f+ f# ^5 q1 o4 X; v! {+ L
[/mw_shl_code]7 m0 r; H+ E! K: ~) L
$ |8 J* O7 @6 F9 U% l8 r
8 l) p" @ L _ G2 O- U引入争取的html,
8 X S( `: X/ z8 ^% i# C
( E% L1 t3 L( d; Q/ {+ S! O[mw_shl_code=html,true]<!DOCTYPE html>
" E5 V. I) D& v5 t9 N e$ O<html>
* e/ w# y9 U- b
3 ]2 [' ^+ H. j7 ~' E: V<head>* W5 M0 H, z6 Y" h$ T# W
<title>hello ThreeJS</title>$ n0 ^9 d5 b1 F! p/ O, v
<style>. G% s* v/ E3 \5 \& p: I7 u. [8 h/ a
body {
2 [4 W0 R! h3 j9 f$ { margin: 0;7 Q6 C, s* M! t: i6 I8 r7 r
}2 B2 y6 u! ^ d5 ]
/ N2 _$ \3 u$ X% L) j y, o. E canvas {% A6 h1 H3 R( h6 Z" _& X) A
width: 100%;
. ?# l& q$ b; T7 K2 c% | height: 100%;
: \! O; c" O3 d& P# W; ~ }! t# _) W B" D
* B J, n) q: F3 Q/ g5 Q
h1 {
9 [$ I' ]: }( P: n) t% k" W6 X color: aqua;
: ^* }4 j' l" ]5 E+ l* m$ n9 }. @ }
" N, g2 ?9 b- |" g" c4 L1 C7 Q9 X0 X </style>& I0 T9 @) N4 S1 c P/ H/ J5 Y M' l
</head>
0 R7 h8 I) m+ ~* d* `/ X9 i8 W! h& b- m& F; V( K3 W% W
<body> T, b7 n' k0 A/ x+ _ T( L
<script src="js/three.js"></script>
- V$ G* O {' Z! C7 C& D <script src="js/OrbitControls.js"></script>
0 }1 Y4 X5 Z! B <script src="myjs.js"></script>
: g$ n% X/ n/ H2 F- F% |
- Y" j& G* R' ^' { Q& V# v% G
1 X+ y6 d6 C% s& _$ Q! V6 c
) \& y1 G8 { y7 E4 y" J7 P2 L# i" n# l$ y! R( l/ m
</body>) Z- M) k, Y: `' e% Y
) `* ^, @+ G4 T3 J# u Y. h
</html>[/mw_shl_code]
7 m' t0 M5 s9 J6 ^# o: \
4 B! r b6 C5 a3 a1 C效果点击这里:3 [% c3 d3 G4 K/ H; I
4 b. H9 z8 b+ q. l3 Uhttp://plmhome.com/doteam/lesson1.html8 A, p! b! J. [# s: C K/ b
A9 T6 T" N) H/ z3 j9 V' d- W( O) ]; T6 `. ~6 k( I+ `; z9 {! A
|
|