<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ceshi</title>
<script type="text/javascript" src=".\build\three.js"></script>
<script src=".\examples\js\controls\TrackballControls.js"></script>
<script src=".\examples\js\controls\DragControls.js"></script>
<style>
body
{
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<!-- 作为Three.js渲染器输出元素 -->
<div id="WebGL-output">
</div>
<!-- 第一个 Three.js 样例代码 -->
<script type="text/javascript"> var camera, scene, renderer;
var sphere;
var controls;
var objects = []; var fov = 45;
var near = 0.1;
var far = 1000;
init();
render(); function init() { scene = new THREE.Scene(); //创建场景 camera = new THREE.PerspectiveCamera(fov, window.innerWidth / window.innerHeight, near, far); //创建摄像机
camera.position.x = 100;
camera.position.y = 100;
camera.position.z = 100;
camera.lookAt(scene.position); renderer = new THREE.WebGLRenderer(); //创建一个WebGL渲染器并设置其大小
renderer.setClearColor(new THREE.Color("#000000"));
renderer.shadowMapEnabled = true;
renderer.setSize(window.innerWidth, window.innerHeight); var ambientLight = new THREE.AmbientLight("#ffffff"); //加入场景光
scene.add(ambientLight); // var pointLight = new THREE.PointLight("#ffffff"); //加入点光源
// pointLight.position.set(110, 110, 110);
// pointLight.castShadow = true;
//scene.add(pointLight); var axes = new THREE.AxisHelper(200); //创建三轴表示
scene.add(axes); controls = new THREE.TrackballControls(camera); //创建场景旋转缩放事件
controls.rotateSpeed = 2.5;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
sphere = createMesh(new THREE.SphereGeometry(100, 100, 100), "./earth.jpg");
scene.add(sphere); window.addEventListener('resize', onWindowResize, false); } function createMesh(geom, imageFile) {
var texture = THREE.ImageUtils.loadTexture(imageFile);
var mat = new THREE.MeshPhongMaterial({ map: texture });
var mesh = new THREE.Mesh(geom, mat);
return mesh;
} function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); } function render() {
requestAnimationFrame(render); controls.update();
sphere.material.map.needsUpdate = true;
renderer.render(scene, camera);
} document.getElementById("WebGL-output").appendChild(renderer.domElement); </script>
</body>
</html>

不知道为什么,我再IE下能显示地球,在chrome下显示不了。

地球贴图下载地址:https://pan.baidu.com/s/1kVflpNh

【three.js练习程序】创建地球贴图的更多相关文章

  1. 在 Web 应用中创建 Node.js 应用程序

    本分步指南将通过 Azure Web 应用帮助您启动并运行示例 Node.JS 应用程序.除 Node.JS 外,Azure Web 应用还支持其他语言,如 PHP..NET.Node.JS.Pyth ...

  2. 用chrome的snippets片段功能创建页面js外挂程序,从控制台创建js小脚本

    用chrome的snippets片段功能创建页面js外挂程序,从控制台创建js小脚本 Chrome的snippets是小脚本,还可以创作并在Chrome DevTools的来源面板中执行.可以访问和从 ...

  3. nw.js桌面程序自动更新(node.js表白记)

    Hello Google Node.js 一个基于Google V8 的JavaScript引擎. 一个伟大的端至端语言,或许我对你的热爱源自于web这门极富情感的技术吧! 注: 光阴似水,人生若梦, ...

  4. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序创建更复杂的数据模型

    这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第六篇:为ASP.NET MVC应用程序 ...

  5. Xamarin iOS编写第一个应用程序创建工程

    Xamarin iOS编写第一个应用程序创建工程 在Xcode以及Xamarin安装好后,就可以在Xamarin Studio中编写程序了.本节将主要讲解在Xamarin Studio中如何进行工程的 ...

  6. 编程第一个Apple Watch程序创建项目

    编程第一个Apple Watch程序创建项目 2.4  编程第一个程序 本节将通过编写第一个程序,为开发者讲解如何添加Watch应用对象.运行程序.界面设计.编写代码等内容本文选自Apple Watc ...

  7. Contoso 大学 - 1 - 为 ASP.NET MVC 应用程序创建 EF 数据模型

    原文 Contoso 大学 - 1 - 为 ASP.NET MVC 应用程序创建 EF 数据模型 原文地址:Creating an Entity Framework Data Model for an ...

  8. MVC中使用EF(1):为ASP.NET MVC程序创建Entity Framework数据模型

    为ASP.NET MVC程序创建Entity Framework数据模型 (1 of 10) By  Tom Dykstra |July 30, 2013 Translated by litdwg   ...

  9. 为ASP.NET MVC应用程序创建更复杂的数据模型

    为ASP.NET MVC应用程序创建更复杂的数据模型 2014-05-07 18:27 by Bce, 282 阅读, 1 评论, 收藏, 编辑 这是微软官方教程Getting Started wit ...

随机推荐

  1. Choose GitLab for your next open source project

    原文:https://b.agilob.net/choose-gitlab-for-your-next-project/ GitLab.com is a competitor of GIthub. I ...

  2. Java内存模型(JSR133)问与答

    What is a memory model, anyway? In multiprocessor systems, processors generally have one or more lay ...

  3. js便签笔记(12)——浏览TOM大叔博客的学习笔记 part2

    1. 前言 昨天写了<js便签笔记(11)——浏览TOM大叔博客的学习笔记 part1>,简单记录了几个问题.part1的重点还是在于最后那个循环创建函数的问题,也就是多个子函数公用一个闭 ...

  4. Linux 一次杀死多进程

    .- | 说明: “grep firefox”的输出结果是,所有含有关键字“firefox”的进程. “grep -v grep”是在列出的进程中去除含有关键字“grep”的进程. “-”是截取输入行 ...

  5. Golang 接口interface

    接口interface 接口是一个或多个方法签名的集合 只要某个类型拥有该接口的所有方法签名,即算实现该接口,无需显示声明实现了哪个接口,这成为Structural Typing 接口只有方法声明,没 ...

  6. SpringBoot学习(二)——Spring的Java配置方式

    Java配置是Spring4.x推荐的配置方式,可以完全替代xml配置. 一.@Configuration 和 @Bean Spring的Java配置方式是通过@Configuration和@Bean ...

  7. Docker环境下搭建DNS LVS(keepAlived) OpenResty服务器简易集群

    现在上网已经成为每个人必备的技能,打开浏览器,输入网址,回车,简单的几步就能浏览到漂亮的网页,那从请求发出到返回漂亮的页面是怎么做到的呢,我将从公司中一般的分层架构角度考虑搭建一个简易集群来实现.目标 ...

  8. Visual Studio 监视与快速监视即时窗口没有智能提示

    工具->选项->文本编辑器->C# 将 自动列出成员 参数信息 都勾选上

  9. eclipse连接VisualSVN Server

    1.下载安装VisualSVN Server 2.修改资源库的网络连接.去掉默认的选中,修改端口,点击ok. 3.新建资源库Test,显示连接的地址http://svnybb/svn/Test/ .之 ...

  10. RocketMQ 消息存储

    消息存储 主要的存储文件: 1.消息文件(commitLog) 2.消息消费队列文件(consumeQueue) 3.Hash索引文件(IndexFile) 4.检测点文件(checkpoint) 5 ...