Modifying colors and applying transparency to objects in Three.js (loading from .obj + .mtl files)

Currently, I am working with Three.js to load .obj + .mtl files in order to view a 3D model within a web browser. I am at the beginning stages and would greatly appreciate some assistance.

Two things that are currently puzzling me:

The model I am working on (requires mouse dragging)

  1. Initially, the object appears transparent in the scene and requires dragging to make it visible

  2. How can I change the black color of the object? (There is an image below showing it in black)

My aim is to make it resemble this example on Sketchfab

The majority of the code is taken from the castle example on script-tutorialsׂ(mentioned at the top of the page)

Any information or guidance would be greatly appreciated.

Answer â„–1

UPDATE: I've noticed that you've made some adjustments, but don't forget about the MTL tip.

Have you experimented with modifying the ambient and directional light components or adding them? It seems like you need to customize how light affects your model.

ambient = new THREE.AmbientLight(0xFFFFFA); //darkest black
    scene.add( ambient );

    var directionalLight = new THREE.DirectionalLight( 0xffeedd ); //for shader visibility
     directionalLight.position.set( 0, 0, 1 ).normalize(); //front of scene
     scene.add( directionalLight );

You can also manually adjust the Ks and Ke components in your material's MTL file. Sometimes they default to:

Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000

They may need different values like 1 instead of 0 for proper light reflection.

You might want to center your obj in the scene by setting its initial position when loading the model like this:

var loader = new THREE.OBJMTLLoader();
                    loader.load( 'models/'mymodel.obj', 'textures/mymodel.mtl', function ( object ){

//change the initial position of your model after loading
                    object.position.set(0,0,0); //in one step
                    object.position.y = -80; //or individually
                    scene.add(object);

});

Alternatively, adjust camera parameters like this:

camera.position.z = 550 ; //for instance

I hope this information is helpful for your project.

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

The error message "Unexpected token" occurs when using async function prefix in TypeScript

Encountering an 'Unexpected token' issue in typescript while attempting to create an async function: async function test() { ... } Investigated the possibility of this error being caused by running an outdated version of node that doesn' ...

MUI: The fontFamily property is not able to be overridden by nesting within the

My goal is to have different fonts for different parts of my application using theme nesting. Unfortunately, I discovered that theme nesting doesn't work when it comes to overriding fonts. In my App.js file: import React from "react"; impor ...

Is it better to master JavaScript before diving into JQuery?

When diving into the world of JavaScript in 2012, is it more beneficial to start by learning JavaScript first and then move on to jQuery, or should one jump right into jQuery without prior knowledge of JavaScript? ...

"After completing the survey form, the User Details form is displayed upon clicking the submit button

In my Quiz, each question loads on a separate page with clickable options. Some questions may have multiple answers, including an "Others" option. At the end of the quiz, users need to fill out a form. Although I've created a survey form, I'm fa ...

"Experience the latest version of DreamFactory - 2.0.4

I'm encountering a 404 error when I send a request to my new DSP. GET http://example.com/api/v2/sericename/_table/tablename 404 (Not Found) Upon checking the Apache error.log, I found this message: ... Got error: PHP message: REST Exception #404 &g ...

Could anyone assist me in resolving the error stating, "The 'Argument `where` of type UserWhereUniqueInput needs at least one of `id` arguments"?

Upon investigating, I inserted this console log to determine what data is being received: { username: 'aa', gender: 'Feminino', cargo: '2', email: 'a', password: 'a' } Lately, I've been facing this err ...

When using AJAX with CodeIgniter, session data is not being saved properly

I am facing an issue that I need assistance with. In my controller, I have a method that creates a CodeIgniter session. To ensure that it is created correctly, I use a print_r() function after creating the session. Subsequently, in my Ajax request, I inclu ...

Limiting the length of numbers in Material UI

Is there a way to restrict user input to only numbers with a maximum length of 3 in Material UI? <TextField id="score" label="score" className={classes.textField} name="totalScore" margin="normal" defaultValue={score} /> We specifically ...

Content that is set to a fixed position within a hidden element will remain at the top

translate3d(0%, 0px, 0px); is causing issues with my position fixed element. In my demo, you'll notice that clicking the button should open up the content just fine, but it is supposed to stay fixed at the top in a position fixed. Therefore, when scr ...

Opacity of a three.js box geometry

Hello friends, I am working with three.js basic material to create two boxes. Currently, I am facing an issue where the smaller box is visible inside the larger box, which is not the desired outcome. Can anyone assist me with this problem? var cube1 = ...

Is there a way to ensure that functions operate effectively within a modal window?

While working on a script for my job, I decided to move most of my HTML content into a modal halfway through writing the code. The challenge now is that many functions I've already created no longer work with the content inside the modal. I'm hop ...

Tips on creating a personalized memoizeOne function that delivers the accurate data type

I've implemented a function for object memoization: import memoizeOne from 'memoize-one'; type ArrayWithOneObj = [Record<string, unknown>]; const compareObject = ([obj1]: ArrayWithOneObj, [obj2]: ArrayWithOneObj) => obj1 === obj ...

A step-by-step guide on accessing and displaying local Storage JSON data in the index.html file of an Angular project, showcasing it on the

I am facing an issue with reading JSON data from localStorage in my Angular index.html file and displaying it when viewing the page source. Below is the code I have attempted: Please note that when checking the View page source, only plain HTML is being ...

The issue with the callback function not being triggered within a self-repeating loop

As I work on creating a user-script to incorporate a trailer video into a website, I encountered an issue with the callback function in my script. The goal is to filter the real source of the video from different URL formats, but for some reason, the callb ...

When attempting to click the "New" button in a lightning datatable to add a new row, an error

Having trouble adding a new row when clicking the New Button in a Lightning Data table. I've created a lightning-button in HTML and called the method in JavaScript. However, when I click the New button, I'm getting an error message saying Undefin ...

Encountering a next-i18next 404 error while attempting to access pages with localeSubpaths configuration enabled

I have encountered a 404 error while trying to access any page of my Next.js application. The application functions properly when the localeSubpaths configuration is not provided. However, upon implementing the localeSubpaths config in next.config.js: co ...

Encountering issues with Node.js and Socket.io not displaying results on Internet Explorer when using a secure connection

I have successfully integrated socket.io, node.js, and express to serve real-time json data to multiple browsers except for IE (tested on version 9) over a secure connection. Everything was functioning smoothly until I switched to HTTPS. From the server&ap ...

Is there a way for me to identify the value within useCallback without any intermediaries?

How can I ensure that console.log('success') is triggered when the ids of myFood[myFood.length - 1]?.id and viewableItems[viewableItems.length - 1]?.item?.id match? Despite both values being equal, there seems to be an issue preventing console.l ...

Add C# iteration with JavaScript on ASP.NET directories

I need help extracting all filenames from a specific folder on the server, and then adding them to a JavaScript array. The functionality should mimic ASP.NET C#'s Directory.GetFiles method. I have already initialized an array and now just require as ...

Creating a dynamic user interface in Angular 6 that successfully tracks changes without reliance on the parent

As I delve into the world of Angular, I am faced with a challenge in creating a reusable component that will be bundled into an npm module. The issue lies in the UI change detection aspect. In order for the component to function properly, the application ...