Is there anyone out there who has successfully imported a model from the three.js editor?

As a designer and 3D artist who occasionally delves into coding, I have a question regarding loading a model from the three.js editor into an actual web page. Despite my limited programming knowledge, I've tried various methods to achieve this, including running a server and uploading the model to address browser security concerns.

Here are some of the approaches I've experimented with:

  1. I attempted to export models using Blender but faced issues displaying them in browsers.
  2. Using a collada file exported and imported into the three.js editor, I made adjustments to materials, added environment maps, and exported using different options - geometry, object, and scene.
  3. Even exporting primitives directly from the three.js editor did not yield favorable results.
  4. Experimenting with code snippets found online, I tried replacing existing models with my own, despite not being proficient in programming.
  5. A snippet of the code I used can be seen below.
  6. I explored both THREE.ObjectLoader() and THREE.JSONLoader().

Note: The following code is not authored by me.

    <script>
      var scene, camera, renderer;
      var WIDTH  = window.innerWidth;
      var HEIGHT = window.innerHeight;
      var SPEED = 0.01;

    function init() {
        scene = new THREE.Scene();
        initMesh();
        initCamera();
        initLights();
        initRenderer();
        document.body.appendChild(renderer.domElement);
    }

    function initCamera() {
      camera = new THREE.PerspectiveCamera(70, WIDTH / HEIGHT, 1, 10);
      camera.position.set(0, 3.5, 5);
      camera.lookAt(scene.position);
    }


    function initRenderer() {
      renderer = new THREE.WebGLRenderer({ antialias: true });
      renderer.setSize(WIDTH, HEIGHT);
    }

    function initLights() {
      var light = new THREE.AmbientLight(0xffffff);
      scene.add(light);
    }

      var mesh = null;
    function initMesh() {
      var loader = new THREE.JSONLoader();
      loader.load('models/cubegeo.json', function(geometry, materials) {
        mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
        mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.75;
        mesh.translation = THREE.GeometryUtils.center(geometry);
        scene.add(mesh);
      });
    }

    function rotateMesh() {
      if (!mesh) {
        return;
      }
      mesh.rotation.x -= SPEED * 2;
      mesh.rotation.y -= SPEED;
      mesh.rotation.z -= SPEED * 3;
    }

    function render() {
      requestAnimationFrame(render);
      rotateMesh();
      renderer.render(scene, camera);
    }

    init();
    render();

    </script>

The above text shows two versions of a cube downloaded from the three.js editor - one as GEOMETRY and the other as an Object.

    {
        "metadata": {
            "version": 4.5,
            "type": "BufferGeometry",
            "generator": "BufferGeometry.toJSON"
        },
        "uuid": "8A2042A8-9DE2-42F5-A970-56E64669E516",
        "type": "BoxBufferGeometry",
        "width": 7,
        "height": 7,
        "depth": 7,
        "widthSegments": 1,
        "heightSegments": 1,
        "depthSegments": 1
    }

Utilizing THREE.JSONLoader() with the GEOMETRY cube resulted in an error:

    Uncaught TypeError: Cannot read property 'length' of undefined
        at parseModel (three.js:36833)
        at JSONLoader.parse (three.js:37241)
        at Object.onLoad (three.js:36764)
        at XMLHttpRequest.<anonymous> (three.js:31352)

Applying ObjectLoader() with the Object cube triggered another error:

    THREE.MeshFaceMaterial has been removed. Use an Array instead.
    MeshFaceMaterial @ three.js:44719
    three.js:46378 THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.
    center @ three.js:46378
    three.js:46379 Uncaught TypeError: geometry.center is not a function
        at Object.center (three.js:46379)
        at (index):53
        at ObjectLoader.parse (three.js:37362)
        at Object.onLoad (three.js:37318)
        at XMLHttpRequest.<anonymous> (three.js:31352)

Answer №1

To ensure compatibility, make sure that you are using the same version of both the THREE Editor and THREE.js library. If you encounter issues with the latest versions, consider downgrading to an earlier version of THREE.js such as .70. If the problem persists, it may be due to discrepancies in the save routines of the THREEjs object with the recent builds. In such cases, filing a bug report or identifying a working version is necessary to resolve the issue. Rest assured, I have successfully resolved similar issues in the past.

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 adjusting height responsively with Bootstrap 4

Utilizing bootstrap to create div elements. Check out the fiddle link below: fiddle On my page, I have 4 divs - two on top and two at the bottom. The height of all 4 card divs should remain the same and not change. In the last div, there could be on ...

Is it possible to include multiple spyObjs within a beforeEach block?

In the process of testing an Angular 1 application using Jasmine, I have encountered a dilemma. My question is, can two spies be created for two different services within the same beforeEach statement? Currently, I have managed to make the first spy work ...

