|
|
@ -13,10 +13,12 @@ |
|
|
|
# You should have received a copy of the GNU General Public License |
|
|
|
# You should have received a copy of the GNU General Public License |
|
|
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import bpy |
|
|
|
import mathutils |
|
|
|
import mathutils |
|
|
|
from PyHSPlasma import * |
|
|
|
from PyHSPlasma import * |
|
|
|
import weakref |
|
|
|
import weakref |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ..helpers import TemporaryObject |
|
|
|
from . import utils |
|
|
|
from . import utils |
|
|
|
|
|
|
|
|
|
|
|
class PhysicsConverter: |
|
|
|
class PhysicsConverter: |
|
|
@ -24,35 +26,44 @@ class PhysicsConverter: |
|
|
|
self._exporter = weakref.ref(exporter) |
|
|
|
self._exporter = weakref.ref(exporter) |
|
|
|
|
|
|
|
|
|
|
|
def _convert_mesh_data(self, bo, physical, indices=True): |
|
|
|
def _convert_mesh_data(self, bo, physical, indices=True): |
|
|
|
mesh = bo.data |
|
|
|
mesh = bo.to_mesh(bpy.context.scene, True, "RENDER") |
|
|
|
mesh.update(calc_tessface=indices) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Yes, we have to have transform data here, even if we have a CoordInterface |
|
|
|
|
|
|
|
mat = bo.matrix_world |
|
|
|
mat = bo.matrix_world |
|
|
|
physical.rot = utils.quaternion(mat.to_quaternion()) |
|
|
|
|
|
|
|
physical.pos = utils.vector3(mat.to_translation()) |
|
|
|
with TemporaryObject(mesh, bpy.data.meshes.remove) as mesh: |
|
|
|
|
|
|
|
# We can only use the plPhysical xforms if there is a CI... |
|
|
|
# Physicals can't have scale... |
|
|
|
if self._mgr.has_coordiface(bo): |
|
|
|
scale = mat.to_scale() |
|
|
|
mesh.update(calc_tessface=indices) |
|
|
|
if scale[0] == 1.0 and scale[1] == 1.0 and scale[2] == 1.0: |
|
|
|
physical.pos = utils.vector3(mat.to_translation()) |
|
|
|
# Whew, don't need to do any math! |
|
|
|
quat = mat.to_quaternion() |
|
|
|
vertices = [hsVector3(i.co.x, i.co.y, i.co.z) for i in mesh.vertices] |
|
|
|
quat.normalize() |
|
|
|
else: |
|
|
|
physical.rot = utils.quaternion(quat) |
|
|
|
# Dagnabbit... |
|
|
|
|
|
|
|
vertices = [hsVector3(i.co.x * scale.x, i.co.y * scale.y, i.co.z * scale.z) for i in mesh.vertices] |
|
|
|
# Physicals can't have scale... |
|
|
|
|
|
|
|
scale = mat.to_scale() |
|
|
|
if indices: |
|
|
|
if scale[0] == 1.0 and scale[1] == 1.0 and scale[2] == 1.0: |
|
|
|
indices = [] |
|
|
|
# Whew, don't need to do any math! |
|
|
|
for face in mesh.tessfaces: |
|
|
|
vertices = [hsVector3(i.co.x, i.co.y, i.co.z) for i in mesh.vertices] |
|
|
|
v = face.vertices |
|
|
|
else: |
|
|
|
if len(v) == 3: |
|
|
|
# Dagnabbit... |
|
|
|
indices += v |
|
|
|
vertices = [hsVector3(i.co.x * scale.x, i.co.y * scale.y, i.co.z * scale.z) for i in mesh.vertices] |
|
|
|
elif len(v) == 4: |
|
|
|
else: |
|
|
|
indices += (v[0], v[1], v[2],) |
|
|
|
# apply the transform to the physical itself |
|
|
|
indices += (v[0], v[2], v[3],) |
|
|
|
mesh.transform(mat) |
|
|
|
return (vertices, indices) |
|
|
|
mesh.update(calc_tessface=indices) |
|
|
|
else: |
|
|
|
vertices = [hsVector3(i.co.x, i.co.y, i.co.z) for i in mesh.vertices] |
|
|
|
return vertices |
|
|
|
|
|
|
|
|
|
|
|
if indices: |
|
|
|
|
|
|
|
indices = [] |
|
|
|
|
|
|
|
for face in mesh.tessfaces: |
|
|
|
|
|
|
|
v = face.vertices |
|
|
|
|
|
|
|
if len(v) == 3: |
|
|
|
|
|
|
|
indices += v |
|
|
|
|
|
|
|
elif len(v) == 4: |
|
|
|
|
|
|
|
indices += (v[0], v[1], v[2],) |
|
|
|
|
|
|
|
indices += (v[0], v[2], v[3],) |
|
|
|
|
|
|
|
return (vertices, indices) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
return vertices |
|
|
|
|
|
|
|
|
|
|
|
def generate_physical(self, bo, so, name=None): |
|
|
|
def generate_physical(self, bo, so, name=None): |
|
|
|
"""Generates a physical object for the given object pair""" |
|
|
|
"""Generates a physical object for the given object pair""" |
|
|
|