threejs

webGL之three.js入门4--ThreeJS Editor入门篇

痞子三分冷 提交于 2020-01-15 02:54:54
因为工作需要,要看threejs editor的源码,顺便记录过程。 github下载的源码目录是这样的 但是editor和其他文件夹内的内容的关联的,我需要将其独立出来并且编辑editor。 进入editor,three.js-master\editor,打开index.html,从源码可以看出来,里面引用了上级目录的一些.js文件。 所以,要独立出来,就把../examples/js文件夹下的所有内容 拷贝 到three.js-master\editor\js目录下。然后把index.html中的“../examples/js”全部替换为“js”,步骤是:"ctrl+F"-->"Find All" ,这样就全部选中了,然后全部替换为“js” 这样,这个editor文件夹就从threejs master中独立出来了。 下面来看看index.html,有人会好奇,这里面没有写人任何样式和布局。其实 < link href ="css/main.css" rel ="stylesheet" /> < link id ="theme" href ="css/light.css" rel ="stylesheet" /> <link rel="stylesheet" href="js/libs/codemirror/codemirror.css"> <link rel=

ThreeJS 给 Shader传参

一笑奈何 提交于 2020-01-14 23:31:43
参考: https://www.cnblogs.com/softimagewht/p/4750847.html ThreeJS 给 Shader传参 一、Shader三种变量类型(uniform, attribute 和varying) 1、uniform 顶点着色器 和 片元着色器 都可以使用 一般用来传递:变换矩阵,材质,光照参数和颜色等信息 用法: 外部(js)给着色器传数据 // 着色器代码 uniform vec4 u_FragColor ; void main ( ) { gl_FragColor = u_FragColor ; } // js代码 var u_FragColor = gl . getUniformLocation ( gl . program , 'u_FragColor' ) ; gl . uniform4f ( u_FragColor , 0.0 , 1.0 , 1.0 , 1.0 ) ; 2、attribute 只能在 顶点着色器 中使用 一般用来传递顶点的数据,如:顶点坐标,法线,纹理坐标,顶点颜色 用法: 外部(js)给着色器传数据 类型: float,vec2,vec3,vec4,mat2,mat3,mat4 // 着色器代码 attribute vec4 a_Position ; void main ( ) { gl_position =

Threejs地球模型展示

淺唱寂寞╮ 提交于 2020-01-14 18:12:31
说明 使用 Threejs 展示地球模型的 Demo 贴图比较大,加载时间会比较久,请耐心等待 演示地址 https://hu243285237.github.io/Earth_Demo/ 项目地址 https://github.com/hu243285237/Earth_Demo 功能点 模型的加载和显示 加载进度的实时显示 贴图按顺序加载(最主要的贴图最先加载) 自适应屏幕(当缩放浏览器时,保持模型在正中间) 鼠标拖拽物体旋转(并且停止旋转时有缓冲效果) 滚轮缩放物体尺寸(并且限制缩放尺寸大小) 云层自旋转 插件 three.min.js ———— threejs 插件 OBJLoader.js ———— 用于加载物体 MTLLoader.js ———— 用于加载材质和贴图 模型来源 https://www.cgmodel.com/model-204627.html 更改了贴图的精度,所有贴图从 4096 改为 2048,以加快加载速度 部署 需要本地搭服务才能正常运行,比如 httpserver 直接打开 html 无法正常运行 来源: CSDN 作者: 哟呵呵和 链接: https://blog.csdn.net/m0_37250299/article/details/103924836

模拟ThreeJS相机

廉价感情. 提交于 2020-01-11 22:57:00
WebGL 对于我来说操作太繁琐了; ThreeJS太方便了,但是相关的数学计算也封装起来了, 但是这一部分又很重要,所以通过ThreeJS 来学习底层相机的实现。 这是一篇学习笔记,学习的内容出自: 代码 , 教程 。更多的代码也来自ThreeJS库。 WebGL本不存在相机,想的多了也就有了。 模拟ThreeJS相机 1、着色器代码 glsl.fragmentShader.js export let fragmentShader = ` uniform vec3 color; void main() { // 给此片元的颜色值 gl_FragColor = vec4(color,1.0); } ` glsl.vertexShader.js export let vertexShader = ` uniform mat4 myProjectionMatrix; uniform mat4 myModelViewMatrix; void main() { // gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); gl_Position = myProjectionMatrix * myModelViewMatrix *vec4(position,1); } ` 2、自己模拟的相机 export

