骑砍战团MOD开发(49)-使用ScoEditor编辑sco文件制作游戏场景

一.ScoEditor下载霸王•吕布 / ScoEditor · GitCodehttps://gitcode.net/qq_35829452/scoeditor二.ScoEditor导出文件种类

     mission_objects.json:场景物/出生点/通道等物体

     layer_ground_elevation.pfm:场景terrain/ground地形增量,采用PFM深度图存储

     ai_mesh.obj:AI网格静态模型,由点/线面构成

三.mission_objects.json

     object_type = ['prop', 'entry', 'item', 'unused', 'plant', 'passage']
 
     object = {
         'type': object_type[type], 类型,场景物/出生点/通道
         'id': id, ID.scene_props.py定义ID
         'garbage': '%0#x' % garbage,
         'rotation_matrix': [mtx_a, mtx_b, mtx_c], 旋转矩阵(右手坐标系,ZXY顺序旋转),转化后获得沿XYZ旋转角度
         'pos': pos, 世界坐标系坐标
         'str': str, spr_torch等标识
         'entry_no': entry_no, (若为prop则prop_instance_get_variation_id获取)
         'menu_entry_no': menu_item_no,(若为prop则prop_instance_get_variation_id_2获取)
         'scale': scale, 伸缩变换比例
     }

     <1.旋转角度转化:euler_angle_to_rotation.bat/rotation_to_euler_angle.bat

     将Blender旋转角度调整为ZXY模式,输入rotx,roty,rotz至 euler_angle_to_rotation.py中得到旋转矩阵,拷贝至mission_objects.json.

     <2.blender python脚本实现导出mission_object.json

import bpy
import math
import json
import mathutils
# mission_obj data_format
# object_type = ['prop', 'entry', 'item', 'unused', 'plant', 'passage']
# object = {
#   'type': object_type[type], 类型,场景物/出生点/通道
#   'id': id, ID.scene_props.py定义ID
#   'garbage': '%0#x' % garbage,
#   'rotation_matrix': [mtx_a, mtx_b, mtx_c], 旋转矩阵(右手坐标系,ZXY顺序旋转),转化后获得沿XYZ旋转角度
#   'pos': pos, 世界坐标系坐标
#   'str': str, spr_torch等标识
#   'entry_no': entry_no, (若为prop则prop_instance_get_variation_id获取)
#   'menu_entry_no': menu_item_no,(若为prop则prop_instance_get_variation_id_2获取)
#   'scale': scale, 伸缩变换比例
#}

# 获取当前场景中所有的对象
objects = bpy.context.scene.objects

mission_objects = []
for object in objects:
    mission_obj = {}
    mission_obj['type'] =  object.get('type')
    mission_obj['id'] = object.get('id')
    mission_obj['garbage'] = object.get('garbage')
    rotation_euler_XYZ = object.rotation_euler.copy()
    rotation_euler_XYZ[0] = rotation_euler_XYZ[0] * -1
    rotation_euler_XYZ[1] = rotation_euler_XYZ[1] * -1
    rotation_euler_XYZ[2] = rotation_euler_XYZ[2] * -1
    rot_matrix = rotation_euler_XYZ.to_matrix()
    mission_obj['rotation_matrix'] = [
     [rot_matrix[0][0], rot_matrix[0][1], rot_matrix[0][2]],
     [rot_matrix[1][0], rot_matrix[1][1], rot_matrix[1][2]],
     [rot_matrix[2][0], rot_matrix[2][1], rot_matrix[2][2]],
    ]
    mission_obj['pos'] = [object.location.x, object.location.y, object.location.z]
    mission_obj['str'] = object.get('str')
    mission_obj['entry_no'] = object.get('entry_no')
    mission_obj['menu_entry_no'] = object.get('menu_entry_no')
    mission_obj['scale'] = [object.scale.x, object.scale.y, object.scale.z]
    mission_objects.append(mission_obj)
    
mission_objects_json = json.dumps(mission_objects, indent=4)
 
