Cannot load OBJ in ASP project - 404 or 500 error - FIXED/Resolved

Hi all, first post - sorry if its in the wrong section etc.

I can not load an OBJ file in my site developing on ASPcore.

With ObjLoader and Tree.obj from examples
image

With ObjLoader2 and same model
image

Sometimes I will get a 500 error and the model will load 100% but it says an error occurred beforehand.
I have added the MIME type in a new web.config file which I added. In the image it shows “text/plain” which i also tried the other of “application/octet-stream”.
image

I am getting three js from dependencies through gulp - “three”: ^0.94.0

  • I can only add 3 images because I am a new user so I will try and add more in comments *

Any help on this would be greatly appreciated. And sorry if I have put too much info, or not enough.
Thanks - David

more images as stated above - sorry.

Sometimes it will give a GET 404 error which i can dig through, and it ends up here.
image
image
The above is in the Object.assign function.

So the question is about hosting and not about OBJLoader, right? I mean does it work if you use e.g. node.js and http-server?

Reference: https://threejs.org/docs/#manual/introduction/How-to-run-things-locally

I just want to make sure that OBJLoader can actually load your tree1.obj. BTW: Can you share the file in this thread?

HI @Mugen87 thanks for the reply.

I am working in Visual Studio 2017, and not done it through Node.JS. I was using Eclipse with XAMPP, with PhP based project and everything worked fine with loading the OBJ file.
What file would you like - I assume the one with the loader in, but if not then I can add more.
scene.js (7.3 KB)

I have just tried the JSON loader which works with a basic box which is looking promising, but I dont want to convert all obj files to json (but if needs be then so be it). the file includes the json addition.

With relation to your question “So the question is about hosting…” I am not too sure if that is the problem, i.e. do i need to host it on a hosting server, not go through Visual Studio 2017. Thanks for the link as well. I will go through that and if something works I will update the post.

The “Tree1.obj” is a copy of the “Tree.obj” which is in the Three-examples, I did what a forum post suggested and created a new file, and copy and pasted the contents from “Tree.obj” to “Tree1.obj”.

Thanks again for helping.

The “Tree1.obj” is a copy of the “Tree.obj” which is in the Three-examples,

Ah, okay. So it’s not a problem of loading and parsing tree.obj via OBJLoader since the model is used in examples like the following:

https://threejs.org/examples/webgl_postprocessing_godrays.html

I’m not sure how visual studio serves files for a web project. If you run a local server like mentioned in the guide it should definitely work.

BTW: It’s not necessary to convert your models to JSON format. Using OBJLoader is okay. The recommended format of the project is glTF though. Read more about this topic right here:

https://threejs.org/docs/#manual/introduction/Loading-3D-models

cool - thanks very much for the links and looking into it. I have tried using IIS but it seems to be hating it even more, but I will try the Node way. thanks again!

EDIT - i have tried running the same code in NODE.JS to no success.
I have also tried loading the glTF duck from threejs and that fails just like the ObjLoader.
I have tried publishing to IIS and again, it does not serve up the OBJ or glTF or FBX files, but does do JSON models.
I am not sure if its a serving issue, but an issue in the parser of Three js - see above for the error in the code.

Any advice would be great. Thanks

I don’t think it’s a parsing issue. Maybe there is a problem on your computer. The node.js approach should definitely work. If possible, please provide a live example for debugging.

Firstly - thanks very much for getting back in touch.
Yeah I doubt its a parsing issue
this is the current state of what is rendering, but there should be other loaded models.
image
Red cube was just a quick test from 3DS max for json file type.

I can not upload my project because it is over the upload limit, do you have an email address I can send it through.
Or i can try and separate everything and put them in a reply comment, but will need you to reassemble on your end - unless there is a better way?

Thanks Mugen

With “live example” I’ve meant something different :wink:. Please provide an URL to your application. It’s not necessary to host the whole app. Just an isolated test case that shows the loading problem.

ohhhhhh sorry dude “school boy error” :smile: I have been running it on local IIS - I will try and put it on some hosting I have for old php site. or figure out how to give you access. Sorry, I am a noob when it comes to web development stuff. Please bare with me.
Edit:
@Mugen87 - just to let you know, I have put the code on a hosting, but just sorting out some web.config files - hopefully it should all be working today. sorry for the wait.

1 Like

@Mugen87
Hey pal - sorry about not being in touch soon - i have been back and forth with my hosting coming (tso-host) for a week now with them telling me it was my fault the site is programmed wrong. Long story short, they dont host ASP.net core apps, so I signed up to AWS.
the following link is the site

http://scenegraphstudios.eu-west-2.elasticbeanstalk.com/

any advice on what could be wrong would be amazing - again, sorry for the wait.

Dave

@Mugen87 - hey dude, I fixed the issue, for anyone else see below for a fix.
//////
Asp.net core - Razor pages.
So everything pointed to the Mime types not being set, but I did add a web.config file with the appropriate code -





forums state to remove then add them again because if you add duplicates, then IIS will freak out (which it does).
With Asp.net core, web.config just does not want to load so you need to add mime types by code.
See code below. Hope this helps anyone else dealing with these issues. @Mugen87 thanks again for the help.
Startup.cs
using Microsoft.AspNetCore.StaticFiles - you may have to include this through nuget.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{

        var options = new StaticFileOptions {
            ContentTypeProvider = new FileExtensionContentTypeProvider()
        };
        ((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add(
            new KeyValuePair<string, string>(".obj", "text/plain"));
       


        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles(options);
        app.UseCookiePolicy();

        app.UseMvc();
    }
1 Like