The initial program in Sim.js resulted in no visual elements displayed on the screen

Currently, I am working my way through the book "WebGL: up and running". The initial program introduced using Sim.js is quite complex for me to comprehend every instruction effectively, as I haven't been able to find any reliable documentation on Sim.js. Therefore, I have decided to create a simpler program in order to gain a better understanding of how it functions.

This program draws inspiration from the code provided in the 3rd chapter, specifically from these two files:

  1. earth-basic.js
  2. graphics-earth-basic.html

I attempted to replicate a similar program that constructs a simple sphere without texture. However, there seems to be an issue as nothing appears on the screen besides the title. Below is the code snippet:

<!DOCTYPE html>
<html>
    <head>
        <title> Sim.js Test </title>
    </head>
    <body>
        <h1 align="center"> Sim.js Test </h1>
        <div id="container" width="400" height="400"></div>
        <script src="../Three.js-master/build/three.min.js"></script>
        <script src= "../Sim.js-master/sim.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script src="jquery.mousewheel.min.js"></script>
        <script type="text/javascript">

            SphereApp= function() {
                Sim.App.call(this);
            }

            SphereApp.prototype= new Sim.App();

            SphereApp.prototype.init= function(param) {
                Sim.App.prototype.init.call(this,param);
                var sphere= new Sphere();
                sphere.init();
                this.addObject(sphere);
            }

            Sphere= function() {
                Sim.Object.call(this);
            }

            Sphere.prototype= new Sim.Object();

            Sphere.prototype.init = function() {
                var object= new THREE.Mesh( new THREE.SphereGeometry(1,10,10), new THREE.MeshBasicMaterial({color:0xff0000}));
                this.setObject3D(object);
            }

            Sphere.prototype.update= function() {
            }

            $(document).ready( function() {
                var container= document.getElementById("container");
                var app= new SphereApp();
                app.init({container:container});
                app.run(); 
            });

        </script>
    </body>
</html>

Answer №1

To resolve the issue, I made adjustments to the attributes of the HTML div element:

<div id="wrapper" style="width:100%;height:100%;background-color:black;overflow:hidden; position:absolute;"> </div>

Although the drawing appeared fine, the container remained concealed.

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

Eliminating HTML element within CKEditor

I'm in the process of developing a CKEditor plugin and one feature I'd like to include is the ability to delete specific HTML elements from the editor's content. For example, removing an <img id="remove-me" />. I understand that I can ...

How come it's not possible to modify the text of this button right when the function kicks off?

When I click a button, it triggers a JavaScript function. The first line of code within the function uses jQuery to change the HTML of the button. However, the button's text does not update in the browser until after the entire function has completed, ...

Incorrect pathing in express.js

I've encountered an issue with my filter while attempting to redirect packages using two express.js routes: app.get('/billdetails/:year/:month/:phoneId', function (req, res, next) { var db = req.db; var year = req.params.year; v ...

Navigating using JavaScript dot notation is a powerful way to

Is there a way to implement JavaScript or jQuery code that will assign an active class to a dot when it is clicked, while also removing the active class from any other dots in the sequence? HTML: <div class="dotnav"> <div class="dot active" ...

Is there a way to utilize two onChange functions within one component?

I'm having trouble utilizing two onChange functions within the same component. I attempted to combine them, but I ran into an issue because one is using useState and the other is a const function. Below is my code snippet: const signup = () => { ...

The window.Print() function is currently experiencing a glitch in Microsoft Edge (Version 91.0.864.59) when trying to use it for the first time within an Angular 12

If you encounter the issue, please follow these steps using the latest version 91.0.864.59 of the Edge browser: https://stackblitz.com/edit/angular-ivy-zbvzap?file=src/app/app.component.html Click on the print button. Close the print dialog. Click on the ...

transforming a cylindrical shape into a curved pipe

Utilizing the capabilities of three.js, I have successfully engineered a captivating scene featuring a textured and meshed cylinder along with a grid boasting lines and vertices. By manipulating the mouse to the left or right, the cylinder elegantly spins ...

Unfortunately, the YouTube iframe Embed feature does not have the ability to adjust audio settings on an

I've been experimenting with the YouTube iframe API and created a simple set of player controls for the YouTube player using Flash CC HTML5 canvas. The controls include a play/pause button, a draggable video bar with buffering visualization, and a vol ...

Eliminate the specified element from the array

I have a text input field where users can enter their interests. Upon pressing the Enter key, the entered interest is added to an array called "interests". These interests are displayed on the screen using a component called "Domain". Each interest element ...

Get a list of all languages supported by browsers using JavaScript

Within my HTML user interface, I have a dropdown that needs to display a list of all installed browser languages except for the first one. I managed to retrieve the first language (en-us), but I also have the zh-CN Chinese pack installed on my operating s ...

The Redis ReJSON consistently throws two errors at me: one for a missing key in a non-terminal path, and another for the requirement to create a

Understanding the second error is relatively simple, while the first error poses a bit more of a challenge. I have experimented with various combinations to address this error, but unfortunately, no progress has been made. When I check my console, I recei ...

Collect data from a third-party website that necessitates the activation of JavaScript

Given that phantomjs has been abandoned, I am exploring alternative methods. For instance, using chrome-webdriver may not be ideal as it cannot operate on a remote host like heroku. Is there a way to scrape a website that relies on JavaScript being activa ...

What is the best way to loop through children in an array using JavaScript?

I have an array that might look like this: arr1 = ["node1","children1","children1.1","children1.1.1"] or it could be arr2 = ["node1","children1"] and I am trying to convert it into the following JSON format: const data_arr1 = [{ title: "N ...

Dragging and Dropping Electron Files into an Inactive Window

I am exploring the implementation of drag and drop functionality within an electron window, utilizing the suggested approach of sandboxing processes. This involves isolating ipcMain from ipcRenderer and creating a bridge through a preload.js script (refer ...

Saving an array of key-value pairs in local storage

I'm attempting to save an array in local storage using the following code: var tempval = []; tempval['key'] = 1; localStorage.setItem("Message", JSON.stringify(tempval)); However, when I check local storage, it only sho ...

Suggestions for updating ng-repeat variable with autocomplete functionality?

Many thanks to the Stack Overflow community for helping me resolve my previous angularjs and autocomplete issue. Here is the link to the question: Angularjs with jquery auto complete not working However, I am facing a similar problem now within the ng-rep ...

Adjusting the Pace of a CSS Marquee

My CSS marquee effect is working perfectly, but I am having trouble with the speed. The issue arises when the text length varies - shorter text takes longer to scroll while longer text scrolls quickly. This inconsistency is due to the animation duration an ...

What is preventing me from retrieving WP custom fields value or post ID using Ajax?

After successfully generating a link based on the visitor's location, I encountered an issue with caching when using full-page caching. To address this problem, I decided to implement AJAX to dynamically load the link. While my code worked well in ret ...

Automatically generated list items are failing to react to the active class

I am facing an issue with two divs in my project. The first div uses the Bootstrap class list-group and is populated with a basic example provided by Bootstrap. The second div is supposed to be populated with list-group-items obtained from an AJAX GET requ ...

Javascript handling scrolling and repositioning

When using the scrollBy() method in the window object of JavaScript, there are two arguments required. But what do these arguments actually represent? The resource I am currently studying from states that it is "the number of pixels to scroll by," but I am ...