The issue of loading SVG with textureloader in three.js has been reported not to work properly since version

I've had success using svg files with Three.js versions R76 and R77, but now in R78 I can only get it to work with pngs and jpgs

    var floor = new THREE.TextureLoader();
    floor.load('layout.svg', function ( texture ) {
        var geometry = new THREE.PlaneBufferGeometry(4096, 4096);
        var material = new THREE.MeshBasicMaterial( { map: texture } );
        var mesh = new THREE.Mesh(geometry, material);
        mesh.rotation.x = -Math.PI / 2;
        scene.add(mesh);
    } );

Since encountering this issue in R78, I have added progress and error functions to the load arguments...

    function ( xhr ) {
        console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
    },

    function ( xhr ) {
        console.log( 'An error happened' );
    }

...which shows that the svg is 100% loaded in r78, but doesn't display in the scene. I previously used phongmaterial for reflection properties and transparency to create a floating effect with svg elements in a skymap, which was great fun. My question now is, how do I make this work again?

In R77, the svg mapped to a planeBufferGeometry in FF or Chrome.

In R78, it won't load without any errors shown on Firebug.

UPDATE

I looked into SVGLoader.js, SVGRenderer.js (requiring Projector.js). While these render an svg file facing the camera and respond to translations, rotations (i.e. perspective view) are not possible. I tried adding an xml header and doctype to the svg file, but Three.js seems unbothered by their absence. Using localhost made no difference in FF, but was required in Chrome.

It appears that the issue lies either with TextureLoader or WebGLRenderer, both of which have undergone significant changes in R78.

I briefly tested the dev version, and it behaved like R78 does.

Can anyone offer suggestions on where to go from here? I'm unsure whether to report this as a bug or request a "feature restore". Here's the desired effect.

Answer №1

Until R78, svgs were transformed into raster images internally before being displayed.

In version R78 and later, if you want to use svg images with Textureloader, make sure to convert them to pngs beforehand.

If the svg is always facing the camera, consider using the THREE.SVGLoader.

If separate svg elements are needed in a three.js scene, convert them to paths and refer to this example for creating either a 2d shape or a 3d extruded shape.

This experience taught me not to just rely on examples working as-is. I need to dive deep, experiment, and keep myself updated with issues on Github.

Additionally, it’s important to test in multiple browsers; during that time, Chrome was experiencing some bugs related to this issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Add a CSS class to a dropdown menu option in HTML and JavaScript (JQuery) if it has a specified ID

I am brand new to HTML and JQuery, and I'm struggling with setting a class for my select element when the currently selected option has an ID of "answer". This is crucial for checking the correctness of a multiple choice question. If achieving this i ...

Convert JavaScript files into JSON files using Laravel

I have a JavaScript file containing key-value pairs as shown below: es.js export default { currency: "Dinero", void: "Vacio", } Now, I need to convert this file into a JSON format. es.json { "currency" : "Dinero", "void" : "Vacio", } W ...

Is utilizing v-model to update the Vuex store a recommended practice?

Hello there! As a newcomer to Vue, I find myself facing a dilemma that has been weighing on my mind. I'm confused about whether we should utilize the v-model directive to make changes to the Vuex store. While Vuex guidelines suggest modifying the stor ...

Interruption of client-side JavaScript by the ASP timer tick event

Exploring the Situation In the realm of web development, I find myself immersed in creating a web application dedicated to monitoring various services. Each service is equipped with an UpdatePanel, showcasing status updates along with interactive buttons ...

What is the best way to utilize an AngularJS directive to send a POST request with all parameters from a form?

I have created a custom AngularJS form with Stripe integration using a directive. You can view the Fiddle for this project here: https://jsfiddle.net/u5h1uece/. HTML: <body ng-app="angularjs-starter"> <script src="https://js.stripe.com/v3/"> ...

Resource for building user interface components in Javascript

I need assistance with implementing a feature that involves scrolling through different text blocks and corresponding images. Users should be able to select a specific text block and have the associated image on the right scroll into view, similar to a car ...

What is the process of directing a data stream into a function that is stored as a constant?

In the scenario I'm facing, the example provided by Google is functional but it relies on using pipe. My particular situation involves listening to a websocket that transmits packets every 20ms. However, after conducting some research, I have not foun ...

"Utilizing JavaScript to filter JSON data at a deep nested

When working with a JSON data set, I often face the challenge of filtering based on specific child values. Take the following example: [ { "Date": "2017-03-02T00:00:00", "Matches": [ { "Id": 67, ...

Determine the precise boundaries of the React component

I am working with a basic ellipse element: <span style={{ width: /*someWith*/, height: /*someHeight*/, borderRadius: "50%" }}/> and, I am using getBoundingClientRect() to retrieve its bounds (displayed in blue). https://i.ssta ...

Possible problem that may arise when using Express without Jade

I've been experimenting with Express for my latest project, and I came across the suggestion to use the Jade template engine for views like this: /* GET home page. */ router.get('/', function(req, res, next) { res.render('index' ...

"Utilizing an if-else statement within a forEach loop

I have an array of ages and I want to determine the age range for each age along with the count, then push it into my object. The issue I am facing is that if there are multiple ages in the same range, it gets pushed twice. I only want to push it once and ...

Exploring AngularJS: Retrieving data based on a specific ID from a JSON document

Within my controller class, I extract the ID of a specific user from the URL and pass it on to the OrderService. My goal now is to fetch the data associated with this ID from a JSON file. How can I accomplish this task? OrderCtrl 'use strict'; ...

Effortless symmetric AES encryption straight from your browser

I have been tasked with developing a basic encryption add-on for a simple knowledge base/article application. The goal is to implement straightforward symmetric encryption without any complex features or a multitude of options. While searching for JavaScr ...

How can I automatically redirect a React page once I receive a response from Express?

I'm facing an issue with redirecting from one page to another in React. The setup involves an Express server serving the required data to React, and upon receiving the data in React, the goal is to display that result on another page by triggering a r ...

Using JavaScript to create an array from information retrieved from an AJAX

Encountering difficulties in retrieving data from an AJAX file, I am attempting to modify the data source of a web application originally defined in JavaScript as: var ds = [ 'Sarah', 'John', 'Jack', 'Don', 'B ...

Loading an HTML file conditionally in an Angular 5 component

Consider a scenario in my project where I have a testDynamic component. @Component({ templateUrl: "./test-dynamic.html", // This file needs to be overriden styleUrls: ['./test-dynamic.css'] }) export class testDynamic { constructor() ...

I can't seem to figure out what's causing this error to pop up in my coding setup (Tailwind + Next.js). It

I've been struggling with this problem for a week now and despite my efforts, I haven't been able to find a solution yet. However, I have made some progress in narrowing down the issue. The problem arises when I try to execute the yarn build comm ...

Aligning a pair of MDC drawers

I am facing a challenge on my webpage where I have implemented two Material Design Component drawers with identical items. One is set to be permanent for desktop and tablet displays, while the other is designed to be hidden or modal for mobile devices. &l ...

Prevent pinch zoom in webkit (or electron)

Is there a way to prevent pinch zoom in an electron app? I've tried different methods, such as using event.preventDefault() on touchmove/mousemove events in JavaScript, adding meta viewport tags in HTML, adjusting -webkit-text-size-adjust in CSS, and ...

What are the steps to add SVG effects to an image or div element?

Embarking on my first venture into using SVG graphics has left me feeling a bit bewildered. Despite extensive research, I have yet to stumble upon the answer to my current quandary. The objective at hand is to transform an image, assuming that the source ...