更新自研插件
This commit is contained in:
@@ -24,13 +24,11 @@ const BODY_COUNT := 4
|
||||
const SHAPE_NAMES: PackedStringArray = [
|
||||
"convex_hull", "trimesh", "box", "sphere", "capsule", "cylinder",
|
||||
]
|
||||
const BODY_NAMES: PackedStringArray = [
|
||||
"static", "rigid", "area", "character",
|
||||
]
|
||||
const DEFAULT_MODEL_EXTENSIONS: PackedStringArray = [
|
||||
"fbx", "glb", "gltf", "dae", "obj", "blend", "md2", "md3", "vrm",
|
||||
]
|
||||
|
||||
const KEY_ASK := ROOT + "ask_before_adding"
|
||||
const KEY_AUTO := ROOT + "auto_add_collision"
|
||||
|
||||
const KEY_SHAPE := ROOT + "collision_shape"
|
||||
@@ -39,7 +37,6 @@ const KEY_SKIP_EXISTING := ROOT + "skip_meshes_with_collision"
|
||||
const KEY_LAYER := ROOT + "collision_layer"
|
||||
const KEY_MASK := ROOT + "collision_mask"
|
||||
const KEY_EXTENSIONS := ROOT + "model_extensions"
|
||||
const KEY_SKIP_DIRS := ROOT + "skip_dirs"
|
||||
|
||||
## The shape this plugin shipped as its default before 2.0 finalised.
|
||||
##
|
||||
@@ -58,22 +55,25 @@ const LEGACY_SHAPE_DEFAULT := 0 # MeshCollider.ShapeType.CONVEX_HULL
|
||||
## reason applied one level out: they must not depend on another script's enum
|
||||
## resolving. Keep them in step with MeshCollider's enum order.
|
||||
##
|
||||
## Each entry carries two kinds of text, and they are NOT interchangeable:
|
||||
## * `hint_string` - consumed by ProjectSettings / the built-in inspector. An
|
||||
## enum uses it for its option list, so it cannot hold prose.
|
||||
## * `label` / `tooltip` - consumed by this plugin's own settings panel, which
|
||||
## labels each row and shows the tooltip on hover.
|
||||
## `hint_string` is the one piece of text an entry carries, and its meaning
|
||||
## depends on the type: an enum uses it for its option list, an array for its
|
||||
## element type, and a bool for a short description. Only the first two are
|
||||
## visible - Project Settings renders a bool as a bare checkbox labelled 启用 and
|
||||
## has no slot for a per-setting description, so what each setting does is
|
||||
## documented in README.md instead.
|
||||
static func project_info() -> Dictionary:
|
||||
return {
|
||||
KEY_ASK: {
|
||||
"name": KEY_ASK,
|
||||
"type": TYPE_BOOL,
|
||||
"default": true,
|
||||
"hint_string": "Ask before adding collision to a dragged-in model",
|
||||
},
|
||||
KEY_AUTO: {
|
||||
"name": KEY_AUTO,
|
||||
"type": TYPE_BOOL,
|
||||
"default": false,
|
||||
"hint_string": "Add collision to every pending model found by a scan",
|
||||
"label": "扫描后自动添加",
|
||||
"tooltip": "打开后,点『扫描场景中的模型』会直接把找到的模型全部加上碰撞。\n"
|
||||
+ "关闭(默认):扫描只列出结果,由你决定是否处理。\n"
|
||||
+ "插件不做任何后台轮询,只有你点按钮时才扫描。",
|
||||
},
|
||||
KEY_SHAPE: {
|
||||
"name": KEY_SHAPE,
|
||||
@@ -81,10 +81,6 @@ static func project_info() -> Dictionary:
|
||||
"default": 1, # MeshCollider.ShapeType.TRIMESH
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "Convex Hull,Trimesh,Box,Sphere,Capsule,Cylinder",
|
||||
"label": "碰撞形状",
|
||||
"tooltip": "Trimesh:逐三角面精确,零简化。静态物体的最佳选择。\n"
|
||||
+ "Convex Hull:凸包,凹形会被填平,可用于会移动的物体。\n"
|
||||
+ "Box / Sphere / Capsule / Cylinder:单个包围体,最省性能。",
|
||||
},
|
||||
KEY_BODY: {
|
||||
"name": KEY_BODY,
|
||||
@@ -92,37 +88,24 @@ static func project_info() -> Dictionary:
|
||||
"default": 0, # MeshCollider.BodyType.STATIC
|
||||
"hint": PROPERTY_HINT_ENUM,
|
||||
"hint_string": "StaticBody3D,RigidBody3D,Area3D,CharacterBody3D",
|
||||
"label": "刚体类型",
|
||||
"tooltip": "碰撞体挂在哪种物理节点下。\n"
|
||||
+ "StaticBody3D:静态场景物件。\n"
|
||||
+ "RigidBody3D:参与物理模拟的道具。\n"
|
||||
+ "Area3D:只做触发检测,不阻挡。\n"
|
||||
+ "CharacterBody3D:玩家/NPC,移动由脚本接管。",
|
||||
},
|
||||
KEY_SKIP_EXISTING: {
|
||||
"name": KEY_SKIP_EXISTING,
|
||||
"type": TYPE_BOOL,
|
||||
"default": false,
|
||||
"hint_string": "Skip meshes already under a physics body",
|
||||
"label": "跳过已有碰撞的网格",
|
||||
"tooltip": "打开后,已经位于物理体下方的网格不再重复生成碰撞。\n"
|
||||
+ "模型自带碰撞时(例如用 -col 后缀导入)应该打开。",
|
||||
},
|
||||
KEY_LAYER: {
|
||||
"name": KEY_LAYER,
|
||||
"type": TYPE_INT,
|
||||
"default": 1,
|
||||
"hint": PROPERTY_HINT_LAYERS_3D_PHYSICS,
|
||||
"label": "碰撞层",
|
||||
"tooltip": "生成的碰撞体属于哪些层。用掩码表示,1 = 第 1 层。",
|
||||
},
|
||||
KEY_MASK: {
|
||||
"name": KEY_MASK,
|
||||
"type": TYPE_INT,
|
||||
"default": 1,
|
||||
"hint": PROPERTY_HINT_LAYERS_3D_PHYSICS,
|
||||
"label": "碰撞掩码",
|
||||
"tooltip": "生成的碰撞体会和哪些层发生碰撞。用掩码表示。",
|
||||
},
|
||||
KEY_EXTENSIONS: {
|
||||
"name": KEY_EXTENSIONS,
|
||||
@@ -132,17 +115,6 @@ static func project_info() -> Dictionary:
|
||||
]),
|
||||
"hint": PROPERTY_HINT_ARRAY_TYPE,
|
||||
"hint_string": "String",
|
||||
"label": "识别为模型的后缀",
|
||||
"tooltip": "逗号分隔,不带点。只有这些后缀的文件会被当作模型处理。",
|
||||
},
|
||||
KEY_SKIP_DIRS: {
|
||||
"name": KEY_SKIP_DIRS,
|
||||
"type": TYPE_PACKED_STRING_ARRAY,
|
||||
"default": PackedStringArray(["res://addons/", "res://.godot/"]),
|
||||
"hint": PROPERTY_HINT_ARRAY_TYPE,
|
||||
"hint_string": "String",
|
||||
"label": "永不扫描的目录",
|
||||
"tooltip": "逗号分隔。这些目录下的模型不会被自动处理。",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -226,19 +198,6 @@ static func set_value(key: String, value) -> void:
|
||||
ProjectSettings.set_setting(key, value)
|
||||
|
||||
|
||||
## Restore every setting this plugin owns back to its registered default.
|
||||
## Returns the number of settings that actually changed.
|
||||
static func reset_to_defaults() -> int:
|
||||
var all := _all_info()
|
||||
var changed := 0
|
||||
for key in all:
|
||||
var info: Dictionary = all[key]
|
||||
if ProjectSettings.get_setting(key) != info["default"]:
|
||||
ProjectSettings.set_setting(key, info["default"])
|
||||
changed += 1
|
||||
return changed
|
||||
|
||||
|
||||
## The configured shape type, clamped to the valid enum range.
|
||||
##
|
||||
## Returns a plain int rather than `MeshCollider.ShapeType` on purpose; see
|
||||
@@ -266,17 +225,3 @@ static func is_configured_model(path: String) -> bool:
|
||||
if String(e).to_lower().trim_prefix(".") == ext:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
## True when `path` is inside a directory the plugin must never scan.
|
||||
static func should_skip(path: String) -> bool:
|
||||
var p := path.replace("\\", "/")
|
||||
for dir in get_strings(KEY_SKIP_DIRS):
|
||||
var d := String(dir).replace("\\", "/")
|
||||
if d.is_empty():
|
||||
continue
|
||||
if not d.ends_with("/"):
|
||||
d += "/"
|
||||
if p.begins_with(d):
|
||||
return true
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user