MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / TestModel

Method TestModel

Examples/StereoKitTest/Docs/DocModel.cs:8–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6 Model testModel;
7
8 bool TestModel()
9 {
10 /// :CodeSample: Model.Model
11 Model model = new Model();
12 model.AddNode("Cube",
13 Matrix .Identity,
14 Mesh .GenerateCube(Vec3.One),
15 Default.Material);
16 /// :End:
17 model.AddNode("Sphere",
18 Matrix .T(0, 1, 0),
19 Mesh .GenerateSphere(1),
20 Default.Material);
21
22 /// :CodeSample: Model Model.Visuals Mesh.VertCount Mesh.IndCount
23 /// ### Counting the Vertices and Triangles in a Model
24 ///
25 /// Model.Visuals are always guaranteed to have a Mesh, so no need to
26 /// null check there, and VertCount and IndCount are available even if
27 /// Mesh.KeepData is false!
28 int vertCount = 0;
29 int triCount = 0;
30
31 foreach (ModelNode node in model.Visuals)
32 {
33 Mesh mesh = node.Mesh;
34 vertCount += mesh.VertCount;
35 triCount += mesh.IndCount / 3;
36 }
37 Log.Info($"Model stats: {vertCount} vertices, {triCount} triangles");
38 /// :End:
39
40 ModelNode lastSubset = model.AddNode("LastSubset",
41 Matrix.T(0, 1, 0),
42 Mesh .GenerateCube(new Vec3(0.5f,1,0.5f)),
43 Default.Material);
44
45 testModel = model;
46
47 // Check that model bounds are as expected
48 Log.Info("Expected bounds: center:<0,0.5,0> dimensions:<1,2,1> Got: {0}", model.Bounds);
49 if (model.Bounds.center.x != 0 ||
50 model.Bounds.center.y != 0.5f ||
51 model.Bounds.center.z != 0 ||
52 model.Bounds.dimensions.x != 1 ||
53 model.Bounds.dimensions.y != 2 ||
54 model.Bounds.dimensions.z != 1)
55 return false;
56
57 /// :CodeSample: ModelNode.Material
58 foreach (ModelNode node in model.Nodes)
59 {
60 // ModelNode.Material will often returned a shared resource, so
61 // copy it if you don't wish to change all assets that share it.
62 Material mat = node.Material.Copy();
63 mat[MatParamName.ColorTint] = Color.HSV(0, 1, 1);
64 node.Material = mat;
65 }

Callers

nothing calls this directly

Calls 7

AddNodeMethod · 0.80
GenerateCubeMethod · 0.80
TMethod · 0.80
GenerateSphereMethod · 0.80
InfoMethod · 0.80
HSVMethod · 0.80
CopyMethod · 0.45

Tested by

no test coverage detected