POV-Ray : Newsgroups : povray.unofficial.patches : MegaPOV Mechsim Motion Question Server Time
4 Nov 2024 20:15:15 EST (-0500)
  MegaPOV Mechsim Motion Question (Message 1 to 7 of 7)  
From: Tom Bates
Subject: MegaPOV Mechsim Motion Question
Date: 23 Jul 2003 19:54:59
Message: <3f1f2053@news.povray.org>
Greetings Ladies and Gentlemen of the forum,

I have lately been experimenting with the MechSim feature of MegaPOV 1.0.

I have created a somewhat complicated structure of masses and connections that
resembles a small animal.

I start it in the "air" and let it fall as the connections reach a steady state of
sorts by the time it lands on the "ground".

I want to be able to modify some of the values of some of the connections, now, to
see if I can get this creature to move.  Very similar, I suppose, to what Mack
Tuesday described in his posting May 22nd, "MegaPOV mechsim environment collisions".

It has occurred to me, from reading these groups as well as reading the available
documentation, that in order to do this, I need to replace the "load_file" command
with file-reading/topology-rebuilding code of my own.

I've done this, but the animation does not seem to be animating.  It keeps
resimulating the first 1/24 seconds for every frame, so I get the same image for
every frame.

It seems to me that the reason for this is that I'm not doing anything with the
"time" value read from the mechsim data file.  And the reason for this is that I
don't know what to do with the "time" value from the mechsim data file.

I would be extremely grateful if someone could enlighten me as to what I need to do.
If you need more information than what I've provided here, please let me know.

Thank you,

Tom Bates

--
#macro T(B)#local m=mod(B,8);#local B=floor(B/8);m#end#local C=126981491245202;#
local D=115694168992822;sphere_sweep{b_spline 16#local i=0;#while(i<16)<T(C)-4,T
(D)-4,10-i/10>.1#local i=i+1;#end pigment{rgb 1}}light_source{-10,1} //Tom Bates


Post a reply to this message

From: Christoph Hormann
Subject: Re: MegaPOV Mechsim Motion Question
Date: 24 Jul 2003 03:54:18
Message: <3F1F90A9.6EB0F43A@gmx.de>
Tom Bates wrote:
> 
> [...]
> 
> I would be extremely grateful if someone could enlighten me as to what I need to do.
> If you need more information than what I've provided here, please let me know.

You should post your code (the mechsim block would be sufficient).  

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 17 Jun. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Tom Bates
Subject: Re: MegaPOV Mechsim Motion Question
Date: 24 Jul 2003 10:57:43
Message: <3f1ff3e7$1@news.povray.org>
Christoph Hormann wrote:
>
>
> Tom Bates wrote:
> >
> > [...]
> >
> > I would be extremely grateful if someone could enlighten me as to what I need to
do.
> > If you need more information than what I've provided here, please let me know.
>
> You should post your code (the mechsim block would be sufficient).
>
> Christoph
>

Thank you, Christoph, for your attention.

I've included relevant bits from my scene file, below.

A little additional explanation:

I could not seem to properly read the "MSIM" bit at the beginning of the standard
mechsim topology file, (MegaPOV gave me the message: "Parse Error: Expected 'float,
vector, or string literal', undeclared identifier 'MSIM' found instead") so I also
replaced the save_file command with my own macro that created a file that used only
floats and vectors.  I've included the macros "DoMyLoadFile" and "DoMySaveFile".

When I watch the "Calculating Mechanics Simulation" in the bottom of the window, the
Time always starts at zero.

When I look at the mechsim topology file, it never changes from the original, as if
none of the masses ever really moved.

Thank you again for your help.

Tom Bates


--
#macro T(B)#local m=mod(B,8);#local B=floor(B/8);m#end#local C=126981491245202;#
local D=115694168992822;sphere_sweep{b_spline 16#local i=0;#while(i<16)<T(C)-4,T
(D)-4,10-i/10>.1#local i=i+1;#end pigment{rgb 1}}light_source{-10,1} //Tom Bates


---------- Excerpts from Test1.pov -------------


#version unofficial megapov 1.0;
#include "mechsim.inc"
#declare fn_Env = function { y }

//  ...

#macro DoMyLoadFile(FileName)
  #fopen LoadFile FileName read
  #read (LoadFile, MSIM_ID, MSIM_Version, MSIM_Time)  //  <<--  I have to do
something with this, but what?
  #read (LoadFile, NMasses, NConnections, NFaces)

  #local i=0;
  #while (i<NMasses)
    #read (LoadFile, MPos, MVel, MRad, MMass)
    mass { MPos, MVel, MRad mass MMass}
    #local i=i+1;
  #end

  #local i=0;
  #while (i<NConnections)
    #read (LoadFile, MMass1, MMass2, MStiff, MDamp, MLength)

    #if (frame_number=3)
      #if (i=cMainEnd + 12 + 0)  #local MLength = 2.5-2*0.3;  #end
      #if (i=cMainEnd + 12 + 1)  #local MLength = 2.5-2*0.3;  #end
      //  ...
    #end

    connection { MMass1, MMass2 stiffness MStiff damping MDamp length MLength}
    #local i=i+1;
  #end

  #local i=0;
  #while (i<NFaces)
    #read (LoadFile, MMass1, MMass2, MMass3)
    face { MMass1, MMass2, MMass3 }
    #local i=i+1;
  #end
  #fclose LoadFile
#end

#macro DoMySaveFile(FileName)
  #fopen SaveFile FileName write
  #write (SaveFile, "42, 0,\n0,\n")  //  <<--  I have to fix this, but how?
  #write (SaveFile, mechsim:mass_count,",\n")
  #write (SaveFile, mechsim:connection_count,",\n")
  #write (SaveFile, mechsim:face_count,",\n")

  #local i=0;
  #while (i<mechsim:mass_count)
    #write (SaveFile, mechsim:mass(i):position,",",
                      mechsim:mass(i):velocity,",",
                      mechsim:mass(i):radius,",",
                      mechsim:mass(i):mass,",\n")
    #local i=i+1;
  #end

  #local i=0;
  #while (i<mechsim:connection_count)
    #write (SaveFile, mechsim:connection(i):index1,",",
                      mechsim:connection(i):index2,",",
                      mechsim:connection(i):stiffness,",",
                      mechsim:connection(i):damping,",",
                      mechsim:connection(i):length,",\n")
    #local i=i+1;
  #end

  #local i=0;
  #while (i<mechsim:face_count)
    #write (SaveFile, mechsim:face(i):index1,",",
                      mechsim:face(i):index2,",",
                      mechsim:face(i):index3,",\n")
    #local i=i+1;
  #end
  #fclose SaveFile
