<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - custom attributes [lines]</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #ffffff;
font-family:Monospace;
font-size:13px;
text-align:center;
font-weight: bold; background-color: #000000;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 0px; width: 100%;
padding: 5px;
z-index:100;
} </style>
</head> <body>
<div id="info"><a href="http://threejs.org" target="_blank">three.js</a> - custom attributes example</div>
<div id="container"></div> <script src="js/Detector.js"></script>
<script src="js/libs/stats.min.js"></script> <script src="../build/three.js"></script> <script type="x-shader/x-vertex" id="vertexshader"> uniform float amplitude; attribute vec3 displacement;
attribute vec3 customColor; varying vec3 vColor; void main() { vec3 newPosition = position + amplitude * displacement; vColor = customColor; gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 ); } </script> <script type="x-shader/x-fragment" id="fragmentshader"> uniform vec3 color;
uniform float opacity; varying vec3 vColor; void main() { gl_FragColor = vec4( vColor * color, opacity ); } </script> <script> if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); var renderer, scene, camera, stats; var object, uniforms; var loader = new THREE.FontLoader();
loader.load( 'fonts/helvetiker_bold.typeface.json', function ( font ) { init( font );
animate(); } ); function init( font ) { camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 400; scene = new THREE.Scene(); uniforms = { amplitude: { value:1.0 }, //波动幅度?因后面有设置,所有这里值并没有太大的影响
opacity: { value: 0.3}, //不透明度(影响的是字体与Z轴平行面的线的透明度)
color: { value: new THREE.Color( 0xff0000 ) } }; var shaderMaterial = new THREE.ShaderMaterial( { uniforms: uniforms,
vertexShader: document.getElementById( 'vertexshader' ).textContent,
fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
blending: THREE.AdditiveBlending,
depthTest: false,
transparent: true }); var geometry = new THREE.TextGeometry( 'K o', { font: font, size: 50, //字体大小
height: 15, //字体厚度
curveSegments: 5, //曲线段 bevelThickness: 0,//齿厚(两侧再次向外延伸)
bevelSize:1.5,
bevelEnabled: true,
bevelSegments: 10, //曲边由几条折线构成 steps:40 //影响字体上下侧面的分段(影响的是字体与Z轴平行面的线的分段) } ); geometry.center(); var vertices = geometry.vertices; var buffergeometry = new THREE.BufferGeometry(); var position = new THREE.Float32Attribute( vertices.length * 3, 3 ).copyVector3sArray( vertices );
buffergeometry.addAttribute( 'position', position ); var displacement = new THREE.Float32Attribute( vertices.length * 3, 3 );
buffergeometry.addAttribute( 'displacement', displacement ); var customColor = new THREE.Float32Attribute( vertices.length * 3, 3 );
buffergeometry.addAttribute( 'customColor', customColor ); var color = new THREE.Color( 0xffffff ); for( var i = 0, l = customColor.count; i < l; i ++ ) { color.setHSL( i / l, 1.0, 0.4 );
color.toArray( customColor.array, i * customColor.itemSize ); } object = new THREE.Line( buffergeometry, shaderMaterial );
object.rotation.x = Math.PI*2;
scene.add( object ); renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setClearColor( 0x050505 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight ); var container = document.getElementById( 'container' );
container.appendChild( renderer.domElement ); stats = new Stats();
container.appendChild( stats.dom ); window.addEventListener( 'resize', onWindowResize, false ); } function onWindowResize() { camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix(); renderer.setSize( window.innerWidth, window.innerHeight ); } function animate() { requestAnimationFrame( animate ); render();
stats.update(); } function render() { var time = Date.now() * 0.001; object.rotation.y = Math.PI*2+time ; uniforms.amplitude.value = Math.sin( 0.5 * time )*0.1;
uniforms.color.value.offsetHSL( 0.0005, 0, 0 ); var attributes = object.geometry.attributes;
var array = attributes.displacement.array; for ( var i = 0, l = array.length; i < l; i += 3 ) { array[ i ] += 0.3 * ( 0.5 - Math.random() );
array[ i + 1 ] += 0.3 * ( 0.5 - Math.random() );
array[ i + 2 ] += 0.3 * ( 0.5 - Math.random() ); } attributes.displacement.needsUpdate = true; renderer.render( scene, camera ); } </script> </body> </html>

THREE.js代码备份——webgl - custom attributes [lines](自定义字体显示、控制字图的各个属性)的更多相关文章

  1. THREE.js代码备份——webgl - scene animation(通过加载json文件来加载动画和模型)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - sc ...

  2. THREE.js代码备份——webgl - geometry - dynamic(模拟海浪,通过时间(毫秒)来控制平面点的运动模拟海浪,鼠标控制写在另外的js中)

    HTML: <!DOCTYPE html> <html lang="en"> <head> <title>three.js webg ...

  3. THREE.js代码备份——webgl - materials - cube refraction [balls](以上下左右前后6张图片构成立体场景、透明球体效果)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - ma ...

  4. THREE.js代码备份——canvas - lines - colors(希尔伯特曲线3D、用HSL设置线颜色)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - l ...

  5. THREE.js代码备份——canvas_lines(随机点、画线)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - l ...

  6. THREE.js代码备份——线框cube、按键、鼠标控制

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - g ...

  7. THREE.js代码备份——canvas - geometry - earth(球体贴纹理)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js canvas - g ...

  8. THREE.js代码备份——canvas_ascii_effect(以AscII码显示图形)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js - ASCII Ef ...

  9. 图片攻击-BMP图片中注入恶意JS代码 <转载>

    昨天看到一篇文章<hacking throung images>,里面介绍了如何在BMP格式的图片里注入JS代码,使得BMP图片既可以正常显示, 也可以运行其中的JS代码,觉得相当有趣. ...

随机推荐

  1. ZooKeeper学习总结(1)——ZooKeeper入门介绍

    1. 概述 Zookeeper是Hadoop的一个子项目,它是分布式系统中的协调系统,可提供的服务主要有:配置服务.名字服务.分布式同步.组服务等. 它有如下的一些特点: 简单 Zookeeper的核 ...

  2. noip模拟赛 党

    分析:一道非常恶心的dp题.每个人要么选或不选,很像是0-1背包,可以套用背包问题的状态,但是因为题目要求3个值,所以可以再加一维表示3个答案. f[i][j][k][l][p][0/1/2]表示i个 ...

  3. nyoj_171_聪明的kk_201402281518

    聪明的kk时间限制:1000 ms  |  内存限制:65535 KB 难度:3描述 聪明的“KK”非洲某国展馆的设计灵感源于富有传奇色彩的沙漠中陡然起伏的沙丘,体现出本国不断变换和绚丽多彩的自然风光 ...

  4. [bzoj2850]巧克力王国_KD-Tree

    巧克力王国 bzoj-2850 题目大意:给出n块巧克力,每块巧克力都有自己的两个参数x和y和本身的价值val,询问:m个人,每个人有两个系数和一个限度a,b,和c.求所有ax+by<=c的巧克 ...

  5. php表单常用正则表达式

    <?php /** * @description: 正则表达式匹配 */ class Regex { /** * @手机号 */ public static function Phone($su ...

  6. 高速搞定Eclipse的语法高亮

    编辑器背景颜色 打开Preferences 选择TextEditors 语法高亮配色 这里以Javascript为例. 选择Javascript 点击右边圈出的绿色框里的选项,适当改动颜色, 高亮色參 ...

  7. Android 外部存储权限分析

    不知道你有么有发现.来自菜鸟的成长史:http://blog.csdn.net/zjbpku/article/details/25161131. KitKat之后的版本号不再支持用户对外置SDcard ...

  8. EarthWarrior3D游戏ios源代码

    这是一款不错的ios源代码源代码,EarthWarrior3D游戏源代码. 而且游戏源码支持多平台. 适用于cocos v2.1.0.0版本号 源代码下载: http://code.662p.com/ ...

  9. 学习笔记—— 一些UPDATE语句

    UPDATE语句原来还有许多种写法,有的还很复杂,孤陋寡闻的我甚至闻所未闻.幸甚至哉,记而志之. 0.UPDATE 表名 SET 字段... FROM ...的方式 USE AdventureWork ...

  10. poj--3061--Subsequence(贪心)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10882   Accepted: 4498 Desc ...