# 打开文件进行写入,如果文件不存在则创建
with open('F:\mission_objects.json', 'w', encoding='utf-8') as file:
    file.write(mission_objects_json)  # 将字符串写入文件

     <3.blender python脚本实现导入mission_object.json

import bpy
import math
import json
import mathutils
# mission_obj data_format
# object_type = ['prop', 'entry', 'item', 'unused', 'plant', 'passage']
# object = {
#   'type': object_type[type], 类型,场景物/出生点/通道
#   'id': id, ID.scene_props.py定义ID
#   'garbage': '%0#x' % garbage,
#   'rotation_matrix': [mtx_a, mtx_b, mtx_c], 旋转矩阵(右手坐标系,ZXY顺序旋转),转化后获得沿XYZ旋转角度
#   'pos': pos, 世界坐标系坐标
#   'str': str, spr_torch等标识
#   'entry_no': entry_no, (若为prop则prop_instance_get_variation_id获取)
#   'menu_entry_no': menu_item_no,(若为prop则prop_instance_get_variation_id_2获取)
#   'scale': scale, 伸缩变换比例
#}

# 获取当前场景中所有的对象
objects = bpy.context.scene.objects

def get_object_by_mission_object(mission_object):
    spr_name = mission_object["str"]
    type = mission_object["type"]
    if type == 'entry':
        return objects["lol_entry_point"]
    elif type == 'prop':
        for object in objects:
            if ('spr_' + object.name) == spr_name:
                return object
    
def handle_mission_object(mission_object_index, mission_object):
    object = get_object_by_mission_object(mission_object)
    new_obj = object.copy()
    new_obj.data = object.data.copy()
    new_obj.data.materials[0] = object.data.materials[0].copy()
    new_obj.rotation_euler = object.rotation_euler.copy()
    new_obj.location = object.location.copy()
    new_obj.scale = object.scale.copy()
    
    new_obj.name = object.name + '_' + str(mission_object_index)
    
    #set mission_object pos rotation and scale
    new_obj.location.x = mission_object["pos"][0]
    new_obj.location.y = mission_object["pos"][1]
    new_obj.location.z = mission_object["pos"][2]
    
    
    new_obj.scale.x = mission_object["scale"][0]
    new_obj.scale.y = mission_object["scale"][1]
    new_obj.scale.z = mission_object["scale"][2]
    
    
    rotation_matrix = mathutils.Matrix(mission_object["rotation_matrix"])
    new_obj.rotation_euler = rotation_matrix.to_euler()
    new_obj.rotation_euler[0] = new_obj.rotation_euler[0] * (-1)
    new_obj.rotation_euler[1] = new_obj.rotation_euler[1] * (-1)
    new_obj.rotation_euler[2] = new_obj.rotation_euler[2] * (-1)
    
    #set mission_object prop
    new_obj["id"] = mission_object["id"]
    new_obj["type"] = mission_object["type"]
    new_obj["garbage"] = mission_object["garbage"]
    new_obj["str"] = mission_object["str"]
    new_obj["entry_no"] = mission_object["entry_no"]
    new_obj["menu_entry_no"] = mission_object["menu_entry_no"]
    bpy.context.collection.objects.link(new_obj)

with open('F:/mission_objects.json', "r") as file:
    mission_objects_json_str = file.read()
    print(mission_objects_json_str)

mission_objects = json.loads(mission_objects_json_str)

for mission_object_index, mission_object in enumerate(mission_objects):
    handle_mission_object(mission_object_index, mission_object)
        

四.ai_mesh.obj

五.layer_ground_elevation.pfm

六.解包sco文件

    将拷贝sco文件至工具目录,运行unpack.bat进行解包.

七.封包sco文件

    修改解包文件夹下的文件,运行repack.bat重新打包生成sco文件.

上一篇:银行监管报送系统介绍(一):支付结算合规监管数据接口规范-填写规则


下一篇:Elasticsearch:让你的 Elasticsearch 索引与 Python 和 Google Cloud Platform 功能保持同步