Dimensions of Collada Element

This is my first time delving into the world of javascript, WebGL, and Three.js. I successfully added a dae 3D model to my scene, but now I need to determine its size in order to generate objects within it. However, upon adding the dae object, it appeared rotated within the scene. After researching and testing, I discovered that simply rotating the object won't work as the bounding box will not rotate along with it. What steps should I take to accurately determine the size of the object?

<!DOCTYPE html>
<html>
<head>
    <title>Collada Size.js</title>
</head>
<body>
<script src="js/three.min.js"></script>
<script src="js/ColladaLoader.js"></script>
<script>

    window.onload = function () {

        var renderer = new THREE.WebGLRenderer();
        renderer.setSize(800, 600);
        document.body.appendChild(renderer.domElement);

        var scene = new THREE.Scene();

        var camera = new THREE.PerspectiveCamera(
                55,             // Field of view
                800 / 600,      // Aspect ratio
                0.1,            // Near plane
                1000           // Far plane
        );
        camera.position.set(-15, 1000, 10);
        camera.lookAt(scene.position);

        var loader = new THREE.ColladaLoader();
        loader.options.convertUpAxis = true;
        loader.load('models/MyFile.dae', function (collada) {
            var dae = collada.scene;
            var skin = collada.skins[0];
            dae.position.set(0, 0, 0);
            //dae.rotation.y = 45;
            render();
            dae.scale.set(120, 150, 120);
            scene.add(dae);

            sizeofDesk(dae);
        });

        function sizeofDesk(dae) {

            var helper = new THREE.BoundingBoxHelper(dae, 0xff0000);
            helper.update();
            // If you want a visible bounding box
            scene.add(helper);
            // If you just want the numbers
            var min = helper.box.min;
            var max = helper.box.max;

            console.log(min);
            console.log(max);
        }

        var dirLight = new THREE.DirectionalLight(0xffffff, 1);
        dirLight.position.set(100, 100, 50);
        scene.add(dirLight);

        renderer.setClearColor(0xffe5e5, 1);

        render();

        function render() {
            requestAnimationFrame(render);
            renderer.render(scene, camera);
        }
    };
</script>

</body>
</html>

Answer №1

Have you considered scaling your object using dae.scale.set(120, 150, 120);? Scaling an object by 150 times may have unintended consequences. The default scale is dae.scale.set(1,1,1), which you might want to stick with.

If you create a new object like this

obj = new THREE.Object3D();scene.add(obj);
and then attach your model to it obj.add(dae);, you'll have more control over how you manipulate the object. This includes pre-scaling the object, rotating it, and translating it as needed.

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 embedding text into a doughnut chart with primeng/chart.js

Currently tackling a primeng chart project involving the development of a doughnut chart within angular. The task at hand is to display text inside the doughnut chart, aligning with the designated design vision. Referencing the image below for visualizatio ...

Tips for expanding button width in 'react-native-swipeout' to enable swipe action on ListView row (React Native)

Currently, I am exploring how to implement the component found here: https://github.com/dancormier/react-native-swipeout My goal is to have the row swiped all the way. Is there a method to increase the button width so that it covers the entire width of th ...

Converting an image to base64 format for storing in localStorage using Javascript

