The exported JSON file from the editor is malfunctioning

After importing the obj file into the editor and exporting the geometry to a js file, I encountered an error in Firefox debug saying "Type Error: t1 is undefined". Interestingly, when I changed the model to the .js file exported by MaxExporter with both "Export UVs" and "Export Normals" selected, everything worked perfectly. However, switching to a file exported by MaxExporter with only "Export UVs" selected resulted in the same error "Type Error: t1 is undefined". I'm not sure if this is a bug or an issue with my code. How can I resolve this?

Below is the code I'm using:

var ambient = 0xffffff, diffuse = 0xffffff, specular = 0x000000, shininess = 100;

var shader = THREE.ShaderLib["normalmap"];
var uniforms = THREE.UniformsUtils.clone(shader.uniforms);

uniforms["tNormal"].value = THREE.ImageUtils.loadTexture("md/normals.jpg");
uniforms["uNormalScale"].value.set(1.5, 1.5);

uniforms["tDiffuse"].value = THREE.ImageUtils.loadTexture("md/diff.jpg");

uniforms["enableDiffuse"].value = true;

uniforms["uDiffuseColor"].value.setHex(diffuse);
uniforms["uSpecularColor"].value.setHex(specular);
uniforms["uAmbientColor"].value.setHex(ambient);

uniforms["uShininess"].value = shininess;

var parameters = {
    fragmentShader: shader.fragmentShader,
    vertexShader: shader.vertexShader,
    uniforms: uniforms,
    lights: true
};
var material = new THREE.ShaderMaterial(parameters);

loader = new THREE.JSONLoader(true);

loader.load("md/model.js", function (geometry) {
    createScene(geometry, 100, material)
});

container.appendChild(renderer.domElement);

window.addEventListener('resize', onWindowResize, false);

}

function createScene(geometry, scale, material) {

    geometry.computeTangents();
    geometry.computeVertexNormals();
    mesh = new THREE.Mesh(geometry, material);
    mesh.castShadow = true;
    mesh.receiveShadow = true;
    mesh.position.y = -0;
    mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
    scene.add(mesh);

}

Answer №1

Looks like there is an issue in your code.

In order for geometry.computeTangents() to work properly, you must have vertex normals. Make sure to adjust the order accordingly.

geometry.computeVertexNormals(); 
geometry.computeTangents(); 

Following these steps should resolve the problem.

However, it seems that geometry.faces[4].normal is returning zero, indicating an issue with your model's geometry.

Update to the latest version, three.js.r.63, for potential improvements.

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

The AngularJS $HTTP loop counter fails to update

When working with an HTTP service and binding JSON data to HTML, I implemented the following code: This function uses a 2-second timer to automatically fetch data whenever there is a change in the backend. function sampleDevices ...

`How can we efficiently transfer style props to child components?`

Is there a way to pass Props in the Style so that each component has a unique background image? Take a look at this component: countries.astro --- import type { Props } from 'astro'; const { country, description } = Astro.props as Props; --- & ...

Ways to show a child's component element within the parent container

Within my Angular 11 project, there exists a component that exhibits a child component containing assorted table filters: Parent Component <table-filters></table-filters> <table> ... </table> Child Component (table-filters) <f ...

Switch from using JSON to representing data as a String in the Swift

Received a JSON file from an API, but the content appears in this format: [ "https:\/\/seekingalpha.com\/article\/4125943-apple-homepod-delay-big-deal?source=feed_symbol_AAPL" ] If we name the JSON Object above as json, I converted ...

What are the implications of dynamically setting or changing event handlers in web development?

Looking to streamline the process of replacing standard confirm() boxes with Bootstrap modals for saving and deleting on a page. Each operation has its own button (referred to as the action button) which triggers the corresponding modal. Upon clicking the ...

How to display JSON data in an Android ListView

When parsing my URL, I receive the following JsonObject: {"status":0,"items":"1333333454510|-7611868|-7222457" Now I need to extract each number separately as a long. If I attempt to convert it to a string, I encounter an error: org.json.JSONException: V ...

Arrange four Divs next to each other with flexbox styling

I've been struggling with aligning my cards side by side. They are a series of divs nested in lists under a <ul> Changing the positioning is not resolving the issue, and I'm hesitant to alter the display as it's crucial for responsive ...

The "src" attribute is missing from the image on the left side

I'm currently facing an issue with the src attribute in this code: An event updates the src based on a variable retrieved from a form. The image files cannot be renamed, so I must work with their existing names. The problem arises as all file names c ...

Can the browser doc mode be switched frequently?

My web application is built using AngularJS, but we also have a legacy web app that functions only in quirks mode and is included via an iframe on one of our pages. The challenge is to make this legacy app work within our main browser-based application, wh ...

What does the underscore before a function in JavaScript or PHP signify?

I am curious about the significance of the underscore symbol (_) when it is placed before a function or variable. Does it serve to simply describe something, or is it required for executing specific functions or calling certain methods? In JavaScript: va ...

Combine an array with a JSON object in Python

Working with JSON in python3 and looking to add an array to a json object. Here's what I have so far: values = [20.8, 21.2, 22.4] timeStamps = ["2013/25/11 12:23:20", "2013/25/11 12:25:20", "2013/25/11 12:28:20"] myJSON = '{ Gateway: {"serial ...

Change a JSON file of Firefox bookmarks into markdown format

Context I'm looking to display a selection of my bookmarks on my Hugo website, sourced from Firefox in JSON format. I want the output to reflect the nested structure through a nested list, tree view, or accordion format. The content on my website is ...

Show the HTML that is received as JSON when making an AJAX request

Previously, my AJAX call would return an array of data as JSON by using "echo json_encode(array)" in my PHP code. I would then loop through the result in my script to build HTML with the returned data before displaying it. Recently, I updated the code to ...

I'm attempting to retrieve information from my vuex store, however, encountering an error in the process

I've encountered an issue with vuex getters while working on my project. I have a route that showcases all users, and upon visiting this route, the AllUsers.vue component is displayed. Within this component, I'm utilizing the UsersList.vue compo ...

What is the best way to start the server when the files are located in separate directories?

I have organized my project into two separate folders, one for the client and one for the server Is there a way to use npm start to simultaneously run both the frontend and backend scripts? Check out the screenshot below: View of Two Folders in my Projec ...

Using RTK Query to store data in a Firebase Realtime Database

Currently, I am facing an issue while trying to retrieve data from a Firebase Realtime Database using RTK Query. The code in this section is throwing an error because the return value is incorrect. If anyone has experience with this particular issue, I wou ...

The "users" property or method has not been defined in Vue.js applications

During the development of my Vue.js shopping cart, I encountered an issue where I wanted to display the username in a label after the user provided correct information. However, I received the following error in Google Chrome: vue.js:634 [Vue warn]: Prope ...

Vue component encounters undefined error when passing prop array through component

My challenge is passing an array of dates to my component, but I keep encountering this error: [Vue warn]: Property or method "dates" is not defined on the instance but referenced during render I'm puzzled by this issue because I am receiving the ...

What is the best way to implement the addMore event in my custom slot components when working with Vue Formulate?

I need help customizing the 'add more' button for group repeatable fields in Vue Formulate. I have created a custom slot component that is functioning correctly, but I am struggling to determine the click event needed to add another field when th ...

Encountered an issue when deploying a Gatsby JS site on Netlify due to a non-zero exit code returned by the build script

Recently, I discovered Gatsby JS (https://github.com/gatsbyjs/gatsby) and chose to construct my portfolio website using this generator. To begin, I forked their default starter site (gatsby-starter-default) and developed my portfolio from there (https://g ...