xyzzy lisp

LightWaveシーンファイルの階層構造を解析する

  • ソース

byte-compileしないと遅い

(defun print-hierarchy-sub (lst level objname itemno type)
  (let ((clst (copy-list lst)))
    (dotimes (i (* level 4)) (princ " "))
    (princ (format nil "*~A(~A, ~A)\n" objname type itemno))
    (while clst
      (if (string= (fourth (car clst)) itemno)
	  (print-hierarchy-sub lst (+ level 1) (first (car clst)) (second (car clst)) (third (car clst))))
      (setq clst (cdr clst)))
    ))

(defun print-hierarchy (lst)
  (let ((clst (copy-list lst)))
    (while clst
      (if (string= (fourth (car clst)) "top")
	  (print-hierarchy-sub lst 0 (first (car clst)) (second (car clst)) (third (car clst))))
      (setq clst (cdr clst)))
    ))

(defun scan-hierarchy-lws (fn)
  "lightwaveシーンファイルの階層構造を解析する"
  (interactive "F")
  (with-output-to-temp-buffer ("*lws階層解析結果*")
    (let ((sbuffer (buffer-stream-buffer *standard-output*)))
      (save-excursion
	(with-open-file (in fn :direction :input)
	  (let ((tmp "")(itemno 0)(objlst)(ob)(pflag))
	    (while (setq tmp (read-line in nil))
	      (if (string-match "AddNullObject \\(.+\\)" tmp) ; null object
		  (progn
		    (if pflag (progn (setq objlst (append objlst (list (append ob (list "top")))))))
		    (setq ob (list (match-string 1) (format nil "~X" (+ #x10000000 itemno)) "null"))
		    (incf itemno)
		    (setq pflag t))
		)
	      (if (string-match "ParentItem \\(.+\\)" tmp) ; parent item
		  (progn (setq objlst (append objlst (list (append ob (list (match-string 1))))))
		    (setq pflag nil))
		)
	      (if (string-match "LoadObjectLayer \\w+ \\(.+\\)" tmp) ; object layer
		  (progn
		    (if pflag (progn (setq objlst (append objlst (list (append ob (list "top")))))))
		    (setq ob (list (match-string 1) (format nil "~X" (+ #x10000000 itemno)) "object"))
		    (incf itemno)
		    (setq pflag t))
		)
	      (if (string-match "LightName \\(.+\\)" tmp) ; light
		  (progn
		    (if pflag (progn (setq objlst (append objlst (list (append ob (list "top")))))))
		    (setq ob (list (match-string 1) (format nil "~X" (+ #x10000000 itemno)) "light"))
		    (incf itemno)
		    (setq pflag t))
		))
	    (print-hierarchy objlst)
	    ))))))