OpenBF1942-Plus
Refractor 1, rebuilt from scratch
Loading...
Searching...
No Matches
scene.h
Go to the documentation of this file.
1// Placed objects -> meshes with world transforms. Rules: docs/formats/con.md "Object placement".
2#pragma once
3#include <functional>
4#include <map>
5#include <string>
6#include <vector>
7
8#include "con.h"
9#include "mat.h"
10
11namespace obf {
12
13struct DrawItem {
14 std::string mesh; // VFS path of a .sm or .tm file
16 // AnimatedMesh only: .skn path, skeleton (.ske) and animation state, inherited from the owning templates.
17 std::string skin, skeleton;
18 std::vector<std::string> states; // by setAnimationState index (soldiers: 0 lower body, 1 upper body)
19 std::string lightmap; // static .sm only: <level>/objectlightmaps/<file>_<x>-<y>-<z>.tga, if present
20 std::string owner; // lower-case name of the object template that holds the geometry
21 bool spawned = false; // placed by an ObjectSpawner (a vehicle), not part of the static level
22 int spawn = -1; // index into build_scene's spawn points, if spawned
23 std::string bone; // skeleton bone it follows: bindToSkeletonPart / useSkeletonPartAsMain (hand weapons)
24};
25
26// What an ObjectSpawner places (the template its team would get) and where.
27struct SpawnPoint {
28 std::string name;
30 int team = 0; // teamOnVehicle 1: the spawner's team (setTeam) owns what it places, its spawn points included
31};
32
33// skipped counts what could not be drawn, by reason ("treemesh", "missing template", ...).
34// hide: child templates to leave out (lower-case name), e.g. first-person soldier parts.
35// spawns: if given, receives every ObjectSpawner's placement (DrawItem::spawn indexes it).
36std::vector<DrawItem> build_scene(const Con& con, const Vfs& vfs, std::map<std::string, int>& skipped,
37 const std::function<bool(const std::string&)>& hide = nullptr,
38 std::vector<SpawnPoint>* spawns = nullptr);
39
40// Extra local transform of a template node (a moving part), by lower-case template name and the how-many-th visit of
41// that name in pre-order (0 for the first). Applied after the node's setPosition / setRotation, so children follow.
42using JointFn = std::function<Mat4(const std::string& name, int occurrence)>;
43// One template tree (e.g. a vehicle) placed at world, without a level instance. ObjectSpawners inside it (a
44// destroyer's landing craft) are not followed: what they place is a vehicle of its own.
45std::vector<DrawItem> build_object(const Con& con, const Vfs& vfs, const std::string& name, const Mat4& world,
46 std::map<std::string, int>& skipped, const JointFn& joint = nullptr,
47 const std::function<bool(const std::string&)>& hide = nullptr, bool wreck = false);
48// "x/y/z" -> 3 floats; atof semantics, missing parts are 0.
49void parse_vec3(const std::string& s, float out[3]);
50
51} // namespace obf
Definition con.h:21
Definition vfs.h:11
Definition con.py:1
Definition anim.cpp:7
std::vector< DrawItem > build_object(const Con &con, const Vfs &vfs, const std::string &name, const Mat4 &world, std::map< std::string, int > &skipped, const JointFn &joint, const std::function< bool(const std::string &)> &hide, bool wreck)
Definition scene.cpp:167
std::function< Mat4(const std::string &name, int occurrence)> JointFn
Definition scene.h:42
std::vector< DrawItem > build_scene(const Con &con, const Vfs &vfs, std::map< std::string, int > &skipped, const std::function< bool(const std::string &)> &hide, std::vector< SpawnPoint > *spawns)
Definition scene.cpp:143
void parse_vec3(const std::string &s, float out[3])
Definition scene.cpp:9
Definition scene.h:13
std::string owner
Definition scene.h:20
std::string mesh
Definition scene.h:14
std::string lightmap
Definition scene.h:19
std::string skin
Definition scene.h:17
int spawn
Definition scene.h:22
bool spawned
Definition scene.h:21
Mat4 world
Definition scene.h:15
std::string bone
Definition scene.h:23
std::vector< std::string > states
Definition scene.h:18
std::string skeleton
Definition scene.h:17
Definition mat.h:8
Definition scene.h:27
Mat4 world
Definition scene.h:29
int team
Definition scene.h:30
std::string name
Definition scene.h:28