kandi X-RAY | threejsfundamentals Summary
kandi X-RAY | threejsfundamentals Summary
This is [a series of lessons or tutorials about three.js] This is work in progress. Feel free to contribute, especially localizations.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of threejsfundamentals
threejsfundamentals Key Features
threejsfundamentals Examples and Code Snippets
Community Discussions
Trending Discussions on threejsfundamentals
QUESTION
I want to create an extension that can load gltf once the method is call. I'm using the latest threejs module according to this blog. But got an error.
Here's my code.
...ANSWER
Answered 2021-Oct-04 at 10:00Regarding the glTF, you may check out this blog post and consider using the Autodesk.glTF
ext instead: https://forge.autodesk.com/blog/gltf-20-support-forge-viewer
QUESTION
I am new to using three.js, JavaScript, html, and CSS and I am working on loading a 3d model. I have a program that is working when I pull a gltf file online, ex:
...ANSWER
Answered 2021-Sep-15 at 17:28Web browsers cannot load files like images or models from local disk (unless you disable security restrictions). To get around this you must run a local server during development, see how to run things locally in the three.js documentation.
QUESTION
I try to add light in Three.js but when I update display, light doesn't affect on my cilinder I literally copy pasted the source code from Three.js docs Three.js but it doesnt work,
this is my code
...ANSWER
Answered 2021-Jul-07 at 14:29I found issue in by code, I use MeshBasicMaterial()
, which doesn't react light, I should use MeshPhongMaterial()
QUESTION
I want to replace a plane in ThreeJS to a specific Z value.
I create a shapeBufferGeometry with shape which contains Vector3s containing the x y and z value.
here is my code and what I obtain. I want the white plane to match the position of aqua lines.
The code bellow allow me to render the scene with my plane the different points in it and the vertices around it.
I know that I can use translate to move the plane but I don't know how to properly use it. And how can I know on which axis should a translate my geometry depending on my vector values.
...ANSWER
Answered 2021-Jun-28 at 13:08No need to add the last point to close the contour.
And your step // 5 assign points to .vertices
needs the check for CCW for points
via ShapeUtils
. Assigning an array of Vector3 to .vertices
of a buffer geometry is useless, as that type of geometry doesn't have that property, so you're working with buffer attributes. Calling of shapeGeom.computeFaceNormals();
is also useless.
QUESTION
I am new to threejs and now trying to make this work since ....
I am loading a GLTF with mappings (jpg) into threejs.
I can't find a way to make the loaded model clickable.
Can you please show, how to make this model clickable (single or double click and touch) and call a js-function ?
this is my scene:
...ANSWER
Answered 2021-Jun-23 at 06:51You need to use a pointerevent like pointerup
and then use the Raycaster
like you already tried.
This is the relevant code:
QUESTION
I'm using BufferGeometry to handle meshes with lots of vertices, faces and normals, which I supply via TypedArrays. During rendering, the Scene
and its Mesh
is constructed without any warnings or errors in the console. With BoxHelper I've constructed a Bounding Box around the mesh.
Now the strangest thing happens: Although the Bounding Box is perfectly correct, the faces/vertices are cut off somewhere in the middle.
To see what I mean, here is the comparison of two models rendered with a python script (left) and rendered with Three.js (right):
The code I've used for this task can be found here in this pastebin. Any help is highly appreciated.
...ANSWER
Answered 2021-Jun-15 at 12:48After some digging, I found my mistake. itemSize
of BufferAttribute
for the faces has to be 1.
So I've changed this line
QUESTION
I am selecting vertices from a point cloud using angular and three.js. I have been trying to label a selected vertex with its x,y,z information. I have been using these resources in my attempt:
- three.js Vector3 to 2D screen coordinate with rotated scene
- https://threejsfundamentals.org/threejs/lessons/threejs-align-html-elements-to-3d.html
and I can't get either to work as described.
My code currently is:
...ANSWER
Answered 2021-Jun-11 at 13:38This is as close as I have managed to get it:
QUESTION
I am running an Ubuntu 20.10 machine and testing my site on Firefox. Using npm as package manager and parcel as a bundler. When I try to load a .gltf model in three.js, parcel does not show any errors. When I go to localhost:1234/ my laptop freezes and the canvas is blank.
The directory structure and the file links in index.html
and index.js
are correct, so that's not an issue. I am also using parcel-plugin-static-files-copy
to ensure the static file is available. Also, I generated the .gltf file using Blender and know that it's a valid json.
Code: index.html
...ANSWER
Answered 2021-Feb-08 at 22:55So turns out there was nothing wrong with the first index.js
that I have mentioned in the question. The model was too high poly for my machine, because when I linked a low poly model the page loaded just fine.
Working code: index.html
QUESTION
I have been learning webgl from webglfundamentals where I came across a simple shader example where you can paint triangles with solid color. Here is link to tutorial and original demo.
I tried to create same effect in three js using plane geometry but I can't manage achieve solid color shader. When I use almost same setup in Three js, I get more like gradient effect. What am I doing wrong here? (I am noticing that my shader isn't consistent either as it renders differently on refresh) Also, is there place to learn shaders specifically for three js?
...ANSWER
Answered 2021-Jan-28 at 16:20The PlaneBufferGeometry
in three.js is using indexed vertices to share vertices so there are only 4 vertices and then 6 indices to use those 4 vertices to make 2 triangles. That means you can't give each triangle different solid colors because they share 2 vertices and a vertex can only have 1 color.
Further, the code is choosing random colors for each vertex so even if you you used 6 vertices so that the 2 triangles didn't share any you still wouldn't get the result you linked to, instead you'd get this result which is further down the page on the same tutorial.
Finally the code is only generating 3 floats per color so you need to set the number of components for the color attribute to 3 instead of 4
If you want to repeat the webgl sample you'll need to provide your own 6 vertices.
QUESTION
My case is like this: I have an asset inventory with multiple assets and I want whenever the user hovers on top of them to start the rendering with an OrbitController (I would prefer Trackball but I know that it is not possible due to a bug). The point is that the "this" variable of the class instance can not pass into the render method of the class :
...ANSWER
Answered 2021-Jan-26 at 19:12You are providing this.render
to the event handlers. this.render
is technically a pointer to the prototype function (Main.prototype.render
).
When the handler is fired, the context will be dependent on how the origin executes the handler. In most cases, the context given to the handler will be that of the origin (or possibly even null
). For example, window.addEventListener( 'resize', handler );
will fire resize events by calling the equivalent of handler.call( window, event );
There are a couple ways to get around this.
Arrow Functions implicitthis
Arrow functions use the this
of the context in which they are defined. So if your arrow function is defined in a member function of your class, and that member function is being executed within a context of an instance of that class, then this
within the body of that arrow function will reference the instance.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install threejsfundamentals
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page