Ajax request terminated while sending parameters

Trying to redirect to http://google.com using an ANCHOR tag, while also posting parameters to another page via AJAX is causing the POST request to be aborted even though the redirection is successful. Here is the code snippet: <script type="text/ja ...

Is there a way to utilize a JavaScript function to transfer several chosen values from a select listbox to a different listbox when a button is clicked?

Is it possible to create a functionality where users can select multiple values from a first list and by clicking a button, those selected values are added to a second list? How can this be achieved through JavaScript? function Add() { //function here ...

The code runs perfectly in the fiddle and browser, but encounters issues in Sharepoint 2013

https://jsfiddle.net/rurounisena/zrab1u8q/74/ UPDATED LINK The provided fiddle has the exact functionality I require. The HTML structure mimics a table from SharePoint. However, when I attempt to link this code to an actual SharePoint page, I encounter th ...

Execute an ajax request when the button is clicked

I am facing an issue with a button that is supposed to trigger a function involving an ajax call and other tasks. Despite setting the button's id for a click function, I am unable to generate any response upon clicking. $.ajax({ type: "GET", ...

Using VueJS to switch classes on multiple cards

There is a page with multiple cards, each containing its own set of status radio buttons: ok, missing, error. The goal is to be able to change the status of individual cards without affecting others. A method was created to update the class on the @change ...

Entering numerous numerical values across a variety of input fields

My website currently has a form with 6 input fields where visitors need to enter a 6 digit code. To make it easier for them, I want to allow users to simply paste the code we provide into the first input field and have the remaining digits automatically po ...

Is there a more efficient method to send a large quantity of input element data to an API via a POST request?

My current ASP.NET project is utilizing JQuery and Bootstrap for the front-end development. One section of the project requires users to fill out a form with over 30 input elements, which then needs to be sent to a back-end API. Typically, I would use JQu ...

Capture user input to extract data from a JavaScript object

I need help with implementing a search function where users can enter a name and the person's extension will be displayed on the UI either by clicking a button or pressing "return". Any ideas on how to make this feature work seamlessly? UI <html ...

Verify if the value in a textbox exceeds the number entered in an array of textboxes

My goal is to compare the value of a single text box, labeled as "totalmarkstoall", with multiple arrays of text boxes labeled as "marksscored". The JavaScript code below is set up to compare these values using a key up function. The issue I am facing is ...

A step-by-step guide on incorporating an environment map onto a gltf object

I am struggling to add an environment map to a loaded GLTF/GLB file. Currently, I am getting a reflection instead of the desired effect where there should be a black dot with a light point on it. After reading some of the documentation for Three.js, I bel ...

Transferring a variable value between functions using autocomplete and AJAX communication

I am facing difficulties with implementing autocomplete jQuery along with AJAX call. The issue arises when a user enters text in the input field, triggering an AJAX POST request to the controller which retrieves values from the database and sends them back ...

Strategies for handling axios responses within a useEffect hook in Reactjs

Currently, I am working with Reactjs and implementing nextjs. I am facing an issue where I am using Axios for fetching data from an API, but I am struggling to display it on the page. To debug this, I have tried using console.log inside the useEffect fun ...

How to eliminate file extensions with grunt-contrib-connect and grunt-connect-rewrite

I'm struggling to find a solution for eliminating the '.html' extension from files within my grunt web app. should display index.html from the respective folder. However, in the absence of a trailing slash (), the page should instead look ...

What is the best way to replace material-ui classNames with aphrodite styles?

Using React to style icons has been a fun experience for me. For the styling, I've relied on the incredible Material-UI library which offers a wide range of components. One such component is the FontIcon. However, I ran into an issue where the FontIc ...

Reorganize HTML table rows based on the last row within a rowspan

I would like to organize the data in the table below according to the values in the last row of a rowspan. https://i.sstatic.net/R9OBF.png Looking at the image, I am aiming to sort the table based on the "Cumulative hours" value. Here, I have implemented ...

Leveraging Vue 3 Composition API with accessors

I'm currently in the process of refactoring some of my components using the composition API. One component is giving me trouble, specifically with asynchronous state when trying to retrieve data from one of its getters. Initially, the component was u ...

Is it true that document.execCommand only works with buttons and not links?

Below is the code snippet I am working with: <div contenteditable="true" style="height:100px;width:100px;border:1px solid; " class="editor"></div> <a class='bold' style="height:10px;width:10px;">B</a> $(function(){ ...

Ways to ensure that res.redirect is only executed after the completion of the for() loop

I am encountering an issue with my post route: app.post("/respostaAprovChamado", function(req, res){ if(req.isAuthenticated()){ for(let i = 0; i < req.body.indiceAprov; i++){ Chamado.updateMany( {"_id": re ...