AnimationHandler does not animate the Three.js Mesh

I've been struggling to animate the exported mesh from my blender. Even the included buffalo mesh that I see animated in the example is not working for me. I've been attempting to replicate it without success. Here's the code, and I think there might be a simple issue that I'm missing, but I can't figure it out. I don't think it's a problem with blender since I can't animate any of the included meshes.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>three.js webgl - blender</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <style>
        body {
            font-family: Monospace;
            background-color: #000000;
            margin: 0px;
            overflow: hidden;
        }

        #info {
            color: #fff;
            position: absolute;
            top: 10px;
            width: 100%;
            text-align: center;
            z-index: 100;
            display:block;

        }

        a { color: red }

        #stats { position: absolute; top:0; left: 0 }
        #stats #fps { background: transparent !important }
        #stats #fps #fpsText { color: #aaa !important }
        #stats #fps #fpsGraph { display: none }
    </style>
</head>

<body>
    <div id="info">
        <a href="http://crenet-games.com">025 Valgany</a>
    </div>

    <script src="/js/three.min.js"></script>
    <script src="/js/Detector.js"></script>
    <script src="/js/libs/stats.min.js"></script>

    <script>
        if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
        var modelBB={"min":new THREE.Vector3(),"max":new THREE.Vector3() };
        var crewon, animation;
        var container, stats;
        var camera, scene, renderer, objects;
        var particleLight, pointLight;
        var skin;
        var clock = new THREE.Clock();
        init();
        function init() {
            container = document.createElement( 'div' );
            document.body.appendChild( container );
            camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 10000 );
            camera.position.set( 2, 4, 5 );
            scene = new THREE.Scene();
            scene.fog = new THREE.FogExp2( 0x00FF00, 0.035 );
            var loader = new THREE.JSONLoader(true);
            loader.load("buffalo.js", function(geometry, materials) {
                geometry.computeBoundingBox();
                var faceMaterial = new THREE.MeshFaceMaterial( materials );
                faceMaterial.skinning = true;
                THREE.AnimationHandler.add( geometry.animation );
                crewon = new THREE.SkinnedMesh(geometry,faceMaterial, false);
                modelBB=geometry.boundingBox;
                crewon.position.set(0,0,0);
                scene.add(crewon);
                renderer.render(scene, camera);
                animation = new THREE.Animation( crewon, geometry.animation.name );
                animation.play( true, 0.5 );
            });
            // Lights
            scene.add( new THREE.AmbientLight( 0xcccccc ) );
            pointLight = new THREE.PointLight( 0xffffff, 1, 30 );
            pointLight.position.set( 5, 0, 0 );
            scene.add( pointLight );
            // Renderer
            renderer = new THREE.WebGLRenderer();
            renderer.setSize( window.innerWidth, window.innerHeight );
            container.appendChild( renderer.domElement );
            // Stats
            stats = new Stats();
            container.appendChild( stats.domElement );
            // Events
            window.addEventListener( 'resize', onWindowResize, false );
            animate();
        }
        function onWindowResize( event ) {
            renderer.setSize( window.innerWidth, window.innerHeight );
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
        }
        function animate() {
            requestAnimationFrame( animate, renderer.domElement );
            var delta = clock.getDelta();
            THREE.AnimationHandler.update( delta );
            render();
            stats.update();
        }

        function render() {
            if ( crewon ){
                crewon.rotation.y+=0.01;
            }
            if( typeof animation != 'undefined' && animation!=null){
                animation.update(0.1);
            }
            if( typeof modelBB != 'undefined' && modelBB!=null){
                camera.position.x = 0;
                camera.position.y = (modelBB.max.y-modelBB.min.y)/2;
                camera.position.z = (modelBB.max.z-modelBB.min.z)*2;
                camera.lookAt( new THREE.Vector3(
                    0,
                    (modelBB.max.y-modelBB.min.y)/2, 
                    0) );
            }
            renderer.render( scene, camera );
        }
    </script>
</body>
</html>

Answer №1

Issue could potentially be found in this section:

var faceMaterial = new THREE.MeshFaceMaterial( materials );
faceMaterial.skinning = true;

Remember, meshFaceMaterial acts as a container for other materials and is not a standalone material. Make sure to loop through the materials it contains:

var materials = faceMaterial.materials;
for (var i = 0, length = materials.length; i < length; i++) {
    var material = materials[i];
    material.skinning = true;
}

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

Displaying array elements on a webpage using JavaScript in HTML

Looking to display multiple blocks in HTML using a JavaScript array. The array contains names such as: var name=['amit','mayank','jatin'];. I need to repeat a certain portion of code in order to show the elements of the array, ...

Establishing the primary language on a multi-language website

I am currently in the process of developing a website and I intend to offer support for both English and French languages. Up to this point, I've been following the primary solution outlined in this question: How to localize a simple HTML website pag ...

Link up each query with every php echo

