Encountering an issue where the P3D sketch does not function properly when running

Currently, I am in the process of converting a project I developed in Processing [Java Mode] to an online platform for web viewing. The project involves P3D rendering to showcase a 3D environment that allows for rotation and manipulation of three data sets (.tsv files) representing earthquake locations and sizes over three years. The code functions well in Java mode, but in JavaScript mode, it only displays a blank gray screen. I have ensured that the HTML for embedding the sketch in the canvas is correct and error-free, so I suspect an issue within the code that might not be compatible with JavaScript. Is it possible to run the PDE as Java without relying on Processing.js? Alternatively, can someone identify any compatibility issues with the Processing.js code?

For reference, here is the link to the non-functional sketch.

Any advice on how to proceed would be greatly appreciated. Thank you.

float dial = 0.0;
FloatTable data;
FloatTable data2;
float dataMin, dataMax;
int rowCount;
int currentColumn = 0;
int columnCount;

int yearMin, yearMax;
int[] years;

int yearInterval = 10;
int volumeInterval = 10;
int volumeIntervalMinor=5;

PImage bg;
PImage texmap;
PFont font;
PImage img, img2;
PImage imgTitle;

int sDetail = 35;  // Sphere detail setting
float rotationX = 0;
float rotationY = 0;
float velocityX = 0;
float velocityY = 0;
float globeRadius = 750;
float pushBack = 0;

float[] cx, cz, sphereX, sphereY, sphereZ;
float sinLUT[];
float cosLUT[];
float SINCOS_PRECISION = 0.5;
int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION);

void setup() {
size(1300,1000, P3D);  
textSize(100);
texmap = loadImage("img/world32k.jpg");   
initializeSphere(sDetail);
setupstuff("2011.tsv");
}

void draw() {    

background(0);    
// drawTitle(); 
drawMain();
renderGlobe(); 
drawDial();

}
void setupstuff(String filename){
data = new FloatTable(filename);
rowCount=data.getRowCount();
columnCount = data.getColumnCount();
years = int(data.getRowNames());
yearMin = years[0];
yearMax = years[years.length - 1];
font = loadFont("Univers-Bold-12.vlw");
dataMin = 0;
dataMax = ceil( data.getTableMax()/volumeInterval)*volumeInterval;
img = loadImage("img/dialface.jpg");
img2 = loadImage("img/dial.png");
imgTitle = loadImage("Title.png");
imageMode(CENTER);
} 

/* More lines of code copied from original text... */

Answer №1

LATEST UPDATE

The issue you are encountering with the Float error may be linked to this specific line:

return !Float.isNaN(data[row][col]);

It's important to note that JavaScript does not recognize Float as it is a Java concept not fully integrated in Processing. You will need to find an alternative for this comparison, such as referring to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN

Similarly, statements like:

float m = Float.MAX_VALUE;

will not function correctly with ProcessingJS. Consider using: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity

Debugging in ProcessingJS can be quite challenging, so ensure you avoid strictly Java elements not fully implemented in Processing. Also, be wary of variable naming conflicts. Refer to the following link to understand potential pitfalls:

Additionally, there is a method missing a closing brace:

