Item mysteriously disappearing during scene rendering

I could really use some assistance. I'm currently working on a WebGL project using Three.js for my school assignment, but I've hit a roadblock.

My goal is to display an object from Blender at the center (0,0,0) of the scene and then rotate it using keyboard arrows.

Below is my init() function:

var scene, camera, renderer;
init();

function init() {

  scene = new THREE.Scene();
  var WIDTH = 880,
      HEIGHT = 550;

  renderer = new THREE.WebGLRenderer({antialias:true});
  renderer.setSize(WIDTH, HEIGHT);
  document.getElementsByClassName("pw")[0].appendChild(renderer.domElement);

  camera = new THREE.PerspectiveCamera(90, WIDTH / HEIGHT, 0.1, 1000000);
  camera.position.set(5,15,10);

  scene.add(camera);

  window.addEventListener('resize', function() {
    var WIDTH = 880,
        HEIGHT = 550;
    renderer.setSize(WIDTH, HEIGHT);
    camera.aspect = WIDTH / HEIGHT;
    camera.updateProjectionMatrix();
  });

  // More code for sky dome and lights...

  var loader = new THREE.ColladaLoader();
  var dae

  loader.options.convertUpAxis = true;

  loader.load( 'models/ring.dae', function ( collada ) {
    dae = collada.scene;
    var skin = collada.skins[0];
  
    dae.position.set(0,0,0);
    dae.scale.set(7,7,7);
  
    scene.add(dae);
  
  });

  // Uncommenting these controls make the object ring.dae disappear... any thoughts on why?</p>
}

Any insights on why the object disappears when attempting to implement controls would be greatly appreciated! Thank you.

Answer №1

updated init()

scene = new THREE.Scene();
  var WIDTH = 880,
      HEIGHT = 550;


  renderer = new THREE.WebGLRenderer({antialias:true});
  renderer.setSize(WIDTH, HEIGHT);
  document.getElementsByClassName("pw")[0].appendChild(renderer.domElement);

  camera = new THREE.PerspectiveCamera(25, WIDTH / HEIGHT, 0.1, 1000000);
  camera.position.set(0,2,7);

  scene.add(camera);

  window.addEventListener('resize', function() {
    var WIDTH = 880,
        HEIGHT = 550;
    renderer.setSize(WIDTH, HEIGHT);
    camera.aspect = WIDTH / HEIGHT;
    camera.updateProjectionMatrix();
  });



  //sky dome


    var vertexShader = document.getElementById( 'vertexShader' ).textContent;
    var fragmentShader = document.getElementById( 'fragmentShader' ).textContent;
    var uniforms = {
    topColor:      { type: "c", value: new THREE.Color(0x000053) },
    bottomColor: { type: "c", value: new THREE.Color( 0x2626ff ) },
    offset:         { type: "f", value: 100 },
    exponent:     { type: "f", value: 0.7 }
    }

    //skydome

    var skyGeo = new THREE.SphereGeometry( 2000, 32, 15 );
    var skyMat = new THREE.ShaderMaterial( { vertexShader: vertexShader, fragmentShader: fragmentShader, uniforms: uniforms, side: THREE.BackSide } );

    var sky = new THREE.Mesh( skyGeo, skyMat );
    scene.add( sky );


  //lights


    var light4 = new THREE.HemisphereLight(0xfffff3, 0xd7f0ff, 0.2); // soft white light
    scene.add( light4 );


    var light2 = new THREE.PointLight(0xd7f0ff, 1);
    light2.position.set(1,1,1);
    scene.add(light2);





    var loader = new THREE.ColladaLoader();


      loader.options.convertUpAxis = true;

      loader.load( 'models/ring.dae', function ( collada ) {

        ring = collada.scene;

        var skin = collada.skins[ 0 ];

    ring.position.set(0,0,0);//x,z,y- if you think in blender dimensions ;)
    ring.scale.set(7,7,7);

    scene.add(ring);
    renderer.render(scene, camera);

    });

    //controls = new THREE.OrbitControls(camera, renderer.domElement);
    document.addEventListener( 'keydown', onDocumentKeyDown, false );
    //document.addEventListener( 'keyup', onDocumentKeyUp, false );
     render();  

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

What is the best way to identify errors in an express listen callback function?

