Resizing a group of 2D SVG shapes in three.js

I'm currently working on creating a map of 2D SVG tiles using three.js. I've utilized SVGLoader() as shown below:

loader = new SVGLoader();

    loader.load(
        // resource URL
        filePath,

        // called when the resource is loaded
        function ( data ) {
            console.log("SVG file successfully loaded");
    
            const paths = data.paths;
            
    
            for ( let i = 0; i < paths.length; i ++ ) {
    
                const path = paths[ i ];
                
                const material = new THREE.MeshBasicMaterial( {
                    color: path.color,
                    side: THREE.DoubleSide,
                    depthWrite: false
                } );
    
                const shapes = SVGLoader.createShapes( path );
                console.log(`Shapes length = ${shapes.length}`);
                try{
                    for ( let j = 0; j < shapes.length; j ++ ) {
    
                        const shape = shapes[ j ];
                        
                        const geometry = new THREE.ShapeGeometry( shape );
                        const testGeometry = new THREE.PlaneGeometry(2,2);
                        
                        try{
                            const mesh = new THREE.Mesh(geometry, material );
                            group.add( mesh );
                        }catch(e){console.log(e)}
                        
                        
        
                    }
                }catch(e){console.log(e)}

    
            }
        },

        // called when loading is in progress
        function ( xhr ) {
    
            console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
    
        },
        // called when loading has errors
        function ( error ) {
    
            console.log( 'An error happened' );
    
        }
    );
    return group;
}

Please disregard the fact that there are multiple instances of try{}catch(){}

In addition to this, I have implemented grid lines and incorporated them into my axis helper within the application so I can visually understand the positioning of each coordinate in relation to the X and Y axis.

The visualization of the SVG on screen can be seen here: Application Output

I am having trouble aligning the scale of the SVG with the individual grid lines. I suspect that I need to delve deeper into the SVG loading script mentioned above and scale each shape mesh accordingly. The following code references the SVG group itself.

try{
    //SVG returns a group, TGA returns a texture to be added to a material
    var object1 = LOADER.textureLoader("TGA", './Art/tile1.tga', pGeometry);
    var object2 = LOADER.textureLoader("SVG", '/Art/bitmap.svg');
    

    const testMaterial = new THREE.MeshBasicMaterial({
        color: 0xffffff,
        map: object1,
        side: THREE.DoubleSide
    });

    //const useMesh = new THREE.Mesh(pGeometry, testMaterial);

    //testing scaling the tile
    try{
        const worldScale = new THREE.Vector3();
        
        object2.getWorldScale(worldScale);

        console.log(`World ScaleX: ${worldScale.x} World ScaleY: ${worldScale.y} World ScaleZ: ${worldScale.z}`);
        //object2.scale.set(2,2,0);

    }catch(error){console.log(error)}
    


    scene.add(object2);
}

Note that the SVG corresponds to object2 in this context. Some approaches I'm considering to address this issue include exploring what a world scale entails, matrix4 transformations, and the scaling methods of either the object3d parent properties or the bufferGeometry parent properties of this specific SVG group object. While three.js is primarily geared towards 3D graphics, I aim to master 2D graphics programming with this library before delving into the 3D realm. There's also a notion that the scale of the SVG group differs significantly from the scale of the scene and its X, Y, and Z axes.

If this query has already been answered, a link to the relevant response would greatly assist me.

Thank you for taking the time to address this inquiry.

Answer №1

By adjusting the dimensions of the SVG file directly in my editing software, I was able to successfully scale it. While this may not be a conventional coding solution, it seems that the code is heavily dependent on the data within the SVG file and limits how much it can be modified.

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

Tips for removing duplicate objects from an array

