Issue with loading animated Three.js file causing it to not display correct

I created an animation in Blender and exported it as a Three.js file to incorporate it into my Three.js code.

Below is the JavaScript code snippet:

var loader = new THREE.JSONLoader();
loader.load( "obj/dog5.js", function( geometry ) {
    mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() );
    mesh.scale.set( 10, 10, 10 );
    mesh.position.y = 20;
    mesh.position.x = 0;

    var materials = mesh.material.materials;

    for (var k in materials) {
        materials[k].skinning = true;
    }

    animation = new THREE.Animation(mesh, "ArmatureAction", THREE.AnimationHandler.CATMULLROM);
    animation.play();

    lesson6.scene.add(mesh);

The error message I encountered is:

Uncaught TypeError: Cannot read property 'length' of undefined

This issue arises from this particular part of my code:

animation = new THREE.Animation(mesh, "ArmatureAction", THREE.AnimationHandler.CATMULLROM);

Upon checking the Three.js library file three.min.js, I noticed the following:

init:function(a){if(!0===a.initialized)return a;for(var b=0;b<a.hierarchy.length;b++)

Although my JSON file contains a hierarchy, it appears as undefined. This could be due to missing code components.

If I exclude the animation segment, the object renders correctly but remains static.

I am at a loss here. Any advice or guidance would be greatly appreciated! Thank you!

EDIT:

After some modifications, the rendering now works with the updated code below:

          for ( var k in materials ) {

        materials[k].skinning = true;

      }

      skinnedMesh = new THREE.SkinnedMesh(geometry, new THREE.MeshFaceMaterial(materials));
      skinnedMesh.scale.set( 11, 11, 11 );
      lesson6.scene.add( skinnedMesh );
      animation = new THREE.Animation( skinnedMesh, skinnedMesh.geometry.animations[ 0 ], THREE.AnimationHandler.CATMULLROM);
      animation.play();

However, the animation still does not play. Could it be related to needing a start time for animation.play? Or possibly an issue within my JSON file?

Your assistance is much appreciated. Thank you!

Answer №1

I discovered the issue I was having. My problem stemmed from incorrectly animating and rendering.

Fix found at threejs.org/examples/webgl_skinning_simple.html:

function animate() {

  requestAnimationFrame( animate );

  THREE.AnimationHandler.update( clock.getDelta() );

  controls.update();

  render();
  stats.update();

}

function render() {

  renderer.render( scene, camera );

}

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 transferring variable values from Java to JavaScript

As a coding novice, I find myself in a situation where I need to pass variable values from a Java class to JavaScript and update them as the data points of a high chart. https://i.sstatic.net/giH84.jpg The goal is to update these values in the chart show ...

Struggling to get the angular application to function properly within the meteor templates

Having trouble integrating an Angular app into Meteor templates Below is my index.html code snippet: <body> </body> <template name="myIndex"> <section ng-app="myApp" ng-controller="AppController as app"> <div ng-in ...

Determining the Z coordinate on a mesh for the corresponding X and Y values

Seeking the Z value on the mesh by passing the X & Y coordinates, I am new to three js and in need of guidance. Utilizing raycaster for this task, my approach is to position the origin directly above the point and the direction just below it. This setup w ...

The $http Service encounters a failure with an unknown status code

Difficulty Integrating AngularJS, jQuery, and Adobe Panel Creation I recently updated the versions of AngularJS and jQuery for my project. Previously, I was using jquery-1.11.0.min.js and AngularJS 1.2.10. Now, I want to utilize the latest available versi ...

The width of Material UI Grid decreases every time it is re-rendered

I'm attempting to display a list of 25 words in a 5x5 grid using the MUI Grid component. The grid is structured as a <Grid container direction="column"> with five <Grid item> elements. Each <Grid item> contains: <Grid co ...

"Unlock the Power of VueJS 2 with Dynamic Templates

Just starting out as a VueJS student! I created a "MainTemplate.vue", which includes a menu, footer, header... Then I decided to create another .vue file named "ComponentB.vue". Here is the content of my ComponentB.vue file: <template> <h ...

Jasmine attempting to access a nonexistent property

I created a very basic component: import { Component } from '@angular/core'; @Component({ selector: 'loading', templateUrl: './loading.component.html', styleUrls: ['./loading.component.scss'] }) export ...

What is the specific function of jQuery Custom events and how do they operate

I've been on the hunt for reliable sources that delve into the inner workings of custom events in jQuery. Specifically, I want to understand how they replicate event bubbling and more. ...

How can I achieve unique spacing between rows in material-ui grid components?

What is the most effective method for creating spacing between specific rows in a grid using material-ui? Consider the following grid with spacing={0}: GridContainer row1 GridItem GridItem row2 GridItem GridItem row3 GridItem GridItem row4 Gr ...

Tips for changing the page URL upon click in a Vue.js application

I am currently developing a post board application using Vue.js and I am facing an issue with redirecting the page when a user clicks on each post. To handle this, I have made use of vue-route and axios in my project. Here is a snippet from index.js, ex ...

How to store selected checkbox values in an array using AngularJS

Check out this code snippet: <tr ng-repeat="doc in providers"> <td><input type="checkbox" ng-true-value="{{doc.provider.Id}}" ng-false-value="" ng-model="ids"></td> </tr> {{ids}} I am trying to store the values of ...

JavaScript promise will return a value that is undefined

Trying to pass a jQuery ajax request through a promise like this: var foo; foo = bar().then(function(response) { console.log("Success!", response); console.log(foo[0].bool); }, function(error) { console.error("Failed!", error); }); console.lo ...

Executing AJAX POST request with callback function

I successfully used this code for the get function to retrieve data. It works flawlessly and I am able to fetch the required data using this function. function getdata(getdatafrom, resultclass){ $.get(getdatafrom, function(data) { $(result ...

AngularJS does not recognize Model as a date object in the input

I am attempting to utilize AngularJS to showcase a date using an input tag with the type attribute set to date: <input ng-model="campaign.date_start" type="date"> Unfortunately, this approach is resulting in the following error message: Error: err ...

Enhance user experience with AngularJS Bootstrap autocomplete feature by automatically filling input box when hovering over dropdown options

I am currently implementing the AngularJs Bootstrap typeahead functionality. Typically, when we enter text that matches an option, the dropdown list appears. https://i.stack.imgur.com/395Ec.png What I aim for is to automatically fill the textbox with the ...

jQuery's making an error here - looks like matchExpr[type].exec is missing in action

Today, I encountered an error while running my code. Despite searching for guidance online, resources that could help me were hard to come by. Specifically, after crafting a few JavaScript functions, any attempt to use jQuery's methods on selectors r ...

Determine the number of network requests being made on a webpage

In my quest to develop a universal method using selenium, I am seeking a way to ensure that all background network activities, including Ajax, Angular, and API calls, have completed. While I am aware of the option to determine the number of active Ajax cal ...

What is the best way to generate a unique bootstrap card for every piece of submitted data?

I am trying to figure out how I can create a dynamic bootstrap card for each submitted data. When the form is submitted, a new card will be created and the data will be stored in that card. Each piece of data will be displayed in a column format similar to ...

Change object values to capital letters

Upon retrieving myObject with JSON.stringify, I am now looking to convert all the values (excluding keys) to uppercase. In TypeScript, what would be the best way to accomplish this? myObj = { "name":"John", "age":30, "cars": [ { "name":"Ford", ...

Having difficulty accessing data in a JavaScript file within Odoo 9 platform

I have attempted to extract HTML content from JavaScript declared in my module. However, when I try to retrieve content by class name, all I can access is the header contents and not the kanban view. openerp.my_module = function(instance) { var heade ...