#end


global_settings {
  assumed_gamma 1.0
  max_trace_level 15

  mechsim {
    // Most of these settings were what I copied out of one of the samples.
    gravity <0, -9.81, 0>
    method 2

    environment {
      function { fn_Env(x, y, z) }
      stiffness 240000
      damping 35000
      friction 0.2, 1.001
    }

    collision {
      2, 2
      stiffness 180000
      damping 30000 //5000
      friction 0.2, 1.001
    }


    #if (clock_on)
      step_count 500
      time_step (1/24)/500

      topology {
        #local cMainEnd   = 1257;

        //  load_file "test1.dat"
        DoMyLoadFile("test1.dat")

        //  save_file "test1.dat" 3
        DoMySaveFile("test1.dat")
      }
    #else
      step_count 0
      topology {

        #local mFRUStart  = mechsim:mass_count;
          Bone(TransFRU)
        #local mFRUEnd    = mechsim:mass_count;
        #local mFRLStart  = mechsim:mass_count;
          Bone(TransFRL)
        #local mFRLEnd    = mechsim:mass_count;

        #local mFLUStart  = mechsim:mass_count;
          Bone(TransFLU)
        #local mFLUEnd    = mechsim:mass_count;
        #local mFLLStart  = mechsim:mass_count;
          Bone(TransFLL)
        #local mFLLEnd    = mechsim:mass_count;

        #local mBRUStart  = mechsim:mass_count;
          Bone(TransBRU)
        #local mBRUEnd    = mechsim:mass_count;
        #local mBRLStart  = mechsim:mass_count;
          Bone(TransBRL)
        #local mBRLEnd    = mechsim:mass_count;
        #local mBRFStart  = mechsim:mass_count;
          Bone(TransBRF)
        #local mBRFEnd    = mechsim:mass_count;

        #local mBLUStart  = mechsim:mass_count;
          Bone(TransBLU)
        #local mBLUEnd    = mechsim:mass_count;
        #local mBLLStart  = mechsim:mass_count;
          Bone(TransBLL)
        #local mBLLEnd    = mechsim:mass_count;
        #local mBLFStart  = mechsim:mass_count;
          Bone(TransBLF)
        #local mBLFEnd    = mechsim:mass_count;

        #local mMainStart = mechsim:mass_count;
        MechSim_Generate_Grid_Std( 0, 0.1, Dense, Stiff, Damp,
                            Faces, <1,1,1>, <5,2,9>, TransMain, 3 )
        #local mMainEnd   = mechsim:mass_count;

        #local cMainEnd   = mechsim:connection_count;
        #debug concat("#local cMainEnd = ",str(cMainEnd,0,0),";\n")

        Heel(mFRUEnd, mFRLStart, 0.3)
        Heel(mFLUEnd, mFLLStart, 0.3)

        Knee(mBRUEnd, mBRLStart, 0.7)
        Heel(mBRLEnd, mBRFStart, 0.9)

        Knee(mBLUEnd, mBLLStart, 0.7)
        Heel(mBLLEnd, mBLFStart, 0.9)

        Shoulder(mMainStart+0,mFRUStart,0.6)
        Shoulder(mMainStart+3,mFLUStart,0.6)
        HipJoint(mMainEnd  -3,mBRUStart,0.8)
        HipJoint(mMainEnd  -0,mBLUStart,0.8)

        //  save_file "test1.dat" 3
        DoMySaveFile("test1.dat")
      }

    #end
  }
}


