Showing posts with label 3ds MAX. Show all posts
Showing posts with label 3ds MAX. Show all posts

Wednesday, September 7, 2011

Export script for Treadmill data from 3ds max to PointLightLab model file (Left Viewport Version)

This script exports a 28 point model from 3ds MAX to a PointLightLab model file format ( 2D version for V4 of PLL)



macroScript TM_LeftFacing_Exporter category:"DuncansTools"
(
	-- number of points to export
	num_dummies = 28
	-- array to hold the dummy refs
	dummy_array = #()
	--scaling factor
	scale = 0.3

	output_name = getSaveFileName caption:"PointLightLab Model File" types:"Models (*.pllm)|*.pllm|All Files (*.*)|*.*|"

	if output_name != undefined then 
	(
	
		output_file = createfile output_name
	
		--create the array of dummies
		for dummies = 1 to num_dummies do
		( 
			dummy_array[dummies] = execute ((if dummies < 10 then ("$Dummy0" ) else ("$Dummy")) + dummies as string)
		)

	
		--Write the file header--
		format "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\" ?>\n" to:output_file
		format "<!DOCTYPE DuncansModelFile SYSTEM \"C:\\Program Files\\DuncansTools\\PointLightLab\\configuration\\ModelFormatv4.dtd\">\n" to:output_file
		format "<DuncansModelFile Version=\"4.0\">\n\n" to:output_file
		
		for t = animationrange.start to animationrange.end do
		(
		
			format "<FrameSet>\n" to:output_file
		
			for dummies = 1 to num_dummies do
			( 
			
				at time t obj_1 = dummy_array[dummies].center
			
				format "<FramePoint Xpos=\"" to:output_file
				format "%" (obj_1.y * scale ) to:output_file
				format "\" Ypos=\"" to:output_file
				format "%" (obj_1.z * scale ) to:output_file
				format "\"/>\n" to:output_file
			
			)
			
			format "</FrameSet>\n\n" to:output_file
		)
		
		format "\n</DuncansModelFile>" to:output_file
		
		close output_file
		edit output_name
	
	)--end if

)--end macroScript

Monday, September 5, 2011

Import script for getting Treadmill Mocap data into 3ds MAX

Maxscript importer for .t3d files generated from PhaseSpace motion capture system using the a full suit and cap with 28 LED's. The .t3d files are generated from C3DWorkbench as simple tab delimited text files with X Y Z data on each line.  The number of points needs to be known before hand and set in the "num_dummies" var.  I was importing 5 second blocks of motion at 30 frames a second, hence the hard wired number of frames in "num_frames" var.

This script generates an array of dummy objects to hold the motion data as a point cloud style data set.  Each point's data is mapped as a keyframe on the dummy except where the point has dropped out or "popped" (if you use EEG nomenclature....) These are filtered out during the import to make it easier to fix the data in the curve editor.  Be careful of frame 0, as it does not seem to filter correctly. (Will figure this out later)


macroscript TM_Importer category: "DuncansTools"
(
	num_dummies = 28
	num_frames = 151
	dummy_array = #()
	
	animationRange = interval 0 num_frames
	
	--create the array of dummies
	for d = 1 to num_dummies do
	(
		dummy_array[d] = dummy ()
		dummy_array[d].boxsize = [1,1,1]
	)
	
	--local x = dummy_array[1].pos.controller	
	--showProperties x

	--get the text file ( tab delimeted works. from excel )
	in_name = getOpenFileName types:"Text  3d (*.t3d|*.t3d|All (*.*)|*.*|"
	if in_name != undefined then
	(
		in_file = openFile in_name
		if in_file != undefined then
		(
			-- turn on animation so we can automatically create keys 
			with animate on
			(
				for frames = 0 to num_frames - 1 do
				(
					for dummies = 1 to num_dummies do
					( 
						-- read the pairs of values from the file
						x_val = readValue in_file
						y_val = readValue in_file
						z_val = readValue in_file
						
						
					-- put the values to the dummies as motion keys
						
						if x_val < 0.5 or x_val > 0.5 then
						(
							at time frames dummy_array[dummies].pos.controller.x_position = x_val
						)
						
						if y_val < 0.5 or y_val > 0.5 then
						(
							at time frames dummy_array[dummies].pos.controller.y_position = y_val
						)
						
						if z_val < 0.5 or z_val > 0.5 then 
						(
							at time frames dummy_array[dummies].pos.controller.z_position = z_val
						)
					)
				)
			)
		)
		close in_file
	)
)