Creating a custom JavaScript file by incorporating the morph normals from a three.js example Flamingo.js model

As a beginner in three.js and webgl, I decided to experiment with some example files within the three.js repo. My goal was to incorporate code from one of the examples - "Morph Normal example" featuring a bird flapping its wings into my own project. I copied lines 90 to 107 from the morph normal example which loads the flamingo.js model. Additionally, I added a couple of lines of my own code to insert this model into my scene. I even included the morphColorsToFaceColors() function at the end of the same js file I was editing. However, upon starting the browser, all models were loading except for the flamingo.js model, displaying an error message in the console:

TypeError {} Three.js:632 f.onreadystatechange Three.js:632 DEPRECATED: [flamingo.js] seems to be using old model format

get stack: function () { [native code] } message: "Object [object Object] has no method 'offsetHSL'" set stack: function () { [native code] } arguments: null caller: null length: 1 name: "" prototype: Object proto: function Empty() {} proto: Error

I made modifications and additions to my custom js code as follows:

var mesh = new THREE.Object3D();
    mesh.position.y = 48;

    var loader = new THREE.JSONLoader();
                    loader.load( "flamingo.js", function( geometry ) {

                        morphColorsToFaceColors( geometry );
                        geometry.computeMorphNormals();

                        var material = new THREE.MeshLambertMaterial( { color: 0xffffff, morphTargets: true, morphNormals: true, vertexColors: THREE.FaceColors, shading: THREE.FlatShading } );
                        var meshAnim = new THREE.MorphAnimMesh( geometry, material );

                        meshAnim.duration = 800;

                        meshAnim.scale.set( 1.5, 1.5, 1.5 );
                        meshAnim.position.y = 150;

                        mesh.add(meshAnim);

    } );

At the end of the same js file, I placed the morphcolorsToFacecolors function after calling the animate() function.

function morphColorsToFaceColors( geometry ) {

    if ( geometry.morphColors && geometry.morphColors.length ) {

        var colorMap = geometry.morphColors[ 0 ];

        for ( var i = 0; i < colorMap.colors.length; i ++ ) {

                geometry.faces[ i ].color = colorMap.colors[ i ];
                 geometry.faces[ i ].color.offsetHSL( 0, 0.3, 0 );

        }

    }

}

The Flamingo.js file remains unchanged from the version provided in the three.js example.

Answer №1

It appears that the version of THREE.js you are currently working with has been updated, resulting in changes to the model format. To maintain consistency with the demo, ensure that you are using the specific version mentioned in the original demonstration.

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

Best practices for effectively managing a sizable dataset in Vue.js

My task at hand is to create a visualization dashboard that can operate solely in the browser, utilizing Vue.js, D3, and JavaScript. The dataset I am working with is stored in a .json file that is 48 MB in size. However, upon parsing the file using d3.json ...

Display and conceal the information with a hyperlink

I need to create a content DIV that includes a link to expand and collapse it. Within this content DIV, there is an unordered list. Initially, only two list items should be displayed with an expand link. If users want to see additional list items, they mu ...

What could be causing my browser to crash when I encounter this specific section?

I'm facing an issue with my code where adding a specific part causes the console to stop outputting and the browser to crash. When I remove this part, everything works fine again. I've tried various troubleshooting methods like running shorter lo ...

Exploring the process of transforming a dynamic PDF into a static PDF using PHP or NodeJS

Issue I am looking for a PHP/NodeJS API that can convert editable PDF files to non-editable PDFs online. Our client application requires the user to download PDF files that cannot be modified using software like Foxit Reader or Adobe. We are currently us ...

What are the differences between a Django/React app API when in production versus during development?

Recently, I created a React app that relies on Axios for fetching APIs. During the development phase, I noticed an issue with the API URL configuration. Since my ReactApp was hosted on localhost:3000 but making API calls to 127.0.0.1 - I encountered some e ...

Routes for Express are throwing a 500 internal server error

