Hi everyone, first of all I’m so happy to have found a Processing instance here on Lemmy!

I’m doing a Processing project where I have ~100 instances of people, all coming from the same 3d model. I’m currently storing all the PShapes inside a 1D array and doing all the drawing inside the draw() function. Now, I would love to put everything that concerns the person inside a class. If I create something like:

class Person {
    PShape person_obj  = loadShape("path/to/shape.obj");

    Person() {}
}

does Processing automatically load only a single model or do I have 100 models in RAM? If the answer is the latter, I tried changing PShape to a static variable but loadShape() is not static and everything results in an error.

Processing documentation about explicit simply says “yeah it’s a java language feature, study it if you need it” which makes sense. So, I started looking for static usages in Java and tumbled upon this StackOverflow post, that basically says to use a context class with all the 3d objects I statically need and pass is to everything else that needs the 3d models.

(link: https://stackoverflow.com/questions/4969171/cannot-make-a-static-reference-to-the-non-static-method )

Does anyone know if it’s the correct approach for Processing?

  • breadsmasher@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    7 months ago

    If I understand correctly, I think what you are getting at is a class which contains the loaded model, and this class is passed into each instance of Person when it loads up.

    On my phone and stuff, not intentionally vague but off the top of my head,

    Have a PersonModel class which handles loading the model into memory and then the other Person class would have this PersonModel class as a dependency. When Person needs the Model, it would use the one declared in PersonModel