Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 5 Unity classes + Fix X-mirroring of models #103

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion unitypack/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .movie import MovieTexture
from .object import GameObject
from .particle import EllipsoidParticleEmitter, MeshParticleEmitter, ParticleEmitter, ParticleSystem
from .physics import BoxCollider, BoxCollider2D, Collider, Collider2D, Rigidbody2D
from .physics import BoxCollider, SphereCollider, CapsuleCollider, BoxCollider2D, Collider, Collider2D, MeshCollider, Rigidbody2D
from .renderer import MeshRenderer, ParticleRenderer, ParticleSystemRenderer, Renderer
from .text import TextAsset, TextMesh, Shader
from .texture import Material, Sprite, Texture2D, StreamingInfo
2 changes: 1 addition & 1 deletion unitypack/engine/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class VertexData(Object):


class MeshFilter(Component):
pass
mesh = field("m_Mesh")
17 changes: 17 additions & 0 deletions unitypack/engine/physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ class BoxCollider(Collider):
size = field("m_Size")


class SphereCollider(Collider):
center = field("m_Center")
radius = field("m_Radius")


class CapsuleCollider(SphereCollider):
height = field("m_Height")
direction = field("m_Direction")


class MeshCollider(Collider):
convex = field("m_Convex", bool)
cooking_options = field("m_CookingOptions")
skin_width = field("m_SkinWidth")
mesh = field("m_Mesh")


class Collider2D(Behaviour):
is_trigger = field("m_IsTrigger")
material = field("m_Material")
Expand Down
30 changes: 19 additions & 11 deletions unitypack/engine/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ShadowCastingMode(IntEnum):
ShadowsOnly = 3


class Renderer(Component):
class RendererBase(Component):
enabled = field("m_Enabled", bool)
lightmap_index = field("m_LightmapIndex")
materials = field("m_Materials")
Expand All @@ -28,17 +28,20 @@ class Renderer(Component):
shadow_casting_mode = field("m_CastShadows", ShadowCastingMode)
sorting_layer_id = field("m_SortingLayerID")
sorting_order = field("m_SortingOrder")
use_light_probes = field("m_UseLightProbes", bool)
lightmap_index_dynamic = field("m_LightmapIndexDynamic")
lightmap_tiling_offset = field("m_LightmapTilingOffset")
lightmap_tiling_offset_dynamic = field("m_LightmapTilingOffsetDynamic")
static_batch_root = field("m_StaticBatchRoot")
subset_indices = field("m_SubsetIndices")

@property
def material(self):
return self.materials[0]


class Renderer(RendererBase):
use_light_probes = field("m_UseLightProbes", bool)
subset_indices = field("m_SubsetIndices")


class ParticleSystemRenderMode(IntEnum):
Billboard = 0
Expand All @@ -55,23 +58,29 @@ class ParticleSystemSortMode(IntEnum):
YoungestInFront = 3


class MeshRenderer(Component):
pass
class MeshRenderer(RendererBase):
use_light_probes = field("m_LightProbeUsage", bool) #Note that it's "...Usage", not "Use..."
additional_vertex_streams = field("m_AdditionalVertexStreams")
dynamic_occludee = field("m_DynamicOccludee")
light_probe_volume_override = field("m_LightProbeVolumeOverride")
motion_vectors = field("m_MotionVectors", bool)
sorting_layer = field("m_SortingLayer")
static_batch_info = field("m_StaticBatchInfo")


class ParticleRenderer(Renderer):
class ParticleRendererBase(Renderer):
camera_velocity_scale = field("m_CameraVelocityScale")
length_scale = field("m_LengthScale")
max_particle_size = field("m_MaxParticleSize")
velocity_scale = field("m_VelocityScale")


class ParticleRenderer(ParticleRendererBase):
stretch_particles = field("m_StretchParticles")
uv_animation = field("UV Animation")


class ParticleSystemRenderer(Renderer):
camera_velocity_scale = field("m_CameraVelocityScale")
length_scale = field("m_LengthScale")
max_particle_size = field("m_MaxParticleSize")
class ParticleSystemRenderer(ParticleRendererBase):
mesh = field("m_Mesh")
mesh1 = field("m_Mesh1")
mesh2 = field("m_Mesh2")
Expand All @@ -80,4 +89,3 @@ class ParticleSystemRenderer(Renderer):
render_mode = field("m_RenderMode", ParticleSystemRenderMode)
sort_mode = field("m_SortMode", ParticleSystemSortMode)
sorting_fudge = field("m_SortingFudge")
velocity_scale = field("m_VelocityScale")
4 changes: 2 additions & 2 deletions unitypack/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read(self, buf):
return self

def __str__(self):
return "%s %s %s" % (-self.x, self.y, self.z)
return "%s %s %s" % (self.x, self.y, self.z)


class OBJVector4(OBJVector3):
Expand Down Expand Up @@ -147,7 +147,7 @@ def __init__(self, mesh):
@staticmethod
def face_str(indices, coords, normals):
ret = ["f "]
for i in indices[::-1]:
Copy link
Contributor

@robert-nix robert-nix Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was done to convert from left-handed coordinates to right-handed coordinates, FWIW. So without this the face normals would all be inside out in tools that expect right-handed models.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, um, TBH I thought pull requests would only add the commits from before they were made.
Either way, you are correct, however removing the - on line 31 inverts the models once, so the face normals are as they should.
I know it's a bit counter-intuitive but if you test it, it should be fine.

for i in indices:
ret.append(str(i + 1))
if coords or normals:
ret.append("/")
Expand Down