|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; f* `) T! k# b7 y5 b' C
* b# U8 a3 ~3 C- X废话不多说,官网自己百度下, threejs.org ,入门很简单。* w" ~- i4 |: a7 s! W- w, m
3 ?- d0 |- A5 a! K G( l) V创建的javascript脚本如下
4 L& z% ^) _' W$ S
3 y1 L0 S( s7 I2 N7 H- c# C
. Y: x& b, w0 i) E( a" D% \' w
[mw_shl_code=javascript,true]& X4 h: [. c4 j) W6 o" U
var scene = new THREE.Scene();
/ h: ~5 y- _- yvar camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);6 \$ o9 O: i( J% d# S( f
var renderer = new THREE.WebGLRenderer();5 p+ @$ X1 Z, s5 |' c* q
renderer.setSize(window.innerWidth, window.innerHeight);1 j/ N: v" [2 B/ _
document.body.appendChild(renderer.domElement);
- Y$ B: P6 i/ q& `' Y$ c( P5 N/ J" s; s" H5 i* @" q
// Refresh Issue 8 N; H) l L8 l# h7 p: D' O. |( t, {
window.addEventListener('resize', function () {" C: u' K# S! B% a* q
var width = this.window.innerWidth;9 u, L+ C& g& g7 [* @
var height = this.window.innerHeight;1 C7 h" O( g0 ?0 Z
render.setSize(width, height);
+ y9 `6 Z0 p7 v# g) ~' X U camera.aspect = width / height;
( t, ~2 X, l$ S$ k3 n j camera.updateProjectionMatrix();1 a- G7 Q6 v5 C0 V. v- B
}); h: _, j7 [. d: T
7 j8 Z( n8 U- @+ N, n6 Y
//orbit contorls( s8 @' F+ ^! K& f5 Z* z6 s
controls = new THREE.OrbiTControls(camera,renderer.domElement);
* j% c( i: e; X6 k: i9 U; h% ?' H
//create the shape
3 F0 H. E/ R2 e4 A0 Evar geometry = new THREE.TorusGeometry(2, 1, 16, 100);' K o* ~. ~* O
//create a meterial
9 ^+ P( t8 P2 [7 v: @1 h3 }var material = new THREE.MeshBasicMaterial({ color: 0xffff00, wireframe: true, });) _4 L" B7 U( e$ d
//var myMaterial = [new THREE.MeshBasicMaterial({map:new THREE.TextureLoader().load('image/plmhome.png'),side:THREE.DoubleSide}),];! \9 w/ u; J) k2 i( z; R: Z
//var material = new THREE.MeshFaceMaterial(myMaterial);
& e: }8 F' N3 q2 | k% O5 }# K
% o* l* ~/ I, l6 ~# pvar cube = new THREE.Mesh(geometry, material);: H( ~" F) r ?+ h/ u* B6 m
scene.add(cube);
3 D+ I$ L7 t' y, ~) q3 s5 F6 ?camera.position.z = 5;5 R3 L& g# ?- O7 K. Z
( B, ]: a; {) ?. N. v/ j- D
* t% b4 }2 P5 |8 A4 x& X4 f t
3 X7 t' D, v; ^! @2 d4 i/ ]+ E5 _& F- e. T) h& O" q, C9 J5 R
" Z3 `5 Y1 G0 W) V4 a6 _//rotate
% u: M# c' y. |9 `7 Lvar update = function () {* }2 v+ R: u( L. ^2 U7 u% Q: E& a
cube.rotation.x += .01;( {+ d2 m, F# i
cube.rotation.y += .02;
( v9 P5 l4 Y& T7 h cube.rotation.z += .02;
; C- N: m! _+ [}
* O" { ?9 l; k2 w2 N0 M; |: s9 e4 w- o/ s, `1 F6 J
var render = function () {4 L5 g; t ~* w3 V$ i& M( Z9 g$ e
renderer.render(scene, camera);
( r( `( z5 R/ [% y}
- {; h2 O# j9 U% b( ]7 ]! k: s
7 Y' w+ f$ q9 C0 k2 B0 f+ v. e! L8 V& A- K% B% T1 w0 _
9 v. S7 T- {$ l0 V0 k+ _
var Gameloop = function () {
5 \% L- q$ l8 A' S# O6 d requestAnimationFrame(Gameloop);" _8 F% S2 B& }+ r4 M
update();% `: [! [* I, X1 z8 I
render();
7 p3 C6 h# d6 h1 j+ x}( v6 o. ]" J$ Y# Q2 x* l6 T
7 c9 q$ @& s; |Gameloop();8 G3 Y0 |4 r. B- I3 h5 a. `( n
[/mw_shl_code]
% |7 P- C$ K' J0 |$ J! i. @ I) d) e2 j5 ]& Z( O: m) N6 d
: N7 ?; Q9 G9 S0 q" Z引入争取的html,+ [( g3 g1 U- T5 v2 L
0 j/ o4 j4 w7 w5 A, C% _+ g: _
[mw_shl_code=html,true]<!DOCTYPE html>8 B; D6 f6 O f3 `1 S& S% A
<html>
: E) V7 V4 H( R+ A7 m) u' s4 ^
5 X8 b M2 b6 M$ \& Q$ Z<head>- u0 h3 b0 ^) I* M! X; O( ]
<title>hello ThreeJS</title>
, m, s' B& L4 j& g; `0 s <style>* B3 F! h& p n# _9 X0 ^
body {: r9 @* ^1 h$ M f1 e9 h1 i
margin: 0;; U1 a8 ^% X! Q3 u
}( V7 i( c [- y5 x+ k$ Y, t) z) P
7 @6 f) @4 c# l canvas {
/ F/ I3 T$ M6 b8 I' p1 C7 I' k$ X. L width: 100%;! c" x5 Z2 Y# `2 C" K# Z$ g
height: 100%;
) }, y. Q* a* R3 |* f& I }9 V. }7 C% `* b6 l" c& c! X
. `- b& a3 ^+ y6 b4 C. X
h1 {( }/ u) q v+ ^2 L& W2 G
color: aqua;9 l( B% M; V5 d7 q8 G9 t
}
; E a% J8 Q. k- }& J </style>1 k4 |' [/ k+ h7 F
</head>9 e4 l' y$ L2 L0 g) w
1 h% z5 ]4 S: ^+ g. w X<body>1 Q3 c9 b' x& O( `' t, ~/ o
<script src="js/three.js"></script>
. \0 d' \7 r' r G; v, S <script src="js/OrbitControls.js"></script>
" O6 E% V F/ |& G7 c! U <script src="myjs.js"></script>
, b6 V& K0 t; R2 }4 r# o* D6 M
' J/ V# s% O( a/ N
( i/ Z& ` N4 b' T3 z$ j' x/ o9 K; T7 V! g( h2 E; @
& T$ q* l4 m& B: V
</body>9 f' X: |( y2 u& u# k5 j
3 ^5 W9 P' C5 @</html>[/mw_shl_code]4 D6 p: P f0 t# Z
7 h, q3 j) K! h+ r1 o" ?/ Z
效果点击这里:
1 ?0 j0 t- i2 o# `% i. U: d6 I# {5 W6 @! [0 c
http://plmhome.com/doteam/lesson1.html5 M s% B( ]5 u! a% T- b7 g; p
* N6 m0 j3 N6 k. t: q8 W& P' s+ {3 a ]
|
|