My current code is set up to verify if there was an error while initiating Express: express() .listen(port, (err: Error) => { if (err) { console.error(err); return; } console.log(`Express started`); ...

How can I stop the body from scrolling to 100% height when the virtual keyboard is displayed?

My chat app has sticky header and footer elements. To handle the mobile virtual keyboard opening, I adjust the document's height using window.visualViewport.height. For example, if the browser's height is 1000px and the virtual keyboard takes up ...

Styling Dropdown Options Based on Conditions in React

In my current project, I am attempting to modify the className of selected items within a mapped array using another array (this.props.notPressAble). The reason for this is because I want certain objects in the array to have a different CSS style. handleOp ...

Adjust the texture rotation on a PlaneGeometry by 45 degrees using UV coordinates

Trying to apply a rotated texture onto a PlaneGeometry has been a bit of a challenge for me. I have a 44x44 diamond-shaped texture that you can view here: https://i.sstatic.net/Babx0.png My goal is to map this diamond texture onto the plane geometry usi ...

Access information stored within nested JSON objects on a local server

After creating a test page, this is the structure that I have set up: <!DOCTYPE html> <html lang="en" class="no-js"> <head> <title>Get JSON Value</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/ ...

There are mistakes in the code that I am struggling to fix

I am encountering an issue where my website only functions properly on Firefox and not on Chrome. However, when I run the HTML using NetBeans on Chrome, the website works fine. I'm unsure of what to do as I need to submit this project within the next ...

Exploring jQuery AJAX and how to effectively manage various data types

ASP.Net MVC is the framework I am currently using, but this issue can apply to any framework out there. When making an Ajax call to my server, most of the time it returns plain HTML content. However, in case of an error, I want it to return a JSON object ...

Update the specific component according to the identified modifications

In my project, I have two simple components: parent and child. The parent component contains an Array and for each element in the array, it renders the child component. parent.component.ts export class parent implements OnInit { data: CustomType[] = [ ...

Using Json with React's Context API

I am dealing with nested JSON and arrays within it. My goal is to create a Search functionality that will iterate through the arrays and, based on a specific ID, display the name of the corresponding object in the array. I attempted using the Context API ...

Having trouble transmitting data from the View to the Controller

Need help with this issue. I'm having trouble passing my data to the controller. Below is my ajax code. <script type="text/javascript"> $(document).on("click", "#login_button", function () { var userName = document.getElementById(" ...

Transforming multi-layered form data into a JSON array structure for seamless integration with application/json

I'm currently developing a Laravel application and facing an issue with the $controller->wantsJson() method in the back-end. This method returns TRUE only if the content type of the request is set to application/json. jQuery.ajax({ type: ...

Node js process.kill(pid) is ineffective in terminating a Linux process

Trying to terminate background processes using nodejs process.kill(pid, 'SIGTERM') results in the processes not being killed. After running the node script provided below, I checked the processes using ps -efww | grep 19783 | grep -v grep in the ...

The function cannot be called because the type does not have the appropriate signature for invoking. The specific type lacks compatible call signatures, as indicated

Encountering an issue while attempting to utilize a getter and setter in my service, resulting in the following error message: Cannot invoke an expression whose type lacks a call signature. Type 'Boolean' has no compatible call signatures 2349 t ...

The error message "Property 'destroy' of undefined cannot be read in DataTables"

I need to develop a function that can create a new DataTable. If there is an existing table, I want the function to first destroy it and then create the new one. This is what I have so far: $.ajax().done(function(response){ Init_DT(response[& ...

JavaScript does not allow for the incrementation of a global variable within a function

Imagine I have some JavaScript and HTML code like this: var x = 1 function increase() { x += 1 console.log(x) } <button onclick="increase()">Click</button> When the button is clicked, x increases to 2 but doesn't go any higher ...

Having trouble launching the emulator in VS Code for React Native?

I'm having trouble launching the android emulator on VS Code to run React-Native. I already have an emulator set up in Android Studio, but when I try to launch it, I get the error message: Error Failed to launch emulator. Reason: No emulators found as ...

Exploring the implementation of the meta robots tag within Joomla 2.5's global settings

Encountering a peculiar issue with Joomla 2.5 and the Meta robots tag. Joomla seems to have a flaw where regardless of the URL, as long as there is a valid article id, it will generate a page. For instance: The id '61' is valid but leads to a ...

Manipulating the DOM results in the SWF being reloaded

Currently, I am utilizing jQuery to insert an SWF into the DOM. However, when the SWF loads and I attempt to clone or wrap it, the SWF ends up reloading. Preventing this reload is crucial for me. Here's an example: $('#test9').before(&apo ...

Troubleshooting a JSON error encountered while utilizing the mongoimport tool

Currently, I am utilizing the mongoimport utility to import data from a json file into mongodb with the following command: mongoimport --db city --collection inspections ./city_inspections.json #mongo import utility The json data structure looks like this ...

I am currently exploring next.js and working on creating a dedicated single post page within my project

I am currently working with Next.js and fetching some dummy data on the homepage. However, I am facing an issue when trying to create a separate page for each post obtained from the homepage. Although I have already coded it, I feel like there is room fo ...