Post a reply to this message

From: Christoph Hormann
Subject: Re: MegaPOV Mechsim Motion Question
Date: 24 Jul 2003 11:15:33
Message: <3F1FF814.8B6BC333@gmx.de>
Tom Bates wrote:
> 
> [...]
> 
> I could not seem to properly read the "MSIM" bit at the beginning of the standard
> mechsim topology file, (MegaPOV gave me the message: "Parse Error: Expected 'float,
> vector, or string literal', undeclared identifier 'MSIM' found instead")

Yes, i know this problem, POV-Ray expects strings to be in quotes.  I
thought about either adding quotes to the file format or introducing an
additional patch for a more tolerant #read function.  I must say i don't
like any of those solutions. :-(

> so I also
> replaced the save_file command with my own macro that created a file that used only
> floats and vectors.  I've included the macros "DoMyLoadFile" and "DoMySaveFile".

Without analyzing your code in depth - it can't work since you call your
'DoMySaveFile' immediately after 'DoMyLoadFile' so you save exactly what
you read.  The simulation is done at the end of the mechsim{} block so you
will have to save your data afterwards (the internal 'save_file' waits
until after the simulation of course).

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 17 Jun. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Tom Bates
Subject: Re: MegaPOV Mechsim Motion Question
Date: 24 Jul 2003 11:57:31
Message: <3f2001eb@news.povray.org>
> > so I also
> > replaced the save_file command with my own macro that created a file that used
only
> > floats and vectors.  I've included the macros "DoMyLoadFile" and "DoMySaveFile".
>
> Without analyzing your code in depth - it can't work since you call your
> 'DoMySaveFile' immediately after 'DoMyLoadFile' so you save exactly what
> you read.  The simulation is done at the end of the mechsim{} block so you
> will have to save your data afterwards (the internal 'save_file' waits
> until after the simulation of course).

Well, that makes sense.  Although, there's apparently more to my problems than just
that.

Out of curiosity, though, I moved the DoMySaveFile call to just after the machsim{}
block, as suggested, to see if that change alone would make a difference.  Sadly it
did not.

>
> Christoph
>

Tom Bates


--
#macro T(B)#local m=mod(B,8);#local B=floor(B/8);m#end#local C=126981491245202;#
local D=115694168992822;sphere_sweep{b_spline 16#local i=0;#while(i<16)<T(C)-4,T
(D)-4,10-i/10>.1#local i=i+1;#end pigment{rgb 1}}light_source{-10,1} //Tom Bates


Post a reply to this message

From: Christoph Hormann
Subject: Re: MegaPOV Mechsim Motion Question
Date: 24 Jul 2003 12:18:17
Message: <3F2006C9.C7EDE79B@gmx.de>
Tom Bates wrote:
> 
> [...]
> 
> Out of curiosity, though, I moved the DoMySaveFile call to just after the machsim{}
> block, as suggested, to see if that change alone would make a difference.  Sadly it
> did not.

So what you are saying is that you generate a topology, run simulation and
the data accessed via 'mechsim:mass(i):position' etc. afterwards is not
different from before?

Now that's peculiar...

I'd suggest you really check this in detail because there is likely to be
some fault.

If you are extremely sure it works this way please create a minimal test
scene (a single mass should suffice) so i can test it.

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 17 Jun. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Tom Bates
Subject: Re: MegaPOV Mechsim Motion Question
Date: 24 Jul 2003 13:32:34
Message: <3f201832@news.povray.org>
Sorry, my bad.

I had put the DoMySaveFile call outside the topology{} block, NOT outside the
mechsim{} block.

NOW I have the DoMySaveFile call outside the mechsim{} block, and it's working like a
charm.  Thank you very much for your help.

Christoph wrote:
>
>
> Tom Bates wrote:
> >
> > [...]
> >
> > Out of curiosity, though, I moved the DoMySaveFile call to just after the
machsim{}
> > block, as suggested, to see if that change alone would make a difference.  Sadly
it
> > did not.
>
> So what you are saying is that you generate a topology, run simulation and
> the data accessed via 'mechsim:mass(i):position' etc. afterwards is not
> different from before?
>
> Now that's peculiar...
>
> I'd suggest you really check this in detail because there is likely to be
> some fault.
>
> If you are extremely sure it works this way please create a minimal test
> scene (a single mass should suffice) so i can test it.
>
> Christoph
>
> --
> POV-Ray tutorials, include files, Sim-POV,
> HCR-Edit and more: http://www.tu-bs.de/~y0013390/
> Last updated 17 Jun. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.