three.js

canvas ,webGL, svg

一世执手 提交于 2020-08-05 18:27:15
SVG只是一种 矢量图 形文件格式, 不仅现在的浏览器都支持,很多主流的系统也都支持。 Canvas 是HTML5新增的一个元素对象,名副其实就是一个画布,浏览器 js 配有相应的操作api,可以不再依赖其他的API或组件而直接绘图,相当于 2D的API 。 WebGL 是以 OpenGL ES 2.0 为基础的一套 浏览器 3D图形API (HTML5),在编程概念上与OpenGL ES 2.0 几乎是完全通用的,同样采用可编程渲染管线,也就是每个顶点的处理受到一小段Vertex Shader代码的控制,每个像素的绘制过程也受到一小段Fragment Shader代码的控制。WebGL主要是3D为主, 不过2D的绘图要求也可以变通来实现。 WebGL 无论如何都需要一个显示对象来呈现,这个对象就是 Canvas,仅此而已,WebGL不对Canvas有任何附加的操作API, 那部分属于浏览器js支持的范畴。 WebGL 也继承 OpenGL ES 2.0 的兼容性支持能力, 在不同的设备上做有限的支持,需要运行时查询。 Three.js 、Babylon.js、Blender4Web等是几种知名的 WebGL 开发框架,对 WebGL 基础操作做了大量的封装,可以拿来就用, 即使不了解 WebGL规范的细节。 d3.js 是采用svg的数据驱动Dom ,用来对数据进行可视化

vue 中使用threejs

懵懂的女人 提交于 2020-08-04 19:17:41
1、安装threejs : npm install three --save 2、页面引入 :import * as THREE from "three"; 如果使用到 OrbitControls 和 CSS3DRenderer import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"; import { CSS3DRenderer,CSS3DObject } from "three/examples/jsm/renderers/CSS3DRenderer.js"; // 注意一定要引入CSS3DObjec 3、图片放在哪儿? 在public下新建一个文件夹static 里面放入图片(如果图片放到src->assets图片文件夹中渲染时不显示图片) 4、在vue环境中渲染页面时明显比直接引入three.js方式卡 scene和camera等不要放在data里面,要在mounted时初始化,beforeDestroy时定时器清空 完整代码 <template> <div class="wrap"> <div ref="container" id="container"></div> </div> </template> <script> import * as THREE from

Drawing polylines on Google Maps Streetview

江枫思渺然 提交于 2020-08-02 16:22:12
问题 I'm drawing some Markers and Polylines on Google Maps v3.exp. When I switch to StreetView, the markers are there, Polylines are not . Searched over the Google, SO, and all other known resources, and surprisingly there are absolutely no hints whatever about this particular question. Does anyone have any deeper information about the issue or is it hopeless to display for example some road information overlay on Streetview? A bit on different topic (although, related) - second thing I tried in

How to make a loading screen in three.js?

只愿长相守 提交于 2020-07-31 07:55:12
问题 I have a large amount of textures and models to load into my project. I am trying to show a progress bars while everything is loading. I think the LoadingManager does just what I need as it tracks the progress of all loaded assets. I'm using the JSONLoader and TextureLoader. If anyone could show me how to do implement this in the example code would be awesome. var camera, scene, renderer; init(); animate(); function init() { camera = new THREE.PerspectiveCamera(70, window.innerWidth / window

three.js 制作属于自己的动态二维码

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-24 17:10:44
今天郭先生说一下用canvas解析图片流,然后制作一个动态二维码的小案例,话不多说先上图,在线案例点击 博客原文 。这是郭先生的微信二维码哦! 1. 解析图片流 canvas = document.createElement('canvas'); // 创建canvas画布 content = canvas.getContext('2d'); // 获取画布的上下文 canvas.width = 310; // 设置尺寸 canvas.height = 310 ; img = new Image(); // 创建一张图片 img.src = require("../assets/images/base/wechat.png"); // 设置图片地址 img.onload = () => { // 在图片加载后 content.drawImage(img, 0, 0, canvas.width, canvas.height); // 将图片添加到画布,并设置宽高 imgData = content.getImageData(0, 0, canvas.width, canvas.height).data; // 获取画布数据 }; imgData是什么样的呢?如下图 这是一个Uint8ClampedArray的类型化数组,这个数组出现最多的也是在imgData上。它会将负数归入0

I just know how to use for to draw the tree, but now I want to use recursion to draw the tree

痞子三分冷 提交于 2020-07-23 08:45:10
问题 I just know how to use for to draw a tree (the tree data is the picture one, the result is picture two), but now I want to use recursion to draw the tree. Please tell me how change writing style from for to recursive first input point //input point const line_point =[0, 0, 0, 2, 151, 2, 2, 151, 2, -62, 283, 63, 2, 151, 2, 62, 297, -58, -62, 283, 63, -104, 334, 74, -62, 283, 63, -58, 338, 45, 62, 297, -58, 67, 403, -55, 62, 297, -58, 105, 365, -86]; take out star point and end point const star

How to manually control animation frame by frame?

試著忘記壹切 提交于 2020-07-22 10:13:25
问题 Regarding this Three.js example https://threejs.org/examples/#webgl_animation_keyframes I was able to load my own model and play animation in a loop. However I want to make a "slider" that will allow user to control animation frame by frame. How I can achieve this with AnimationMixer? Let's say that animation clip has duration 4s. I would like to control in realtime current animation time from 0s to 4s. 回答1: The answer is right there in the code of the example you linked: mixer = new THREE

How to display a locally selected image in three.js?

旧街凉风 提交于 2020-07-09 20:44:06
问题 I always get a cross-origin-error. how can I circumvent this, or better yet, fix it? I need the user to be able to pic a local image and let it be displayed in a PlaneGeometry. my code: this.reader.readAsDataURL(file); this.reader.onloadend = function( ev ) { var file = ev.target.result, //geometry = new THREE.CubeGeometry(1, 1, 0.1), geometry = new THREE.PlaneGeometry(1, 1, 1, 2), texture = THREE.ImageUtils.loadTexture(file), material = new THREE.MeshBasicMaterial({ map: texture }), mesh =

Threejs: Disable frustum culling for some objects

心不动则不痛 提交于 2020-06-29 03:53:14
问题 In order to solve the problem of z-fighting, I limited the near and far of camera to a small range.But when I want to add a larger object,it was culled by view frustum. I tried object3d.frustumCulled property,not working as expected,the reason is as follows: https://github.com/mrdoob/three.js/issues/12170 So,is there a way to ensure that some specific objects are not frustum culled without changing the camera near and far? THX. 回答1: Culling doesn't mean that an object is drawn or not. It can

Best way to get vertices of a mesh three.js

雨燕双飞 提交于 2020-06-29 03:46:52
问题 I am new to Three.js so perhaps I am not going abut this optimally, I have geometry which I create as follows, const geo = new THREE.PlaneBufferGeometry(10,0); I then apply a rotation to it geo.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI * 0.5 ) ); then I create a Mesh from it const open = new THREE.Mesh( geo, materialNormal); I then apply a bunch of operations to the mesh to position it correctly, as follows: open.position.copy(v2(10,20); open.position.z = 0.5*10 open.position.x