#! /bin/sh


if [ "$1" = "" ]; then
	set $HOME/.medit.mat $HOME/.medit.lgt
fi

echo "(merge-baseap  appearance {"

for f in $@; do
    if [ ! -f "$f" ]; then
	echo "$0: $f: file not found" >&2
	continue
    fi

    case "$f" in
	*.mat)
	    echo "  material {
	ka 1.0 kd 1.0 ks 1.0"
	    while read kw args ; do
		case "$kw" in
		    ambient|diffuse|specular|shininess) echo "	$kw $args" ;;
		esac
	    done <$f
	    echo "  }"
	    ;;
	*.lgt)
	    echo "  lighting {
	replacelights"
	    first=1
	    while read kw args; do
		case "$kw" in
		    localviewer) echo "	$kw $args" ;;
		    ambient)
			if [ "$first" != "" ]; then
			    echo "	$kw $args"
			    first=
			else
			    echo "	light {"
			    if [ "$args" != "0.000000 0.000000 0.000000" ]; then
				echo "		$kw $args"
			    fi
			fi ;;
		    color)
			echo "		$kw $args" ;;
		    position)
			echo "		$kw $args"
			echo "	}"
			;;
		esac
	    done <$f 
	    echo "  }" ;;
	*)
	    echo "$0: $f: expected *.mat or *.lgt suffix." >&2 ;;
    esac
done

echo "} )"
