Class: Quake::Mdl::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/mdl/reader.rb

Overview

Parses Quake MDL (alias model) files. Binary format: 76-byte header, skins, texcoords, triangles, frames. Vertices are stored as 3 compressed bytes decompressed via scale/origin.

Constant Summary collapse

IDPOLYHEADER =

"IDPO" in little-endian

0x4F504449
MDL_VERSION =
6
MAX_LBM_HEIGHT =
480
MAXALIASVERTS =
2000
ALIAS_BASE_SIZE_RATIO =
1.0 / 11.0

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Reader

Returns a new instance of Reader.



15
16
17
18
# File 'lib/quake/mdl/reader.rb', line 15

def initialize(data)
  @data = data
  @pos = 0
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/quake/mdl/reader.rb', line 20

def parse
  header = read_header
  validate_header!(header)
  skins, skin_intervals = read_skins(header)
  stverts = read_stverts(header[:numverts])
  triangles = read_triangles(header[:numtris])
  frames = read_frames(header[:numframes], header[:numverts])

  Model.new(
    scale: header[:scale],
    scale_origin: header[:scale_origin],
    bounding_radius: header[:boundingradius],
    eye_position: header[:eyeposition],
    skin_width: header[:skinwidth],
    skin_height: header[:skinheight],
    skins: skins,
    skin_intervals: skin_intervals,
    stverts: stverts,
    triangles: triangles,
    frames: frames,
    flags: header[:flags],
    sync_type: header[:synctype],
    size: header[:size] * ALIAS_BASE_SIZE_RATIO,
    mins: Math::Vec3.new(-16.0, -16.0, -16.0),
    maxs: Math::Vec3.new(16.0, 16.0, 16.0)
  )
end