2019-11-11 10:03:52 +00:00
|
|
|
""" Contains Scene object for representing a .msh file and the function to create one
|
|
|
|
from a Blender scene. """
|
|
|
|
|
|
|
|
from dataclasses import dataclass, field
|
2019-11-15 03:28:09 +00:00
|
|
|
from typing import List, Dict
|
2019-11-11 10:03:52 +00:00
|
|
|
from copy import copy
|
2022-01-18 20:16:49 +00:00
|
|
|
|
2019-11-11 10:03:52 +00:00
|
|
|
import bpy
|
|
|
|
from mathutils import Vector
|
2022-01-18 20:16:49 +00:00
|
|
|
|
2020-12-06 09:11:12 +00:00
|
|
|
from .msh_model import Model, Animation, ModelType
|
2019-11-15 03:28:09 +00:00
|
|
|
from .msh_material import *
|
2019-11-11 10:03:52 +00:00
|
|
|
from .msh_utilities import *
|
2022-01-18 20:16:49 +00:00
|
|
|
|
2019-11-11 10:03:52 +00:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class SceneAABB:
|
|
|
|
""" Class representing an axis-aligned bounding box. """
|
|
|
|
|
|
|
|
AABB_INIT_MAX = -3.402823466e+38
|
|
|
|
AABB_INIT_MIN = 3.402823466e+38
|
|
|
|
|
|
|
|
max_: Vector = Vector((AABB_INIT_MAX, AABB_INIT_MAX, AABB_INIT_MAX))
|
|
|
|
min_: Vector = Vector((AABB_INIT_MIN, AABB_INIT_MIN, AABB_INIT_MIN))
|
|
|
|
|
|
|
|
def integrate_aabb(self, other):
|
|
|
|
""" Merge another AABB with this AABB. """
|
|
|
|
|
|
|
|
self.max_ = max_vec(self.max_, other.max_)
|
|
|
|
self.min_ = min_vec(self.min_, other.min_)
|
|
|
|
|
|
|
|
def integrate_position(self, position):
|
|
|
|
""" Integrate a position with the AABB, potentially expanding it. """
|
|
|
|
|
|
|
|
self.max_ = max_vec(self.max_, position)
|
|
|
|
self.min_ = min_vec(self.min_, position)
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Scene:
|
|
|
|
""" Class containing the scene data for a .msh """
|
|
|
|
name: str = "Scene"
|
2019-11-15 03:28:09 +00:00
|
|
|
materials: Dict[str, Material] = field(default_factory=dict)
|
2019-11-11 10:03:52 +00:00
|
|
|
models: List[Model] = field(default_factory=list)
|
|
|
|
|
2020-11-30 01:10:16 +00:00
|
|
|
animation: Animation = None
|
2019-11-11 10:03:52 +00:00
|
|
|
|
2022-01-18 20:16:49 +00:00
|
|
|
skeleton: List[int] = field(default_factory=list)
|