WebGL

Loading assets into three.js using File API

天大地大妈咪最大 提交于 2019-12-06 11:12:13
I'd like to create the functionality to import a 3D model to view in the browser by using the File API . The three.js loaders work great on files that I host. My understanding is that the loader uses ajax to retrieve the file. I'd like to be able to load the file from disk on the client to view it. How might this be accomplished? You can override or "hot patch" the loaders' load() function to fit your needs. Put your overrides before any other THREE.js -related code. For example: THREE.OBJLoader.prototype.load = function(url) { // copy the function from OBJLoader.js source and change the AJAX

How do I create resizable objects in THREE.JS

偶尔善良 提交于 2019-12-06 10:48:02
Lets say I have a simple cube and some variables specifying its width, height and depth. How do I update my THREE mesh when the w/h/d changes? (I have everything else like changelisteners etc). Do I update vertices directly? Or is it easier to just redraw everything? I think easiest would be to create your cube with 1 unit dimensions (1x1x1). Then set the dimensions by scaling it: mesh.scale.x = width; mesh.scale.y = height; mesh.scale.z = depth; Not actually sure if mesh supports scale, if not, you can wrap it in Object3D var obj = new THREE.Object3D(); obj.add(mesh); obj.scale.x = width; obj

Multiple objects in webgl

折月煮酒 提交于 2019-12-06 10:42:37
I'm trying to render a few objects to a canvas and I'm having a bit of trouble understanding what's not working. I'm building two objects at the moment that represent the two meshes that I want to render. If I create one mesh the code works fine so the problem, I think, is that the data gets screwed up when I'm building two or more. Here's an example of the mesh data: "name":"cone", "buffers":{ "vertexPosition":{}, // Buffer "vertexIndex":{} // Buffer }, "mesh":{ "vertices":[], // emptied it to fit on page "faces":[] // emptied it to fit on page }, "mvMatrix": Float32Array[16], "itemSize":3,

Render WebGL non-contiguous lines as a single object

回眸只為那壹抹淺笑 提交于 2019-12-06 10:40:39
I have multiple WebGL lines to render, and they all have the same rendering style. So for performance, I want to render them all as a single object, in a single draw call. But the problem is that the lines don't all connect to each other. See example here: http://jsfiddle.net/b6jgS/6/ As you can see the rings connect, but I don't want them to. Yet I still want to draw them in a single draw call. The relevant code is this, which simply generates some geometry for some rings: # Pardon the coffeescript! ringsGeom = new THREE.Geometry() for u in [-2..2] for v in [0..100] ringsGeom.vertices.push

Webgl flickering in Chrome on Windows x64 with nvidia GPU

半城伤御伤魂 提交于 2019-12-06 09:41:16
I see a weird flickering of some rendered geometry Chrome on Windows 10 x64 with nVidia chips. I've also tested in in Chrome for Linux, Firefox for both platforms, Android, and with Intel GPU. It works fine everywhere, except the one platform mentioned. Minimal example looks like this: Vertex shader: precision mediump float; smooth out vec2 pointCoord; const vec2 vertexCoord[] = vec2[]( vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 1.0) ); void main() { gl_Position = vec4(vertexCoord[gl_VertexID], 0.0, 1.0); pointCoord = vertexCoord[gl_VertexID]; }

Three.js - a vertex shader to color based on location of pixel on screen

こ雲淡風輕ζ 提交于 2019-12-06 09:14:13
问题 Using Three.js, I have written a vertex shader that colors each point in a plane according to which quadrant of the screen a pixel is rendered. // vertex shader uniform float width; uniform float height; varying float x; varying float y; void main() { vec4 v = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); x = v.x; y = v.y; gl_Position = v; } // fragment shader varying float x; varying float y; void main() { gl_FragColor = vec4(x, y, 0.0, 1.0); } Live example at jsFiddle: http:/

get transformed vertices positions after vertex shader in THREE.js

回眸只為那壹抹淺笑 提交于 2019-12-06 08:59:51
问题 I am changing the positions of some vertices inside a vertex shader but i can't find a way to get those new updated vertices positions back inside js (i'm currently using THREE.js : the vertex position of my mesh's vertices always remains the same). I found this link Retrieve Vertices Data in THREE.js, but glGetTexImage doesn't exist in webgl (and i'm quite skeptical about this floating-point texture method as well). Thanks for your help ! 回答1: If reading the data from the buffer is the only

Create a plane mesh, with points defining colors

南楼画角 提交于 2019-12-06 08:47:17
I've created ~2500 meshes and use an algorithm defining the color of each mesh. The algorithm goes through all meshes and adds a value depending on the distance it has to each "red-start" point. The value then decides what the color should be. This is the result: It is lagging and the corners aren't smooth. I want to recreate the same color result in some other way but can't figure out how. How can you do it with THREE.Shape and FragmentShader? Final Goal Description: Using one, for increase in FPS, mesh (THREE.Shape) that defines the area which is to be colored. Be able to insert X amount of

Texture shape extrude in three.js

那年仲夏 提交于 2019-12-06 08:46:21
问题 I'm trying to texture an extruded shape in Three.js. In the following code I create a curved shape, extrude the shape, then create a mesh with the geometry and a material I've loaded from a Jpg file. The wireframe displays but the texture does not. The texture is 512*512px in size. Am I using the correct approach? Do I need to manually UV map the texture? I'd like the texture to wrap to the entire extruded face instead of each individual quad. var x = -50, y = 20, z = 150; var rx = 0, ry =

How to create fog using Open GL ES 2.0 or WebGL?

元气小坏坏 提交于 2019-12-06 08:31:31
问题 I would like to create a fog effect for my game but I can't find any tutorials on how to do it using OpenGL ES 2.0. If anyone has links to tutorials, can provide an explanation, or source code I would be grateful. 回答1: There's a section on replicating fixed-function fog using shaders in the OpenGL ES 2.0 Programming Guide on page 224. The source code is available on the google code project (MIT License). It's a gigantic rendermonkey XML file, but the shader source embedded in it is pretty