Currently, I am working on code that sets the background-image of a link. This is what I have so far: $("a.link").css("background-image", "url('images/icon.png')"); However, I want to enhance it by storing the image in localStorage: if (!local ...

When utilizing Ionic with Angular, it is difficult to access the hardware back button on mobile devices that have buttons located within the display/screen

When trying to access the hardware back button in my app, I encountered an issue where I couldn't produce an alert message to the user before the app closed. After posting a question on Stack Overflow (link of the question) and receiving help from the ...

What is the best way to update the $scope of a directive from another directive's controller in Angular.js?

One of my directives is responsible for loading a list of events from a service: .directive('appointments', [function () { return { restrict: 'CE', scope: { ngTemplate: '=', ...

Looking to develop a multi-tiered menu component?

I am currently using aurelia along with ES6 to develop a multi-level menu component. The JSON data structure that I'm working with looks like this: data: [ levelId: 1, label: 'Level1', childItems: [ { levelId: 2, labe ...

How can you effectively retrieve values in Chakra Core without encountering any memory complications?

I have been studying this example in an effort to develop a basic JavaScript engine that can execute scripts like the zxcvbn library. I thought I had it all figured out, but there are certain parts of the code that still puzzle me. Particularly, I am strug ...

Issue: The type 'void' cannot be assigned to the type 'ReactNode' in the array.map() function

Having trouble with my function call error within the practice setup in App.tsx. My expectation of array.map() being compatible with TypeScript seems to be incorrect. The generated HTMLElement from this map is not displaying on screen. Any suggestions on ...

AngularJS: Updating data in controller but not reflecting in the HTML view

Within my AngularJS app, I've come across the following code: example.html <div> <p>{{name}}</p> </div> <div> <button ng-click="someFunction()"></button> </div> exa ...

Guide to defining a conditional statement in a Nuxt.js application

I am working on displaying data from the Wordpress API in a Nuxt.js project. I am trying to organize the data by category, for example where ('post.category ', '=', 'categoryName '). Can anyone help me with the syntax in Vue.j ...

Guide to hosting AngularJS Material documentation on a local server

After gathering the latest angularjs material, I noticed that the links in the document lead to absolute URLs at material.angularjs.org/.... I wish to have access to read the documentation and demonstration content locally. ...

Utilize a variable function in AngularJS

Within my app.js file, I have declared functions in the following manner: var func1 = function(v1,v2,v3) { . . } var func2 = function(v1,v2,v3) { . . } Moving on to my controller.js file: var action = ""; if(..) { action = 'func1';} ...

Best Practices for Converting TypeScript to JavaScript

What is the recommended approach to converting this JavaScript code into TypeScript? JAVASCRIPT: function MyClass() { var self = this, var1 = "abc", var2 = "xyz"; // Public self.method1 = function () { return "somethin ...

Strange sequence of results coming from Vue.js

methods: { ShowWindow: function(QueryID) { this.$data.ID = QueryID; if(this.GetData()) { console.log("asdasd") } document.querySelector("#EditWindow").style.visibility = "visi ...

What sets Express.js apart from koa2.js in handling asynchronous functions?

I've encountered a situation where I had to set up the router using Express, and it was functioning correctly with the following code: router.get('/',(req,res)=>{ queries.getAll().then(stickers=>{ res.json(stickers) }) ...

Uploading a file using AngularJs

When it comes to uploading an image or file using HTML tag in AngularJS, it seems that the tag is not supported. The solution? Create a custom directive. In my index.html page, I included the following code: <body ng-controller="myController"> ...

Error in THREE.js: Unable to access property 'lib' from an undefined source (THREE.ShaderUtils.lib["normal"])

I have been working on the challenges provided in the WebGL introductory book by Oreilly. Encountered a runtime error with the following code snippet. After searching online, it seems like I am the only one facing this issue. Could you please assist me in ...

Create a discord.js bot that can randomly select and send a picture from a collection of images stored on my computer

I'm currently working on a bot that sends random pictures from an array of images stored on my computer. However, I encountered an issue when trying to embed the image, resulting in the following error message: C:\Users\47920\Desktop&bs ...

Is there a way to retrieve the request URL within the validate function of the http strategy?

Is it possible to access the context object present in guards within the validate method of my bearer strategy, by passing it as an argument along with the token? bearer-auth.guard.ts: @Injectable() export class BearerAuthGuard extends AuthGuard('be ...

Decoding multiple data with jQuery on the server-side

Scenario: A situation arises where I am utilizing a jQuery.ajax call to send three arrays to the server for database storage. The challenge lies in decoding the combined data object on the server side and breaking it back into the original three arrays. ...