POV-Ray : Newsgroups : povray.unofficial.patches : MegaPOV Mechsim Motion Question : Re: MegaPOV Mechsim Motion Question Server Time
28 Sep 2024 16:43:19 EDT (-0400)
  Re: MegaPOV Mechsim Motion Question  
From: Tom Bates
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

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