Obj2pbt Documentation 9 3 21
Obj2pbt Documentation 9 3 21
Contents
1 Introduction .................................................................................................................................. 2
1.1 Project Overview .................................................................................................................. 2
1.2 Project Contributors .............................................................................................................. 2
2 Requirements ............................................................................................................................... 3
2.1 User Requirements ................................................................................................................ 3
2.1.1 Software requirements ................................................................................................... 3
2.1.2 How to use the program ................................................................................................. 3
2.2 Project Functional Requirements .......................................................................................... 3
3 Code documentation .................................................................................................................... 4
4 Methodology .............................................................................................................................. 11
4.1 Overview ............................................................................................................................. 11
4.2 Splitting one triangle into two right triangles ..................................................................... 11
4.3 Calculating position, scale, and rotation ............................................................................. 13
4.3.1 Position ........................................................................................................................ 13
4.3.2 Scale ............................................................................................................................. 14
4.3.3 Rotation ........................................................................................................................ 14
4.4 Position, scale, and rotation to .pbt ..................................................................................... 15
5 Testing........................................................................................................................................ 16
5.1 Overview ............................................................................................................................. 16
5.2 Testing Methodology .......................................................................................................... 16
5.2.1 Example 1 .................................................................................................................... 16
5.3 Position ............................................................................................................................... 17
5.4 Scale .................................................................................................................................... 17
5.5 Rotation ............................................................................................................................... 18
5.6 .obj to .pbt ........................................................................................................................... 19
1 Introduction
1.1 Project Overview
Manticore Games created Core as a platform for users to create and publish minigames utilizing
assets provided by the game’s engine; thus, many Core minigames look inherently similar due to
the limited roster of assets available to creators.
This project is an attempt to work around this limit, resulting in a program that converts .obj
models — exported from software like Cinema4D or Blender — into .pbt files capable of being
understood by Core’s game engine.
2 Requirements
2.1 User Requirements
- When the user opens the program and selects a .obj file, the program will convert the .obj
into an equivalent .pbt file
4
3 Code documentation
The program was written entirely in python and was then compiled into an executable file using
the pyinstaller library.
position
rotation
scale
parent_id
mesh_id
id
Represents an object
name
position
The position of the object in 3D space. For right triangles, this is the point where the right
angle occurs
Type
list[ float, float, float ]
rotation
The rotation of the object in 3D. The three xyz-Euler angles required to rotate the object
Type
list[ float, float, float ]
scale
The scale of the object in 3D. For wedges, this is thickness, length, and width of the
object
Type
5
parent_id
mesh_id
id
generate_pbt_part()
Generates a string that can be inserted into a .pbt file to add the object
Parameters
None
Return Type
str
class Folder(root)
Attributes Methods
id def add_child
children def children_to_string
root def generate_pbt_part
id
children
6
root
Parameters
Return Type
Object
child_to_string()
Generates a string of the Folder’s children to be inserted into the .pbt file. This function
is used in generate_pbt_part()
Parameters
None
Return Type
str
generate_pbt_part()
Generates a string that can be inserted into a .pbt file to add the folder. This is done by
iterating through all Objects in self.children and adding their data into a string
Parameters
None
7
Return Type
str
class PBT(name)
Attributes Methods
template_name def get_mesh_id_for_name
template_id def add_folder
root_id def children_to_string
objects def all_objects_pbt
meshes_by_id def object_assets_pbt
def generate_pbt
template_name
The name of the template. This is set by the name parameter during initialization
Type
str
template_id
root_id
objects
meshes_by_id
get_mesh_id_for_name(mesh_name)
8
Parameters
Return Type
int
add_folder()
Generates a new Folder with self as the root parameter of Folder(root), and adds it to
self.objects. Returns the new Folder
Parameters
None
Return Type
Folder
children_to_string()
Generates a string of all the Folder’s ids in self.objects to be inserted into the .pbt file.
This function is used in generate_pbt()
Parameters
None
Return Type
str
all_objects_pbt()
Generates a string of all Folder’s pbt parts in self.objects. This is done by iterating
through all Folders in self.objects and adding their data into a string. This function is
used in generate_pbt()
Parameters
None
Return Type
str
objects_assets_pbt()
9
Parameters
None
Return Type
str
generate_pbt()
Parameters
None
Return Type
str
def generate_id()
Generates a random and unique id and returns the id
Parameters
None
Return Type
int
def triangle(a, b, c)
Takes in three points representing a triangle in 3D space and returns the position, scale,
rotation of the two right triangles that split the given triangle. The methodology for this is
detailed in section 4.2 and 4.3. The order of returned values is as follows:
- Position of triangle0
- Position of triangle1
- Scale of triangle0
- Scale of triangle1
- Rotation of triangle0
- Rotation of triangle1
Parameters
a (list[ float, float, float ]) - a point on a triangle
10
Return Type
Tuple( list[ float, float, float ], list[ float, float, float ],
list[ float, float, float ], list[ float, float, float ],
list[ float, float, float ], list[ float, float, float ])
def run(path)
Takes a file path to an .obj file as input, converts it into a .pbt file, and writes the .pbt file
into the directory that the .obj file belongs to.
Parameters
Return Type
None
11
4 Methodology
4.1 Overview
3D models in triangulated .obj files are defined by polygons split into triangles. Core does not
have support for arbitrary triangles defined by point triplets; it does, however, support placement
of 3D wedges. By setting the wedge’s thickness to 0.002, we can essentially create 3D right
triangular planes.
By extracting the triangle information from an .obj file, splitting each triangle into two right
triangles, converting the point triplets into wedges defined by vectors with thickness 0.002, and
placing that data into a .pbt file, we convert the .obj model into an equivalent .pbt model.
̅̅̅ and 𝑎𝑐
We imagine sides 𝑎𝑏 ⃗⃗⃗⃗ and 𝑎𝑏
̅̅̅ as vectors 𝑎𝑏 ⃗⃗⃗⃗ :
12
Define a new vector ⃗⃗𝑙1, which is the vector projection of 𝑎𝑐 ⃗⃗⃗⃗ onto vector ⃗⃗⃗⃗
𝑎𝑏 (denoted by
proj𝑎𝑏
⃗⃗⃗⃗⃗ ⃗⃗⃗⃗
𝑎𝑐 ). This can be calculated by:
⃗⃗⃗⃗ ∙ ⃗⃗⃗⃗
𝑎𝑐 𝑎𝑏
proj⃗⃗⃗⃗⃗ ⃗⃗⃗⃗
𝑎𝑐 or 𝑙1 = ⃗⃗⃗⃗
𝑎𝑏
𝑎𝑏 ⃗⃗⃗⃗ ⃗⃗⃗⃗
𝑎𝑏 ∙ 𝑎𝑏
⃗⃗⃗⃗ onto 𝑎𝑐
Define another new vector, 𝑝, which is the vector rejection of 𝑎𝑏 ⃗⃗⃗⃗ . This can be calculated
by:
𝑝 = ⃗⃗⃗⃗
𝑎𝑏 − ⃗⃗𝑙1
13
𝑎𝑐 ∙ ⃗⃗⃗⃗
⃗⃗⃗⃗ 𝑎𝑏
⃗⃗⃗
𝑙2 = (1 − ⃗⃗⃗⃗
) 𝑎𝑏
⃗⃗⃗⃗
𝑎𝑏 ∙ ⃗⃗⃗⃗
𝑎𝑏
Using these vectors, we can define two triangles, which we call triangle0 and triangle1.
4.3.1 Position
14
The position of a wedge in Core is the point where the right angle occurs. Notice that this point is
⃗⃗⃗⃗ that ⃗⃗𝑙1 and ⃗⃗⃗
the same for both triangle0 and triangle1. Position in our model is the point on 𝑎𝑏 𝑙2
point towards, and from which 𝑝 originates.
4.3.2 Scale
The scale of a wedge in Core is a list of three variables: thickness, length, and width.
- The thickness of our wedges is 0.002, which is the smallest acceptable thickness. This is
so our wedges appear as triangles.
- The width of our wedges is a shared side and is therefore the same for both triangle0 and
triangle1. This is calculated by:
o Width of triangle0/triangle1 = ‖𝑝‖
4.3.3 Rotation
The rotation of a wedge in Core is defined by the xyz-Euler angles required to rotate the wedge.
To calculate rotation, we first need to define the 3x3 rotation matrices for triangle0 and triangle1,
which we will call matrix0 and matrix1 respectively.
̂
−𝑝̂ × 𝑎𝑏
- matrix0= [ 𝑝̂ ]
−𝑎𝑏̂
̂
−(−𝑝̂ × 𝑎𝑏)
- matrix1 = [ 𝑝̂ ]
̂
𝑎𝑏
Where:
15
𝑝
- 𝑝̂ is the unit vector of 𝑝, i.e. 𝑝̂ = ‖𝑝‖
⃗⃗⃗⃗⃗
- ̂ is the unit vector of ⃗⃗⃗⃗
𝑎𝑏 ̂ = 𝑎𝑏
𝑎𝑏, i.e. 𝑎𝑏 ⃗⃗⃗⃗⃗ ‖
‖𝑎𝑏
Rotation for our program is then calculated through the following scipy function:
- Rotation of triangle0 =
scipy.spatial.transform.Rotation.from_matrix(matrix0).as_Euler('xyz',
degrees=True) * [-1, -1, 1]
- Rotation of triangle1=
scipy.spatial.transform.Rotation.from_matrix(matrix1).as_Euler('xyz',
degrees=True) * [-1, -1, 1]
5 Testing
5.1 Overview
Because this project is very informal, testing documentation is not detailed, formalized, or even
required. Most tests are either kept secret or deleted after they have served their purpose.
5.2.1 Example 1
First, we draw triangle △ 𝑎𝑏𝑐 in Core with the following three points:
{
"a": [-9.42809009552002, -1.92450094223022, -2.72165536880493],
"b": [-8.52802848815918, 1.74077653884888, -4.92365980148315],
"c": [-8.57492923736572, -1.40028011798859, -4.95073795318604]
}
{
"triangle_1": {
"position": {
"x": -9.070,
"y": -0.466,
"z": -3.598
},
"rotation": {
"x": -114.189,
"y": 30.261,
"z": -103.797
},
"scale": {
"x": 0.026,
"y": 0.017,
"z": 0.000
}
},
"triangle_2": {
"position": {
"x": -9.070,
"y": -0.466,
17
"z": -3.598
},
"rotation": {
"x": 125.080,
"y": 51.990,
"z": 117.915
},
"scale": {
"x": 0.017,
"y": 0.017,
"z": 0.000
}
}
}
We can now test this known-good data against the data that our program outputs.
5.3 Position
The position of a wedge in Core is the point where the right angle occurs. We can test this
calculation with the example detailed in 5.2.1
When we ran the program with the test data above, the program output the following positions:
"triangle_1": {
"position": {
"x": -9.070,
"y": -0.466,
"z": -3.598
},
…
},
"triangle_2": {
"position": {
"x": -9.070,
"y": -0.466,
"z": -3.598
},
…
}
5.4 Scale
The scale of a wedge in Core is a list of three variables: thickness, length, and width. We can test
this calculation with the example detailed in 5.2.1
When we ran the program with the test data above, the program output the following scales:
18
"triangle_1": {
…
"scale": {
"x": 0.026,
"y": 0.017,
"z": 0.000
}
},
"triangle_2": {
…
"scale": {
"x": 0.017,
"y": 0.017,
"z": 0.000
}
}
5.5 Rotation
The rotation of a wedge in Core is the xyz-Euler angles required to rotate the wedge. We can test
this calculation with the example detailed in 5.2.1
When we ran the program with the test data above, the program output the following rotations:
"triangle_1": {
…
"rotation": {
"x": -114.189,
"y": 30.261,
"z": -103.797
},
…
},
"triangle_2": {
…
"rotation": {
"x": 125.080,
"y": 51.990,
"z": 117.915
},
…
}
This test fully converts a .obj file to .pbt. To test this, we will download a .obj model and fully
converted it to a .pbt model with the program. We then put this model into Core and see if the
converted model looks correct.
After converting the model from .obj format into a .pbt file, we inserted it into Core Create and
saw the following results:
Models within .obj files may be split into groups to allow separate coloration as seen below: