Particle Surface Questions

Eugene
2007-02-11
2013-05-28
  • Eugene
    Eugene
    2007-02-11

    I've seen toxi's old particle tutorial, and I've looked through the SCParser, but I still can't figure out the particle surface.  I was wondering if anyone has gotten it working and if they might be able to link to an example or "how to" on using the partcile surface using the data from your own model as the shape.  From what I can tell, you need a file with data, a radius, a number, and a little_endian?

     
    • Thats right. Can you post more details about what errors you are getting?

      The particle data file just contains the raw floating point data for particle positions as: xyzxyzxyz,.... in binary form. The default is big endian byte order but if you specify the "little_endian" keyword Sunflow can read the data that way.

       
    • Eugene
      Eugene
      2007-02-11

      I think it's because I'm just not implementing a data file properly.  What I tried doing is taking the point data from an exported object and added it to a data file and call that from within the scene file.  Here is the error I get:

      API    error : Cannot create point parameter particles -- invalid data length
      API    error : Unable to update "particles_1" - removing
      GEOM   error : Geometry "particles_1" was not declared yet - instance is invalid
      API    error : Unable to update "particles_1.instance" - removing
      API    error : Expecting } found null

       
      • Indeed it seems the file format is invalid. Here is what the .sc file should contain:

        object {
            shader grey
            type particles
            filename "c:/your_folder/particles.dat"
            radius 0.03
        }

        particles.dat should be a binary file, ie: not human readable. The file should be exactly 4*3*n bytes long, where n is the number of particles. Are you writing out the particle file by some code you wrote? What do you mean by "taking point data from an exported object" ?

        I'm going to add a plain ascii syntax so you can specify particle data in ascii directly in the .sc file. This should make things easier in the next version. Note also that the particle file expects an absolute path (or relative to where you launched sunflow from). I will fix this so the path can be relative to the scene file for the next version too.

        If you are still confused, mail me your scene and the code you are using to generate your particle file and I will take a look.

         
    • Eugene
      Eugene
      2007-02-11

      I see now.  My absolute path was correct, but by trouble was that I wasn't using a binary .dat file.  I was taking the point data from an exported object (e.g. 1.58558118343 -0.436836093664 2.2244925499) and thinking that would be sufficient to add to its own data file (which it obviously wasn't).  So I suppose the big question is when ascii is allowed, will we be able to use object point information like I descibe above?  Until then, how would I generate a binary file for a specific model?

       
      • Yes you will be able to do what you wanted. I already added this into svn, the new syntax is:

        object {
          shader grey
          type particles
          points 5
             0.1 0.2 0.3
             0.1 0.2 0.3
             0.1 0.2 0.3
             0.1 0.2 0.3
             0.1 0.2 0.3
          radius 0.03
        }

        The filename method still works obviously, it will be more efficient for large amounts of particles (the files can now be specified relative to the include path).

        Here is a workaround you can use in the meantime. Create a .java file alongside your .sc file with the following contents:

        import org.sunflow.core.primitive.ParticleSurface;
        import org.sunflow.system.Parser;

        public void build() {
          include("your_scene.sc");                                   // the name of your scene file goes here
          try {
            Parser p = new Parser(resolveIncludeFilename("your_ascii_filename.dat")); // the name of your particle file goes here
            int n = p.getNextInt();
            float[] data = new float[3 * n];
            for (int i = 0; i < data.length; i++)
              data[i] = p.getNextFloat();
            p.close();
            parameter("particles", "point", "vertex", data);
            parameter("num", data.length / 3);
            parameter("radius", 0.1f);                             // the radius of the particles goes here
            geometry("particle_object_name", new ParticleSurface());
            parameter("shader", "shader_name");                    // replace with the shader name you want to use
            instance("particle_object_name.instance", "particle_object_name");
          } catch (Exception e) {
            e.printStackTrace();
          }
        }

        Just render this .java file from the command line instead of the main .sc file. All the paths can be relative, you only need to specify the filename as long as they are all in the same folder.

        I just typed that without testing it, so let me know if it doesn't work. I also assumed that your ascii file contains the number of points in the first line.

         
    • kirkthibault
      kirkthibault
      2007-02-13

      I tried the above code and I get an error:

      "Line 5, Column 9: A method named "include" is not declared in any enclosing class nor any supertype, nor through a static import."  I got this error by command line and also by cutting and pating the code into the script window within the GUI.

      kirk

       
      • I'm sorry, the first line of the code should be:

        parse("yourfile.sc");

         
    • kirkthibault
      kirkthibault
      2007-02-13

      Thanks Chris!  That resolved the problem - however, one minor glitch that I eventually figured out is:

      Line 17: parameter("shader", "shader_name"); // replace with the shader name you want to use

      SHOULD READ:

      parameter ("shaders", ....
      [plural "shaders" not "shader"]

      Then it works fine!

      Thanks again!

      kirk

       
      • Glad to hear it worked. Sorry about the typos on the shaders arg.

         
    • kirkthibault
      kirkthibault
      2007-02-13

      No worries - I'm sure you built those typos in to the posted code just to sharpen my fledgling Java skills.  Thanks for the encouragement!

      kirk

       
    • kirkthibault
      kirkthibault
      2007-02-14

      Simple particle surface test:

      http://kirkt.smugmug.com/photos/129633990-L.jpg

      used the paritcle surface more like a 3D matrix of points - just handcoded a simple .dat file to feed to the above java code snippet.

      Thanks Chris.

      kirk

       
      • Nice image!