Skip to content

Go package for parsing Source Engine StudioModel formats (.mdl, .vtx, .vvd, .phy)

Notifications You must be signed in to change notification settings

Galaco/studiomodel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Go report card GolangCI
codecov CircleCI

studiomodel

Golang library for loading Valve studiomodel formats (.mdl, .vtx, .vvd)

Some parts of a prop are mandatory (mdl,vvd,vtx), others are not (phy). It's up to the implementor to construct a studiomodel the way they want to.

This is a collection of parsers for different formats, it has no concept of the filesystem structure (theoretically different StudioModel components could be located in different folders).

Tested against Counter Strike Source and Counter Strike Global Offensive

Features

  • VVD reader is stable
  • VTX reader is usable, only for single LOD models
  • MDL reader is usable, currently incomplete (some properties not populated)
  • PHY reader is usable, string data table is not supported yet

Usage

package main

import (
	"github.com/galaco/studiomodel"
	"github.com/galaco/studiomodel/mdl"
	"github.com/galaco/studiomodel/phy"
	"github.com/galaco/studiomodel/vtx"
	"github.com/galaco/studiomodel/vvd"
	"log"
	"os"
)


func main() {
	filePath := "foo/prop" //
	
	// create model
	prop := studiomodel.NewStudioModel("models/error")

    // MDL
	f,err := os.Open(filePath + ".mdl") // file.Load just returns (io.Reader,error)
	if err != nil {
		log.Println(err)
		return
	}
	mdlFile,err := mdl.ReadFromStream(f)
	if err != nil {
		log.Println(err)
		return
	}
	prop.AddMdl(mdlFile)

	// VVD
	f,err = os.Open(filePath + ".vvd") // file.Load just returns (io.Reader,error)
	if err != nil {
		log.Println(err)
		return
	}
	vvdFile,err := vvd.ReadFromStream(f)
	if err != nil {
		log.Println(err)
		return
	}
	prop.AddVvd(vvdFile)

	// VTX
	f,err = os.Open(filePath + ".vtx") // file.Load just returns (io.Reader,error)
	if err != nil {
		log.Println(err)
		return
	}
	vtxFile,err := vtx.ReadFromStream(f)
	if err != nil {
		log.Println(err)
		return
	}
	prop.AddVtx(vtxFile)

	// PHY
	f,err = os.Open(filePath + ".phy") // file.Load just returns (io.Reader,error)
	if err != nil {
		log.Println(err)
		return
	}
	phyFile,err := phy.ReadFromStream(f)
	if err != nil {
		log.Println(err)
		return
	}
	prop.AddPhy(phyFile)
	
	log.Println(prop)
}