I am utilizing the underscore.js plugin in my code I experimented with it on jsfiddle var basket=[{ "basketitems":[{"items":[]}], "itemdetails":[{ "amountPledged": "100", "bActivity": "Handloom Wo ...

implementing data in a single component using vue.js

I am facing an issue with a component where I need to fetch data using an ajax call. The component is being called correctly and the data is returned in the ajax call, but I am struggling to assign it to the data in the template? <template> < ...

Exploring jQuery AJAX Attributes during ajaxStart and ajaxStop event handlers

With my project consisting of over 40 ajax webservice calls, I am looking to incorporate additional debugging features. One such feature is a timing method which I have already developed using my Timer class/object in Javascript. I'm seeking assistan ...

SVG with embedded fonts failing to display properly in web browsers

Within this SVG, there are two different font types being used: SymbolMT for the mathematical expressions and Hind-Light for the text. Both fonts have been defined within the @font-face section of the SVG. The font used for the math expressions appears a ...

How do I send a jQuery table object to a web worker using Javascript?

I have an HTML table with various columns and rows that can be edited by users directly. Whenever a user makes changes to the table, I need to calculate certain sums on the rows of the table. Initially, the function responsible for calculating these sums ...

Alter the HTML tag once the text is encompassed within it

Can you configure your HTML code to display (B) when the text in (A) is wrapped? If it's not wrapped, then just display (A) (A) <div> <span>abcdefgabcdefgabcdefg</span> <span>abcdefgabcdefgabcdefg</span> ...

Tips for expanding the capabilities of the tinyMCE table plugin

Is it possible to customize the TinyMCE table plugin so that the default template includes a column with a width of 200px? Currently, I am using the inlite theme and would like the default table template to look like this: <table> <tr> ...

Use jQuery to smoothly scroll a div

I created a container using a <div> element which is divided into 3 inner divs. The first two inner divs are meant to serve as previous and next buttons, with ids of prev and next respectively. At the bottom, there are 3 more inner divs, each with un ...

Keycloak does not support using the updateToken() function within an asynchronous function

In our development of a Spring application with React/Redux frontend, we faced an issue with Keycloak authentication service. The problem arose when the access token expired and caused unexpected behavior in our restMiddleware setup. Here is a simplified v ...

Ensuring seamless integration between Angular routing and Django

I'm in the process of incorporating a new app into my existing Django project. This new app includes an API utilizing the rest-framework and an Angular application. Within this app, there is a single Django template that serves as a connection point f ...

Updating the content within a div using HTML

I'm facing a challenge. It's not so much about how to do something, but rather how to do it better. What I'm aiming for Additionally, I want to dynamically load content into the page when clicking on navigation links. My query is what wou ...

"Adjusting the Width of Inner Content in a Div

Here is the structure of a div: <div id="showHide"> <div>Alarm</div> <div>Alarmasdf</div> <div>Alarmasdffasdff</div> How can I obtain the width of the largest content, such as "Alarmasdffasdff"? I hav ...

Safari experiencing hang after successful CORS OPTIONS request

Safari (10 - OSX El Capitan) Issue with CORS Encountering a problem with CORS while performing a POST request from an AngularJS front-end to a Laravel back-end. In Chrome and Firefox, both OPTIONS and POST requests return http status 200 OK In Safari 10 ...

What is the proper method for utilizing $http and $q in an Angular service?

I am currently working on implementing reverse geocoding to retrieve the city name from latitude and longitude data. After developing an Angular service that interacts with the Google Maps API using $http, I found myself facing challenges due to the async ...

Utilize Javascript or Jquery to intercept and handle both GET and POST requests

Is there a method to effectively intercept and capture both GET and POST requests as they are sent from the browser to the server? In my web application, full page refreshes occur after each request is submitted, however, some pages experience delays in r ...

Utilizing PHP and AJAX to Extract Information from a MySQL Database

My goal is to fetch data from a MySQL database hosted on a webserver and display it in an HTML table. I've been following an example on W3Schools, but I'm facing issues retrieving the data successfully. Here is the source code: (HTML) <html& ...

Utilizing ng-pattern in Angular to detect leading zeroes in alphanumeric input fields

Are you wondering how to identify a leading zero in an alphanumeric field using ng-pattern in angular? <body ng-app> <h1>Regex test</h1> <form name="myForm"> <input name="myNumberField" ng-model="myNumber" ng-pa ...

Dynamic Interval Update - Using jQuery or Vanilla JavaScript

In my code, I currently have two "stopwatches" (and possibly more in the future). The existing code works well, but I am looking for a way to avoid repeating it multiple times. I believe creating a function would be an ideal solution to reduce redundancy. ...

Confirm that the form is valid prior to displaying the Bootstrap modal popup

My PHP file contains a simple form and a Bootstrap modal. When the submit button is clicked, the Bootstrap modal will be displayed. The form includes: https://i.sstatic.net/10R2r.png I want to validate the fields in the form. If successful, I then need ...

Nested iteration using a for loop in Javascript

I am attempting to iterate through a large array of values and calculate the average of one of the values for each second. I seem to be having trouble getting this code to function correctly, and it appears that the issue lies within the nested while loop. ...