Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:07:45+00:00 2026-06-17T19:07:45+00:00

I am trying to write a OBJMesh model reader and I’ve got the OBJMesh

  • 0

I am trying to write a OBJMesh model reader and I’ve got the OBJMesh class setted up, but when I try to retrieve the stored data in the array by creating the OBJMesh object and call the get function, it doesn’t do it.

Here’s the code

OBJMesh.js

function OBJMesh(file)
{
    this.modelVertex = [];
    this.modelColor = [];
    this.init = false;

    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, true);

    var objmesh = this;
    rawFile.onreadystatechange = function ()
    {

        if(rawFile.readyState == 4)
        {
            if(rawFile.status === 200 || rawFile.status === 0)
            {
                var allText = rawFile.responseText;
                var lines = allText.split("\n");


                for(var i = 0; i < lines.length; i ++)
                {
                    var lineData = lines[i];
                    var lineString = lineData.split(" ");

                    if(lineString[0] === "v")
                    {

                        var x = parseFloat(lineString[1]);
                        var y = parseFloat(lineString[2]);
                        var z = parseFloat(lineString[3]);

                        objmesh.modelVertex.push(x);
                        objmesh.modelVertex.push(y);
                        objmesh.modelVertex.push(z);

                        objmesh.modelColor.push(0.0);
                        objmesh.modelColor.push(0.0);
                        objmesh.modelColor.push(0.0);
                        objmesh.modelColor.push(1.0);

                        //document.getElementById("textSection").innerHTML = objmesh.modelVertex[0];
                    }
                }
            }
        }
        objmesh.init = true;
    }

    rawFile.send();
}

OBJMesh.prototype.getModelVertex = function ()
{
    return this.modelVertex;
};

OBJMesh.prototype.getModelColor = function ()
{
    return this.modelColor;
};

OBJMesh.prototype.getInit = function ()
{
    return this.init;
};

main.js

var cubeModel;

function main()
{
    cubeModel = new OBJMesh("file:///Users/DannyChen/Desktop/3DHTMLGame/cube.obj");

    while(cubeModel.getInit() === false)
    {
        //wait for it
    }

    var cubeVertex = cubeModel.getModelVertex();

    document.getElementById("textSection").innerHTML = cubeVertex[0];

}

it just keeps printing out “undefined”. Why’s that? and how can I fix it??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:07:47+00:00Added an answer on June 17, 2026 at 7:07 pm

    but it seems that onreadystatechange is an async-Call so,

    this.init = true;
    

    will be set before the function onreadystatechange is called.

    May be you could set at the end of the onreadystatechange function

    objmesh.init = true;
    

    i hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying write a function that generates simulated data but if the simulated
Trying to write out syslog entries containing strings but they don't register. // person.name
Trying to write to a text file w/ Adobe Acrobat Reader utilizing AcroJS. As
trying to write a functional php script to detect charset retrieve web pages. My
Trying to write a trivial application, But I have stuck into one of the
Trying to write my first app on android. But the app crashes(FC) on the
Trying to write a function that will write my structure array to a binary
Im trying write program in CUDA but I have problem with synchronization in the
We've been trying write unit tests for a worker class written in C#, which
I'm trying write a java program to send live microphone data over UDP, then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.