简单好用threejs库3D可视化试一下?

↘锁芯ラ 提交于 2019-12-24 04:20:29
3D可视化应用开发对每个企业来说都是大工程,需要投入大量的人力物力财力才能做好这项工程,但其实可是化繁为简,不需要大费周章,具体来说,thingjs3D可视化开发平台,基于webgl3D绘制标准,使用最热门的Javascript语言,封装 threejs库 ,前端工程师可实现在线开发,可视化场景通过拖拽和简单写一些代码,对接数据源,项目部署之后就可以运行在您的服务器了~真是简单好用呢。 thingjs-面向物联网的3D可视化开发平台 /** * 说明:将场景中对象展示到界面上 * 操作:点击界面上选择框 * 说明:场景初始化完成后,子物体的显隐、样式默认继承父物体的显隐状态、样式 * 通过 obj.inheritVisible = true/false 控制子物体是否继承父物体显隐状态 */ // 引入jquery.easyui插件 THING.Utils.dynamicLoad(['lib/jquery.easyui.min.js', 'lib/default/easyui.css'], function() { var panel = `<div class="easyui-panel" style="opacity: 0; padding:5px; width: 300px;height: auto;margin-top: 10px;margin-left: 10px;

Three.js中文文档地址

╄→尐↘猪︶ㄣ 提交于 2019-12-11 23:27:58
考虑到threejs官网的文档有时候打开比较慢,为了方便大家编程使用,我申请了一个国内的阿里云服务器,在我的个人小站上部署了一份 Threejs中文文档 个人小站文档地址:http://www.yanhuangxueyuan.com/threejs/docs/index.html 来源: CSDN 作者: 郭隆邦技术博客 链接: https://blog.csdn.net/u014291990/article/details/103488137

ThreeJS Rotation Animation

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a cube in ThreeJS and I would like to rotate it 90 degrees clockwise every time I press a button. I think I have the basic gist of it: create a Three.Animation instance, bind it to the cube, and then have the animation begin every time I press the correct button. However, I'm having a difficult time understanding ThreeJS's API, because it doesn't seem to contain any examples for its methods. This is THREE.js's Animation constructor: ( root, data, interpolationType, JITCompile ) I don't understand what goes into the fields. I'm

threejs how to rotate around object&#039;s own center,instead of world center

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: two objects in the scene. the cube rotate axis should be the cube's center,that's my expect. but the shoe model's rotate axis is the world's y axis. my original code is. cube.rotation.y += 0.01; shoe.rotation.y += 0.01; I found a solution in stackoverflow,like this: cube.rotation.y += 0.01; var pivot = new THREE.Object3D(); pivot.add(shoe); pivot.rotation.y += 0.01; but it doesn't works. and then,I change the shoe's position. cube.rotation.y += 0.01; var pivot = new THREE.Object3D(); shoe.position.set(-5,0,0); pivot.add(shoe); pivot.rotation

Using webpack, threejs examples, and typescript?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having a lot of trouble getting stuff in threejs's examples (like EffectComposer or Detector) to work with webpack and typescript. First off the relevant *.d.ts files are all present and installed via tsd . My problem is getting webpack to actually include files outside of the default threejs build (namely things in examples/js/ ). With three installed from npm I can do something like import THREE = require('three'); Which works fine but lacks any of the aforementioned goodies. There are a few other threejs packages on npm that bundle

ThreeJS disable rendering of faces behind the Camera

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am Writing a Panorama Viewer . The Image is Displayed in a Sphere with a variable amount of faces. I want it only to render the faces in the camera direction (for better performance). Does ThreeJS do this automatically or can I declare specific faces of a mash that do not get rendered? like mash.faces[5].rendered = false; or so. 回答1: This process is called viewing frustum culling and ThreeJS takes care of this. ThreeJS also takes care of font and/or backface culling depending on your material settings. Meaning that only the