float getTableMin() {
    float m = Float.MAX_VALUE;
    for (int row = 0; row < rowCount; row++) {
      for (int col = 0; col < columnCount; col++) {
        if (isValid(row, col)) {
          if (data[row][col] < m) {
            m = data[row][col];
          }
        }
      }
    }
    return m;

Ensure to add the closing brace like so:

float getTableMin() {
    float m = Float.MAX_VALUE;
    for (int row = 0; row < rowCount; row++) {
      for (int col = 0; col < columnCount; col++) {
        if (isValid(row, col)) {
          if (data[row][col] < m) {
            m = data[row][col];
          }
        }
      }
    }
    return m;
}  

Properly formatted code is crucial. Use Ctrl-t in your Processing IDE to automatically tidy up your code for better readability.

Furthermore, your code wouldn't even execute in Java mode without this correction. It would trigger an unexpected token: float error for the concerned method.

ADDITIONAL UPDATE

To eliminate the Float related issues, adjust the following line:

return !Float.isNaN(data[row][col]);

to

return isNaN(data[row][col]);

Substitute all occurrences of Float.MAX_VALUE; with Number.MAX_VALUE;.

After switching to JavaScript-friendly code, I encountered the error you're facing as well. I will attempt to troubleshoot and update the solution accordingly.

Answer №2

Instead of using the fullscreen() function, consider using the following code snippet:


size(window.innerWidth, window.innerHeight, P3D);

IMPORTANT: This code snippet may not work in Internet Explorer.

void setup() {
    if (window.innerWidth) {
        wW = window.innerWidth;
        wH = window.innerHeight;
    } else {
        var cW = document.body.offsetWidth;
        var cH = document.body.offsetHeight;
        window.resizeTo(500,500);
        var barsW = 500 - document.body.offsetWidth;
        var barsH = 500 - document.body.offsetHeight;
        wW = barsW + cW;
        wH = barsH + cH;
        window.resizeTo(wW,wH);
    }
    size(wW,wH,P3D);
}

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

Utilize the data storage API within Next.js or directly in the user's

Struggling to store this ini file on either the server or client, any help would be greatly appreciated. Additionally, I would like to display the ini info in the browser so that clients can easily copy and paste the information. However, I seem to be fac ...

JavaScript - Executing the change event multiple times

Below is the table I am working with: <table class="table invoice-items-table"> <thead> <tr> <th>Item</th> <th>Quantity</th> <th>Price</th> & ...

Retrieve the service variable in the routing file

How do I access the service variable in my routing file? I created a UserService with a variable named user and I need to use that variable in my routing file. Here is the approach I tried, but it didn't work: In the routing file, I attempted: cons ...

Having trouble with Spring Boot 3 Security's requestMatchers.permitAll?

Here is the newly implemented SecurityFilterChain bean based on the updated Spring Security 6 / Spring boot 3 documentation. However, the configuration requestMatchers -> AntPathRequestMatcher -> permitAll seems to be ineffective as every request is ...

Increasing the Efficiency of Styled Components

It appears to me that there is room for improvement when it comes to checking for props in Styled Components. Consider the following code: ${props => props.white && `color: ${colors.white}`} ${props => props.light && `color: ${c ...

Components for managing Create, Read, Update, and Delete operations

As I embark on my Angular 2 journey with TypeScript, I am exploring the most efficient way to structure my application. Consider a scenario where I need to perform CRUD operations on a product. Should I create a separate component for each operation, such ...

Creating a GITHUB project with Maven

Coming from a BIG Data background, I need some assistance with Maven. I am looking to obtain a JSON jar file for use in my json tables. There is serialization/deserialization code available on Github at this location: https://github.com/rcongiu/Hive-JSON-S ...

What is the proper method for deserializing .NET Dictionary objects with Jackson?

Here's a brief summary before diving into the detailed explanation below :-) I'm looking for help on deserializing a Dictionary using Jackson and a custom deserializer. Currently, I have an Android app communicating with a .NET (C#) server via ...

What steps should I take to create a collapsible Bootstrap navbar?

I'm attempting to recreate the scrolling functionality seen here: It seems like they might be using a customized Bootstrap Navbar, so I've taken one from here: and tailored it to my needs. How can I achieve the effect where the navigation bar ...

I'm having difficulty mocking a function within the Jest NodeJS module

I have a module in NodeJS where I utilize a function called existsObject to validate the existence of a file in Google Storage. While testing my application with Jest 29.1.2, I am attempting to create a Mock to prevent the actual execution of this functio ...

UI is experiencing lag issues post Alert invocation in React Native

// When a text field is pressed, an alert function is called. This function opens an alert and then calls another function on confirmation. However, the application gets stuck when "showAlert1()" is called, and this function is being invoked multiple times ...

Issue: The component factory for GoogleCardLayout2 cannot be located

Recently I've been working on an Ionic 3 with Angular 6 template app where I encountered an issue while trying to redirect the user to another page upon click. The error message that keeps popping up is: Uncaught (in promise): Error: No component fac ...

Ensure that the control button is pressed during the JavaScript onclick event function

I am looking to create a JavaScript function that checks if the CTRL button is pressed. Here is my PHP code: <tr class="clickable" onclick="gotolink('<?= base_url() . invoices/createinvoice/' . $customer->Id; ?>')"> And here ...

Using the power of Javascript's jQuery library: the fantastic ".on()" Event Handler

I'm encountering an issue with the Jquery Event Handler ".on()". On my home page, I have a Favorite button on each post. If the post has not been favorited: li appears inactive Event 1 is triggered If the post has been favorited: li appears act ...

What is the process of choosing a language (English/French) within a pop-up?

<body style="text-align:center"> <h2>Popup</h2> <div class="popup" onclick="myFunction()">Interact with me to show/hide the popup! <span class="popuptext" id="myPopup">A Simple Popup!</span> </div> <script& ...

Trouble arises when trying to import Jest with Typescript due to SyntaxError: Import statement cannot be used outside a module

Whenever I execute Jest tests using Typescript, I encounter a SyntaxError while importing an external TS file from a node_modules library: SyntaxError: Cannot use import statement outside a module I'm positive that there is a configuration missing, b ...

Sending server components to client components as properties

I've been working on making an API call in my ServerComponent.js to retrieve data that I can then pass as props to ClientComponent.js. This allows me to display cached text content from an API on the front page without having to make a new API call ev ...

The retrieval of JSON data in a JavaScript function is malfunctioning

I am new to working with Ajax and have reached the point where I am able to retrieve data. However, I am struggling to return the data as I keep getting undefined values. Below is the code snippet: function select_aragement(arragament){ var arrst = ar ...

Using Javascript to define cookie values

I'm attempting to use JavaScript to set a cookie that will instruct Google Translate to select the language for the page. I've experimented with setting the cookie based on my browser's cookie selection of a language. <script> $(doc ...

Using Angular's ng-repeat prefilter with JavaScript

Is it possible to achieve the functionality of this angular js filter ng-repeat on a tr element using pure javascript? Could it be done in just one custom filter? Please note that showRow is a function that returns a boolean value, and searchString is a s ...