POV-Ray : Newsgroups : povray.unofficial.patches : Megapov 1.2 - mechsim - How can I remove a mass Server Time
31 Oct 2024 19:02:00 EDT (-0400)
  Megapov 1.2 - mechsim - How can I remove a mass (Message 1 to 5 of 5)  
From: submersible toaster
Subject: Megapov 1.2 - mechsim - How can I remove a mass
Date: 12 Aug 2005 10:30:01
Message: <web.42fcb156b3e0fe5273647170@news.povray.org>
Unless I've missed something in the docs , I cannot find a way to remove
mechsim objects from a scene short of hacking on the MSIM file itself.

I'm trying to expire a mass after it reaches a certain distance , does
anyone have any pointers?


Post a reply to this message

From: Christoph Hormann
Subject: Re: Megapov 1.2 - mechsim - How can I remove a mass
Date: 12 Aug 2005 12:25:01
Message: <ddiiap$8bn$1@chho.imagico.de>
submersible toaster wrote:
> Unless I've missed something in the docs , I cannot find a way to remove
> mechsim objects from a scene short of hacking on the MSIM file itself.

That is correct - there isn't currently any way to do this except 
modifying the data file.  To be more precise: access to simulation data 
from the scene file is completely read-only.

Christoph

-- 
POV-Ray tutorials, include files, Landscape of the week:
http://www.tu-bs.de/~y0013390/ (Last updated 24 Jul. 2005)
MegaPOV with mechanics simulation: http://megapov.inetart.net/


Post a reply to this message

From: submersible toaster
Subject: Re: Megapov 1.2 - mechsim - How can I remove a mass
Date: 14 Aug 2005 08:20:01
Message: <web.42ff363ba3e0ebc673647170@news.povray.org>
So something like this might be called right after load_file , expires some
mass objects . It would require either careful use of concat() and str() or
a shell-out to something that can read a file listing the mass indexes to
expire. ??

#macro ExpireMass_Distance( Point, Distance )

#if (mechsim:mass_count)
 #while (Cnt<mechsim:mass_count)
  #local Mass_Pos = mechsim:mass(Cnt):position
  #if (vlength( Mass_Pos - Point ) < Distance )
    //Do nothing mass in still in range
  #else
    //Mass is out of range and should be removed
    //Write sim data to a temporary file?
    // Or write Cnt to a temporary file and shell-out to script to remove
from MSIM
 #local Cnt=Cnt+1;
 #end
#end


> modifying the data file.  To be more precise: access to simulation data
> from the scene file is completely read-only.

Is that by design or simply that it's not a often requested feature?


Post a reply to this message

From: Christoph Hormann
Subject: Re: Megapov 1.2 - mechsim - How can I remove a mass
Date: 14 Aug 2005 09:20:02
Message: <ddng62$67o$1@chho.imagico.de>
submersible toaster wrote:
> So something like this might be called right after load_file , expires some
> mass objects . It would require either careful use of concat() and str() or
> a shell-out to something that can read a file listing the mass indexes to
> expire. ??

The mechsim data file format can't be read using the SDL file reading 
features so you would need an external tool for this.

>>modifying the data file.  To be more precise: access to simulation data
>>from the scene file is completely read-only.
> 
> Is that by design or simply that it's not a often requested feature?

By design to some extent.  It would not really be difficult to add this 
from side of the mechsim patch but the POV-Ray scene description 
language currently does not offer any comparable feature so it would 
change the nature of the language to have such a function.

For example offering something like

mechsim:mass(Cnt):remove()

would be possible but it would be a function which returns nothing - 
something that currently does not exit in POV-Ray.

Another possibility would be to have the topology{} block and topology 
elements be declarable:

#declare Obj = topology { load_file "test.dat" }

and allow access to its elements via

Obj:mass(i)

this way you would have completely free control over the simulation data 
from the scene file.  But this would also be something completely new in 
terms of language design.

Christoph

-- 
POV-Ray tutorials, include files, Landscape of the week:
http://www.tu-bs.de/~y0013390/ (Last updated 24 Jul. 2005)
MegaPOV with mechanics simulation: http://megapov.inetart.net/


Post a reply to this message