Suppose I have the following PHP code: $logger = $_SESSION['logger']; $postquery = $con->query("SELECT * FROM posts ORDER BY id DESC LIMIT 5"); while($row = $postquery->fetch_object()){ $posts[] = $row; } And then, this section of ...

Create an HTML table to view JSON data from a cell on a map

Looking to transform the JSON data into a table by organizing the information based on supplier and product. Below is the JSON input and code snippet: $(document).ready(function () { var json = [{ "Supplier": "Supplier1", "Product": "O ...

Deciphering JSON strings using JavaScript

Here is a string that I am trying to parse using Json: {\"description\": \"PSY - Gangnam Style (\\uac15\\ub0a8\\uc2a4\\ud0c0\\uc77c) \\n\\u25b6 NOW available on iTunes: h ...

Having trouble with npm install, unable to successfully install any node modules after cloning my project from git

I recently pulled my project from a git repository and encountered issues while attempting to run npm install. Despite trying different solutions like running npm install --save core-js@^3 to address the core-js error, I keep receiving the same message pr ...

Utilizing intricate CSS selectors for integration testing with webdriverjs

In my quest to develop integration tests using Selenium with JavaScript bindings, WebdriverJS, Mocha, and Chai, I stumbled across an interesting suggestion in this article. It proposed using WebdriverJS over the official SeleniumJS bindings for some reason ...

TinyMCE is substituting the characters "<" with "&lt;" in the text

I am currently using Django with placeholder tags: I am attempting to insert a flash video into my TinyMCE editor, but it is replacing the '<' symbol with < in the code, preventing it from loading properly and only displaying the code. I ...

Transferring an array between Javascript and Django

I am working with an array of objects in JavaScript, like this: Arr = [0: {k;v}, 1: {k,v}] and so on, each containing numerous fields. The challenge I'm facing is in sending these objects to Django. I have attempted using JSON.stringify to send the ...

Create a pair of divs on your webpage that users can drag around using HTML5

Hello to all HTML5 developers! I am currently facing an issue where I am attempting to designate two separate divs as dragable areas for incoming files. Unfortunately, it seems that only one of them can be active at a time. How can I adjust my code so th ...

Discovering the root cause of why a particular CSS style is not being implemented correctly

Currently, I am in the process of developing a secondary theme for one of my websites. It's going to be a dark theme. I'm facing an issue where a specific CSS style is not being applied to a particular element, even though it works perfectly fine ...

Stop YouTube Video in SlickJS Carousel, Remove Placeholder Image Forever

Feel free to check out the CodePen example: http://codepen.io/frankDraws/pen/RWgBBw Overview: This CodePen features an ad with a video carousel that utilizes SlickJS. There are a total of 3 YouTube videos included in the carousel, with the SlickJS ' ...

Most effective method to retrieve yesterday's data

Currently, I'm working on a requirement and I need to validate the logic that I've implemented. Can someone help me with this? The task at hand is to calculate the 1 month, 3 month, and 6 month return percentages of a stock price from the curren ...

What is the best way to display an HTML page located in a subfolder with its own unique stylesheets and scripts using Express and Node?

I am looking to display an HTML page that is located within a subfolder along with its own unique style-sheets and scripts. I am using Express and Node for this purpose, and have already acquired a separate login page that I would like to render in a sim ...

Utilize Ajax to automatically populate a textbox with suggestions

I'm retrieving data via an AJAX call. How can I bind the data for auto-completion in a text box using both the name and ID as fields? What is the best way to bind this data in the frontend and retrieve the selected name's ID in the backend using ...

What methods can be used to limit the input allowed in a kendo filter text field by the

I have successfully customized the filter on a Kendo grid, but I am facing a small issue. When there is a date column in the grid, I want to restrict users from typing anything in the filter input. The expected behavior is that users should always select t ...

Arranging items in Angular based on selection from the database

i have data in table: Id, word, score , score_list. score are 0.4, 0.2, -0.5, 0, -0.3 .... in score_list i have positive, negative , neutral. How can i sort data with select by score_list? This is html <select class="form-control"> <option> ...

Asynchronously load an AngularJS controller from AJAX without altering the route

I am looking to dynamically load an Angular controller after making an AJAX call that generates a new view in HTML. Here is the setup I currently have: Example of a View: HTML Snippet From AJAX <!-- CVS Pharmacy Extracare - Add View --> <d ...

Assigning multiple values to a key within a JavaScript object

I have a task that needs to be completed as outlined below: $rootscope.$on('function', var1, var2, var3){ var renderObejcts = $('.launch').fullGrid({ events: function(zone1, zone2, callback) { //performing ...

Utilizing the Jquery ready method in conjunction with the load function

While utilizing the ready() method to access the DOM, I encountered an issue where jQuery was returning undefined when trying to access an element. Even after nesting the ready() function inside $(window).on("load", function()), there were still instances ...