var scene,camera,render,camera;
var loader = new THREE.FontLoader();
//导入字体,设定字体,这里的话,你们找对自己的字体路径,可能和我的不一样的!!下载的three.js包里面examples/fonts里面有字体
loader.load('http://111.231.28.181:9527/ZH_CN.json',function(font){
init(font);
animate();
});
function initCamera() {
camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
camera.position.set(0, 40, 100);
camera.lookAt(new THREE.Vector3(0,0,0));
}
var mesh,gourps
function init(font){
// 老三样 场景scene,相机camera,渲染器render
scene=new THREE.Scene();
// 相机
camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,1000);
camera.position.set(0,10,500);
// 渲染器
renderer=new THREE.WebGLRenderer();
// LIGHTS
var dirLight = new THREE.DirectionalLight( 0xffffff, 0.125 );
dirLight.position.set( 0, 0, 1 ).normalize();
scene.add( dirLight );
var pointLight = new THREE.PointLight( 0xffffff, 1.5 );
pointLight.position.set( 0, 100, 90 );
scene.add( pointLight );
var plane = new THREE.Mesh(
new THREE.PlaneBufferGeometry( 10000, 10000 ),
new THREE.MeshBasicMaterial( { color: 'block', opacity: 0.5, transparent: true } )
);
plane.position.y = 10;
plane.rotation.x = 0;
scene.add( plane );
//背景颜色修改一下
renderer.setClearColor( 0xf9f9f9 );
renderer.setSize(window.innerWidth,window.innerHeight);
//显示在窗体
document.body.appendChild(renderer.domElement);
// 文字
var text = "卢黎最美";
var g = new THREE.TextGeometry(text,{
// 设定文字字体,
font:font,
//尺寸
size:30,
//厚度
height:10,
curveSegments:4,
bevelThickness:2
});
//计算边界,暂时不用管
g.computeBoundingBox();
//3D文字材质
var m = [
new THREE.MeshPhongMaterial({ color: 0x6698cb, flatShading: true }), // front
new THREE.MeshPhongMaterial({ color: 0x6698cb }) // side
];
gourps=new THREE.Group()
mesh = new THREE.Mesh(g,m);
gourps.add(new THREE.Object3D().add(mesh))
gourps.position.x=-100
// 加入到场景中
scene.add(gourps);
}
let loop=0
function animate(){
requestAnimationFrame( animate );
gourps.rotation.x += 0.04;
// 渲染
renderer.render(scene,camera);
}
body { margin: 0; }
canvas { display: block; }
console