From: submersible toaster
Subject: Re: Megapov 1.2 - mechsim - How can I remove a mass
Date: 23 Aug 2005 06:05:01
Message: <web.430af447a3e0ebc673647170@news.povray.org>
Rather convoluted but successful , Find below - a macro that identifies
masses that are greater than 'Distance' from 'Position'. Expired mass
indicies are written to 'ExpireFile' seperated by newlines , with the first
line containing the name of 'LoadFile' from which these masses were chosen.

Also find perl code that when called will load the file named as it's first
argument (the expiry file) , then parse the named msim datafile , remove
the masses at indicies listed and out (hopefully) correct msim data to
STDOUT.

BUGS: mechsim_expire.pl is completly ignorant of the connections of masses
to other mechsim objects , hence connections would snap to different
apparent masses . It is by no means complete , but does all I need it to
right now.




// "mechsim_expire.inc"
#version unofficial MegaPov 1.2;
#macro ExpireMasses(LoadFile,ExpireFile,Position,Distance)
#if (mechsim:mass_count)
 #local Cnt = 0;
 #fopen Expiry ExpireFile write
 #write ( Expiry , LoadFile, "n" )

 #while (Cnt<mechsim:mass_count)
  #local Mass_Pos = mechsim:mass(Cnt):position;
  #local Length = vlength( Mass_Pos - Position );
  //#debug concat( str(Cnt,0,0) , " has vlength from origin of " ,
str(Length,3,3) , "n")
  #if ( Length  < Distance )
    //Do nothing mass in still in range
  #else
 //#debug concat ( "Mass" , str(Cnt,0,0) , "is out of range!n")
 #write ( Expiry , Cnt , "n" )
    //Mass is out of range and should be removed
    // Cnt to a temporary file and shell-out to script to remove
 //from MSIM
  #end
 #local Cnt=Cnt+1;
 #end
#end
#end


// mechsim_expire.pl
#!/usr/bin/perl -w
use strict;

my $expiry = shift @ARGV;
die "mechsim_expire.pl <filename>

Will read a target file and list of indices from <filename> , remove the
listed mass(es) and write MSIM data to STDOUTn";

die "$expiry does not exist " unless -f $expiry;

open ( my $exp , $expiry ) or die $! ;


my $target = <$exp>;
my $destination = <$exp>;
chomp($target,$destination);

open ( my $fh , $target ) or die "Cannot open target MSIM file $!";


my @expired = <$exp>;
chomp (@expired);


my $MSIM = ParseMSIM($fh);

RemoveExpired( @expired , $MSIM );
Output($MSIM);

sub Output {
 my $data = shift;
 print $data->{version};
 print $data->{info};
 print $data->{timing};
 print @{$data->{mass}} if @{$data->{mass}};
 print @{$data->{face}} if @{$data->{face}};
 print @{$data->{connection}} if @{$data->{connection}};
 print @{$data->{viscoelastic}} if @{$data->{viscoelastic}};
}

sub RemoveExpired {
 my $expired = shift;
 my $data = shift;
 ## remove mass elements
 foreach my $dead ( @$expired  ){
 $data->{mass}->[$dead] = undef;
 }
 my @remain = grep { defined } @{$data->{mass}};
 $data->{mass} = @remain;
 warn scalar @remain , " masses remainingn";
 my @info = split ' ' , $data->{info};
 $info[1] -= scalar(@$expired);
 $data->{info} = join (" " , @info) . $/;


}


sub ParseMSIM {
 my $msim = shift;
 my $version = <$msim>;
 my $info = <$msim>;
 my $timing = <$msim>;

 my @mass;
 my @connection;
 my @viscoelastic;
 my @face;

 while (my $line = <$msim>) {
 my $type = substr($line,0,1);
 push @mass , $line if ('M' eq $type);
 push @connection , $line if ('C' eq $type);
 push @viscoelastic , $line if ('V' eq $type );
 push @face , $line if ('F' eq $type);
 }
 my %data;
 @data{qw/version info timing/} = ($version , $info , $timing);
 @data{qw/mass connection viscoelastic face/} = (@mass , @connection,
@viscoelastic, @face);

 return %data;
}


Post a reply to this message

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