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

Prototype: SharedMesh export #197

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
51 changes: 32 additions & 19 deletions korman/exporter/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ def finalize(self):
dspan.composeGeometry(True, True)
inc_progress()

def _is_shared_mesh(self, bo):
cm = bo.plasma_modifiers.clothing_mesh
return cm.enabled

def _export_geometry(self, bo, mesh, materials, geospans):
# Recall that materials is a mapping of exported materials to blender material indices.
# Therefore, geodata maps blender material indices to working geometry data.
Expand Down Expand Up @@ -491,7 +495,7 @@ def export_object(self, bo):
drawables = self._export_mesh(bo)

# Create the DrawInterface
if drawables:
if drawables and not self._is_shared_mesh(bo):
diface = self._mgr.find_create_object(plDrawInterface, bl=bo)
for dspan_key, idx in drawables:
diface.addDrawable(dspan_key, idx)
Expand All @@ -517,24 +521,33 @@ def _export_mesh(self, bo):
# Step 2: Export Blender mesh data to Plasma GeometrySpans
self._export_geometry(bo, mesh, materials, geospans)

# Step 3: Add plGeometrySpans to the appropriate DSpan and create indices
_diindices = {}
for geospan, pass_index in geospans:
dspan = self._find_create_dspan(bo, geospan.material.object, pass_index)
self._report.msg("Exported hsGMaterial '{}' geometry into '{}'",
geospan.material.name, dspan.key.name, indent=1)
idx = dspan.addSourceSpan(geospan)
diidx = _diindices.setdefault(dspan, [])
diidx.append(idx)

# Step 3.1: Harvest Span indices and create the DIIndices
drawables = []
for dspan, indices in _diindices.items():
dii = plDISpanIndex()
dii.indices = indices
idx = dspan.addDIIndex(dii)
drawables.append((dspan.key, idx))
return drawables
if self._is_shared_mesh(bo):
# Step 3: Add plGeometrySpans to a plSharedMesh object
shared = self._mgr.find_create_object(plSharedMesh, bl=bo)
shared.flags |= plSharedMesh.kDontSaveMorphState
for geospan, pass_index in geospans:
geospan.props |= (plGeometrySpan.kRequiresBlending | plGeometrySpan.kPropForceShadow)
shared.addSpan(geospan)
return shared
else:
# Step 3: Add plGeometrySpans to the appropriate DSpan and create indices
_diindices = {}
for geospan, pass_index in geospans:
dspan = self._find_create_dspan(bo, geospan.material.object, pass_index)
self._report.msg("Exported hsGMaterial '{}' geometry into '{}'",
geospan.material.name, dspan.key.name, indent=1)
idx = dspan.addSourceSpan(geospan)
diidx = _diindices.setdefault(dspan, [])
diidx.append(idx)

# Step 3.1: Harvest Span indices and create the DIIndices
drawables = []
for dspan, indices in _diindices.items():
dii = plDISpanIndex()
dii.indices = indices
idx = dspan.addDIIndex(dii)
drawables.append((dspan.key, idx))
return drawables

def _export_material_spans(self, bo, mesh, materials):
"""Exports all Materials and creates plGeometrySpans"""
Expand Down
13 changes: 13 additions & 0 deletions korman/properties/modifiers/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
from ... import idprops


class PlasmaClothingMeshModifier(PlasmaModifierProperties):
pl_id = "clothing_mesh"

bl_category = "Avatar"
bl_label = "Clothing Mesh"
bl_description = "Mesh for a Clothing Item"
bl_icon = "MOD_CLOTH"

def export(self, exporter, bo, so):
# This is handled in the mesh exporter code
pass


class PlasmaLadderModifier(PlasmaModifierProperties):
pl_id = "laddermod"

Expand Down
3 changes: 3 additions & 0 deletions korman/ui/modifiers/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

from ...helpers import find_modifier

def clothing_mesh(modifier, layout, context):
pass

def laddermod(modifier, layout, context):
layout.label(text="Avatar climbs facing negative Y.")

Expand Down