My server is unable to locate the APIs that I have created in the API directory, which is resulting in a 500 internal server error. I have thoroughly checked routes.js and everything appears to be correct. Additionally, I have an error.js file for handlin ...

What is V8's approach to managing dictionaries?

After attending V8 presentations, it became clear to me that it optimizes constructions such as the one below by tagging a type object: function Point(x, y) { this.x = x; this.y = y; } I am curious about what happens if I were to return an object (JS ...

After successfully executing an AJAX request three times, it encountered a failure

I have implemented a script to send instant messages to my database asynchronously. Here is the code: function sendMessage(content, thread_id, ghost_id) { var url = "ajax_submit_message.php"; var data = { content: content, thread_id: thread_id }; ...

What is the method for launching a standalone terminal window from a vscode extension?

I am in the process of creating a custom extension for Visual Studio Code. My goal is to open a separate terminal window and execute multiple commands consecutively, similar to Terminal.sendText but not within the integrated terminal. Is there a method to ...

Having trouble formatting an AJAX POST request properly

Despite my best efforts, I continue to encounter the dreaded 500 (Internal Server Errors) every time I try to execute a POST request to https://rates.tradelanes.us/bankaccount/record/create. I suspect it has something to do with the format of my data. Howe ...

Display or conceal pictures depending on an array list

One of my current challenges involves managing a list of tags and a separate list of selected tags: data () { return { tags: ['#tag1', '#tag2', '#tag3'], selectTags: ['#tag1', '#tag2', ...

Is it possible for me to send transactions asynchronously using polkadot-js?

After thoroughly going through the official documentation, I stumbled upon a page discussing how to transfer using polkadot-js const transfer = api.tx.balances.transfer(BOB, 12345); const hash = await transfer.signAndSend(alice); I am curious if it' ...

Angular2 - Error: The view has been destroyed and cannot be updated: detectChanges

My application keeps encountering this persistent error: extensions::uncaught_exception_handler:8 Error in event handler for runtime.onMessage: Attempt to use a destroyed view: detectChanges at ViewDestroyedException.BaseException [as constructor] (chrome ...

Error message displayed in console while attempting to assign material to mesh

I am experimenting with applying MeshStandardMaterial to a mesh of a GLTF imported model. For testing purposes, I used a simple cube exported from Blender as the GLTF model. Upon successfully loading the GLTF model, I proceeded to do the following: this.m ...

Can you explain the significance of the <%= %> HTML tag?

I've recently been tackling a project with Webpack. For those not familiar, Webpack is a bundler that combines all your files into one final product. One task I encountered was trying to insert one HTML file into another, similar to an import or requ ...

Tips for retrieving the value when a button is clicked in AngularJS

Looking for assistance on retrieving the selected value in AngularJS when a button is clicked. Below is the code I am currently using: <div class="form-inline"> <div class="form-group"> <select class="form-control" data-n ...

Angular Checkbox Single Select

I have a piece of HTML code with ng-repeat that includes checkboxes. <table> <tr ng-repeat="address in contactInfo.Addresses"> <td>{{address.DisplayType}}</td> <td>{{address.AddressLine1}}</td> <td>{ ...

Learning the process of dynamically binding an id to an HTML tag in Vue.JS

I am currently utilizing Bootstrap Vue for UI and attempting to implement a collapsing feature using this provided link For instance, using v-b-toggle.collapse-2 where the 2 represents a static id. However, I am interested in dynamically assigning this id ...

Having trouble with the filtering feature in Material UI Datagrid

I'm currently using Material UI Data Grid to display a table on my website. The grid has an additional filter for each column, but when I click on the filter, it hides behind my Bootstrap Modal. Is there a way to bring it to the front? https://i.stac ...

Communicate with the parent component in React to either access data or pass data from parent to child component

Can you explain a method for passing data between components without using props? render() { return ( <Parent> <Child1> <Child2> </Parent> ); } In the context of components Parent and Child, how can the data genera ...