Three.js set texture to inline svg - three.js

I am not sue of this is even possible but instead of setting a texture to a jpg like THREE.TextureLoader().load('./texture1.jpg')
I want to set the texture to an INLINE SVG (I want to animate with javascript GSAP).
Is this possible? Probably not :(

Sorry, it's not. You can't use a SVG file as a texture. However, you can load SVG files in three.js via THREE.SVGLoader and then create shape meshes from the resulting path data.
But keep in mind this is a one-time operation. If you animate the SVG, you won't see any effect after the loading process.

Related

How to load gltf with svg texture

I am trying to load svg and use it as a texture for some parts of my 3d scene in react-three-fiber. The issue I am trying to fix is that somet of the textures are quite blurry even though I have big raster images.
I can load an svg using react-three-drei's component, and it looks super crisp.
Is there a way I can load svg as a texture for a mesh? Or should I go about it as I somehow link the component to the mesh and mimic its size and movement during animations?
Not sure how I can do this.
I've tried adding the svg files directly in my gltf file as texture with mimetype image/svg+xml but react three-fiber gives an error about enconding.
Also I've tried using useTexture() with the svg source which does work, however blurry as the raster textures.
I want to know if it is possible for me to achieve this somehow. Or if there is an alternative to making my scene render crisper.
Hi sadly textures are raster images only…
There is technique called SDF 2d but this would also involve converting svg to image…
You can check it here https://github.com/dy/svg-path-sdf
The way it works, it coverts svg to raster under the hood, for you, maybe there is some options for it, however I would recommend process your svg to png or jpg manually…

Possible workaround for having color and texture with Three.js CanvasRenderer?

I am using CanvasRenderer to render numerous Sprite objects. I am mapping a texture (PNG image) to the Sprites. I'd like to be able to change the color of the texture programmatically.
With the WebGLRenderer, I can use ParticleSystem and ParticleSystemMaterial to achieve this. Here's a live demo of setting color to this texture (http://wxalert.info/private/dv/ball.png) with that technique: http://wxalert.info/private/dv/demo.html
But since CanvasRenderer does not support ParticleSystem, I am using Sprites instead with a SpriteBasicMaterial. Here's a live demo of this: http://wxalert.info/private/dv/demo2.html
I'd like to be able to set the color with CanvasRenderer just like with WebGLRenderer, but I'm not sure if this is possible.
One thought was perhaps to load the image to an HTML5 canvas element, apply the color there, and then load the canvas context from the material. But any other suggestions would be greatly appreciated.
UPDATE: Here's an example of kind of what I was thinking of doing if using the HTML5 canvas: http://wxalert.info/private/dv/html5canvas.html. Basically, I would do the color manipulation there and then just load the canvas from the material. But wasn't sure if there was a simpler or better way.

How to create scaleable svg animations?

Consider creating an SVG animation: a rectangle move into the scene from left side of the svg image and move out from right side and this is a loop.
(And i don't what to use canvas libraries or any javascript code).
[1] Is it possible to create this simple animation with any application (just like flash but with svg export) (I know Adobe Illustrator let us export vectors but not sure about animating theme).
[2] Also as SVG is vector based i intend to make this svg animating fluid (setting the width of svg to 100% an content scale automatically) is it also possible?
(I know how to do such these things using canvas libraries like snap.svg kinetic ... with bunch of js code i'm looking for some GUI App which let a graphic designer having no idea what JS is do it like Adobe Flash for example).
Any solution?
I am not sure about GUI App but fluid animations are possible. Look at the following elements: animate, animateMotion, animateTransform, animateColor.
Here are some examples and documentation:
MDN: animate, animateMotion
W3C

How to generate the top and perspective view of an object using ThreeJS?

I want to generate the top and perspective view of an object.
Input: A 3d object, maybe .obj or .dae file.
Output: the image files presenting the top and front view of the loaded object.
Here is some expected output:
The perspective view of a chair
The top view of a chair:
Can anyone give me some suggestions to solve this problem? Demo may be preferred
You could create a small three.js scene with your obj or collada-file loaded using the appropriate loaders. (see examples of the specific loaders). Then create the necessary cameras you want to have in the scene. See examples for orthographic and perspective cameras that come with three.js, too.
To produce the images you want, you could use the toDataURL function, see this thread here and use google
Three.js and HTML5 Canvas toDataURL
in essence, after the objects are loaded, you could do something like:
renderer.render(scene, topViewCamera);
dataurl = canvas.toDataURL();
renderer.render(scene, perspectiveCamera);
dataurl2 = canvas.toDataURL();
I think you could also use 2 renderTargets and then use those for output, too, but maybe if you are new to three.js, start with the toDataURL() method from HTML5.

How do I attach a text to the vertices of a cube in three.js? Also, Can I add a Text at any point inside the Cube?

I am trying to create a cube using three.js for a project. I need to add text to vertices and at different points inside the cube. Any idea how this can be done?
For some basic code examples of using Sprite objects in Three.js, check out:
http://stemkoski.github.com/Three.js/Sprites.html
And for an easy way to create images that contain text to use as your sprite textures, check out the sample code at:
http://stemkoski.github.com/Three.js/Texture-From-Canvas.html
I think a combination of these two ideas will achieve what you are looking to do.
If you want to have label-style texts, so that the text begins at a specific point, but is always oriented with the camera and easily readable no matter the camera position, you can use sprites. (example of canvas-created text label sprites: http://i.imgur.com/e9I68xD.jpg - here they are rendered on a separate pass to that they are never obscured by the scene but you can do it on the same pass)
If that's what you are looking for, I'd suggest first checking the Sprites examples, and learn to attach some static image as a sprite to correct position in the scene. After you get that working, you modify the code so that you generate the text to an image canvas using standard Javascript Canvas functions, and using that image as the sprite.

Resources