mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-21 13:16:49 +01:00
Now the CharacterSkeleton uses Arrays directly.
This commit is contained in:
parent
fbc1c056a1
commit
08c0c69aa7
@ -129,7 +129,6 @@ animation_player_path = NodePath("armature/AnimationPlayer")
|
|||||||
animation_tree_path = NodePath("AnimationTree")
|
animation_tree_path = NodePath("AnimationTree")
|
||||||
script = ExtResource( 8 )
|
script = ExtResource( 8 )
|
||||||
automatic_build = true
|
automatic_build = true
|
||||||
use_threads = true
|
|
||||||
mesh_instance_path = NodePath("armature/Armature/Skeleton/MeshInstance")
|
mesh_instance_path = NodePath("armature/Armature/Skeleton/MeshInstance")
|
||||||
skeleton_path = NodePath("armature/Armature/Skeleton")
|
skeleton_path = NodePath("armature/Armature/Skeleton")
|
||||||
materials = [ ExtResource( 3 ), ExtResource( 3 ), ExtResource( 7 ) ]
|
materials = [ ExtResource( 3 ), ExtResource( 3 ), ExtResource( 7 ) ]
|
||||||
@ -142,7 +141,7 @@ viss = [ ExtResource( 1 ) ]
|
|||||||
[node name="armature" parent="." instance=ExtResource( 6 )]
|
[node name="armature" parent="." instance=ExtResource( 6 )]
|
||||||
|
|
||||||
[node name="Skeleton" parent="armature/Armature" index="0"]
|
[node name="Skeleton" parent="armature/Armature" index="0"]
|
||||||
transform = Transform( 1, -4.89119e-19, -2.97968e-26, 4.89119e-19, 1, 4.1058e-43, 2.97968e-26, -4.24593e-43, 1, 0, -1.02549e-15, 0 )
|
transform = Transform( 1, 4.03225e-18, -1.60695e-25, -4.03225e-18, 1, 6.68419e-43, 1.60695e-25, -2.10195e-44, 1, 0, -1.7555e-15, 0 )
|
||||||
bones/0/bound_children = [ NodePath("RootAttachment") ]
|
bones/0/bound_children = [ NodePath("RootAttachment") ]
|
||||||
bones/1/bound_children = [ NodePath("RightHipAttachment") ]
|
bones/1/bound_children = [ NodePath("RightHipAttachment") ]
|
||||||
bones/10/bound_children = [ NodePath("BoneAttachment") ]
|
bones/10/bound_children = [ NodePath("BoneAttachment") ]
|
||||||
@ -153,7 +152,7 @@ bones/24/bound_children = [ NodePath("RightHandAttachment") ]
|
|||||||
[node name="MeshInstance" type="MeshInstance" parent="armature/Armature/Skeleton" index="0"]
|
[node name="MeshInstance" type="MeshInstance" parent="armature/Armature/Skeleton" index="0"]
|
||||||
|
|
||||||
[node name="LeftHandAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="1"]
|
[node name="LeftHandAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="1"]
|
||||||
transform = Transform( 0.103158, 0.116365, -0.98781, 0.05663, -0.992148, -0.110935, -0.993045, -0.0444985, -0.108942, 0.230246, 0.767934, -0.00958773 )
|
transform = Transform( 0.10345, 0.112808, -0.988185, 0.0561394, -0.992553, -0.107388, -0.993041, -0.0443706, -0.109018, 0.23159, 0.765436, -0.00915625 )
|
||||||
bone_name = "left_hand"
|
bone_name = "left_hand"
|
||||||
|
|
||||||
[node name="LeftHandAP" type="Spatial" parent="armature/Armature/Skeleton/LeftHandAttachment"]
|
[node name="LeftHandAP" type="Spatial" parent="armature/Armature/Skeleton/LeftHandAttachment"]
|
||||||
@ -161,7 +160,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.04, -0.09 )
|
|||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="RightHandAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="2"]
|
[node name="RightHandAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="2"]
|
||||||
transform = Transform( -0.0411806, -0.0329775, -0.998579, -0.126788, -0.991125, 0.0379445, -0.99109, 0.128176, 0.0366468, -0.231902, 0.769133, -0.00714437 )
|
transform = Transform( -0.0419076, -0.0392233, -0.998316, -0.126366, -0.990898, 0.0442205, -0.991117, 0.128014, 0.0365859, -0.235761, 0.769562, -0.00764265 )
|
||||||
bone_name = "right_hand"
|
bone_name = "right_hand"
|
||||||
|
|
||||||
[node name="RightHandAP" type="Spatial" parent="armature/Armature/Skeleton/RightHandAttachment"]
|
[node name="RightHandAP" type="Spatial" parent="armature/Armature/Skeleton/RightHandAttachment"]
|
||||||
@ -177,7 +176,7 @@ transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 0, 0
|
|||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="NeckAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="4"]
|
[node name="NeckAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="4"]
|
||||||
transform = Transform( 0.999959, -0.0088956, -0.00102705, 0.00894264, 0.997195, 0.0731071, 0.000373855, -0.0731193, 0.997323, 0.00114021, 1.31441, 8.64493e-05 )
|
transform = Transform( 0.999941, -0.0107506, -0.00153485, 0.0108248, 0.997155, 0.0730699, 0.000744998, -0.0730893, 0.997325, 0.00121189, 1.31167, 0.000110133 )
|
||||||
bone_name = "neck"
|
bone_name = "neck"
|
||||||
|
|
||||||
[node name="TorsoAP" type="Spatial" parent="armature/Armature/Skeleton/NeckAttachment"]
|
[node name="TorsoAP" type="Spatial" parent="armature/Armature/Skeleton/NeckAttachment"]
|
||||||
@ -185,7 +184,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.04, -0.09 )
|
|||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="RightHipAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="5"]
|
[node name="RightHipAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="5"]
|
||||||
transform = Transform( 0.999795, 0.020248, 9.60409e-09, -0.020248, 0.999795, 4.71757e-07, -4.99805e-11, -4.71855e-07, 1, 0.00445231, 0.772908, 0 )
|
transform = Transform( 0.999925, 0.0122509, 5.81089e-09, -0.0122509, 0.999925, 4.71819e-07, -3.02633e-11, -4.71855e-07, 1, 0.00762171, 0.770191, 0 )
|
||||||
bone_name = "pelvis"
|
bone_name = "pelvis"
|
||||||
|
|
||||||
[node name="Spatial" type="Spatial" parent="armature/Armature/Skeleton/RightHipAttachment"]
|
[node name="Spatial" type="Spatial" parent="armature/Armature/Skeleton/RightHipAttachment"]
|
||||||
@ -198,7 +197,7 @@ material/0 = null
|
|||||||
material/1 = null
|
material/1 = null
|
||||||
|
|
||||||
[node name="BoneAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="6"]
|
[node name="BoneAttachment" type="BoneAttachment" parent="armature/Armature/Skeleton" index="6"]
|
||||||
transform = Transform( 0.999957, -0.00921895, -0.000246357, 0.00921441, 0.999868, -0.00108139, 0.000256306, 0.00107972, 0.999999, 0.00286966, 1.12684, -0.000116092 )
|
transform = Transform( 0.999938, -0.0111065, -0.000615132, 0.0110965, 0.999825, -0.00111529, 0.000627457, 0.0011097, 0.999999, 0.00329544, 1.1241, -9.80367e-05 )
|
||||||
bone_name = "spine_2"
|
bone_name = "spine_2"
|
||||||
|
|
||||||
[node name="Spatial" type="Spatial" parent="armature/Armature/Skeleton/BoneAttachment"]
|
[node name="Spatial" type="Spatial" parent="armature/Armature/Skeleton/BoneAttachment"]
|
||||||
|
@ -98,7 +98,6 @@ var _textures : Array
|
|||||||
var _texture : Texture
|
var _texture : Texture
|
||||||
|
|
||||||
#var mesh : ArrayMesh = null
|
#var mesh : ArrayMesh = null
|
||||||
var st : SurfaceTool = null
|
|
||||||
|
|
||||||
var _thread_done : bool = false
|
var _thread_done : bool = false
|
||||||
var _thread : Thread = null
|
var _thread : Thread = null
|
||||||
@ -106,7 +105,6 @@ var _thread : Thread = null
|
|||||||
var _editor_built : bool = false
|
var _editor_built : bool = false
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
st = SurfaceTool.new()
|
|
||||||
_texture_packer = TexturePacker.new()
|
_texture_packer = TexturePacker.new()
|
||||||
_texture_packer.texture_flags = 0
|
_texture_packer.texture_flags = 0
|
||||||
# _texture_packer.texture_flags = Texture.FLAG_FILTER
|
# _texture_packer.texture_flags = Texture.FLAG_FILTER
|
||||||
@ -190,11 +188,14 @@ func build_mesh(data) -> void:
|
|||||||
|
|
||||||
meshes.clear()
|
meshes.clear()
|
||||||
|
|
||||||
st.clear()
|
var vertices : PoolVector3Array = PoolVector3Array()
|
||||||
st.set_material(_materials[0])
|
var normals : PoolVector3Array = PoolVector3Array()
|
||||||
st.begin(Mesh.PRIMITIVE_TRIANGLES)
|
var uvs : PoolVector2Array = PoolVector2Array()
|
||||||
var vertex_count : int = 0
|
var colors : PoolColorArray = PoolColorArray()
|
||||||
|
var indices : PoolIntArray = PoolIntArray()
|
||||||
|
var bone_array : PoolIntArray = PoolIntArray()
|
||||||
|
var weights_array : PoolRealArray = PoolRealArray()
|
||||||
|
|
||||||
for skele_point in range(EntityEnums.SKELETON_POINTS_MAX):
|
for skele_point in range(EntityEnums.SKELETON_POINTS_MAX):
|
||||||
var bone_name : String = get_bone_name(skele_point)
|
var bone_name : String = get_bone_name(skele_point)
|
||||||
|
|
||||||
@ -212,18 +213,11 @@ func build_mesh(data) -> void:
|
|||||||
|
|
||||||
var arrays : Array = entry.entry.get_mesh(model_index).array
|
var arrays : Array = entry.entry.get_mesh(model_index).array
|
||||||
|
|
||||||
var vertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX] as PoolVector3Array
|
var cvertices : PoolVector3Array = arrays[ArrayMesh.ARRAY_VERTEX] as PoolVector3Array
|
||||||
var normals : PoolVector3Array = arrays[ArrayMesh.ARRAY_NORMAL] as PoolVector3Array
|
var cnormals : PoolVector3Array = arrays[ArrayMesh.ARRAY_NORMAL] as PoolVector3Array
|
||||||
var uvs : PoolVector2Array = arrays[ArrayMesh.ARRAY_TEX_UV] as PoolVector2Array
|
var cuvs : PoolVector2Array = arrays[ArrayMesh.ARRAY_TEX_UV] as PoolVector2Array
|
||||||
|
var cindices : PoolIntArray = arrays[ArrayMesh.ARRAY_INDEX] as PoolIntArray
|
||||||
var indices : PoolIntArray = arrays[ArrayMesh.ARRAY_INDEX] as PoolIntArray
|
|
||||||
|
|
||||||
var bone_array : PoolIntArray = PoolIntArray()
|
|
||||||
bone_array.append(bone_idx)
|
|
||||||
|
|
||||||
var weights_array : PoolRealArray = PoolRealArray()
|
|
||||||
weights_array.append(1.0)
|
|
||||||
|
|
||||||
var ta : AtlasTexture = _textures[skele_point]
|
var ta : AtlasTexture = _textures[skele_point]
|
||||||
|
|
||||||
var tx : float = 0
|
var tx : float = 0
|
||||||
@ -240,38 +234,55 @@ func build_mesh(data) -> void:
|
|||||||
tw = ta.region.size.x / otw
|
tw = ta.region.size.x / otw
|
||||||
th = ta.region.size.y / oth
|
th = ta.region.size.y / oth
|
||||||
|
|
||||||
|
var orig_vert_size : int = vertices.size()
|
||||||
for i in range(len(vertices)):
|
|
||||||
st.add_normal(bt.basis.xform(normals[i]))
|
|
||||||
|
|
||||||
var uv : Vector2 = uvs[i]
|
vertices.resize(orig_vert_size + cvertices.size())
|
||||||
|
normals.resize(orig_vert_size + cvertices.size())
|
||||||
|
uvs.resize(orig_vert_size + cvertices.size())
|
||||||
|
colors.resize(orig_vert_size+ cvertices.size())
|
||||||
|
bone_array.resize(bone_array.size() + cvertices.size() * 4)
|
||||||
|
weights_array.resize(weights_array.size() + cvertices.size() * 4)
|
||||||
|
|
||||||
|
for i in range(len(cvertices)):
|
||||||
|
normals[orig_vert_size + i] = bt.basis.xform(normals[i])
|
||||||
|
|
||||||
|
var uv : Vector2 = cuvs[i]
|
||||||
|
|
||||||
uv.x = tw * uv.x + tx
|
uv.x = tw * uv.x + tx
|
||||||
uv.y = th * uv.y + ty
|
uv.y = th * uv.y + ty
|
||||||
|
|
||||||
st.add_uv(uv)
|
uvs[orig_vert_size + i] = uv
|
||||||
|
|
||||||
st.add_bones(bone_array)
|
bone_array[(orig_vert_size + i) * 4] = bone_idx
|
||||||
st.add_weights(weights_array)
|
weights_array[(orig_vert_size + i) * 4] = 1
|
||||||
|
for j in range(1, 4):
|
||||||
|
bone_array[(orig_vert_size + i) * 4 + j] = 0
|
||||||
|
weights_array[(orig_vert_size + i) * 4 + j] = 0
|
||||||
|
|
||||||
st.add_color(Color(0.7, 0.7, 0.7))
|
colors[orig_vert_size + i] = Color(0.7, 0.7, 0.7)
|
||||||
st.add_vertex(bt.xform(vertices[i]))
|
vertices[orig_vert_size + i] = bt.xform(cvertices[i])
|
||||||
# st.add_vertex(vertices[i])
|
|
||||||
|
var orig_indices_count = indices.size()
|
||||||
for i in range(len(indices)):
|
indices.resize(indices.size() + cindices.size())
|
||||||
st.add_index(vertex_count + indices[i])
|
for i in range(len(cindices)):
|
||||||
|
indices[orig_indices_count + i] = orig_vert_size + cindices[i]
|
||||||
vertex_count += len(vertices)
|
|
||||||
|
|
||||||
var arr : Array = st.commit_to_arrays()
|
|
||||||
|
|
||||||
|
var arr : Array = Array()
|
||||||
|
arr.resize(Mesh.ARRAY_MAX)
|
||||||
|
arr[Mesh.ARRAY_VERTEX] = vertices
|
||||||
|
arr[Mesh.ARRAY_NORMAL] = normals
|
||||||
|
arr[Mesh.ARRAY_TEX_UV] = uvs
|
||||||
|
arr[Mesh.ARRAY_COLOR] = colors
|
||||||
|
arr[Mesh.ARRAY_INDEX] = indices
|
||||||
|
arr[Mesh.ARRAY_BONES] = bone_array
|
||||||
|
arr[Mesh.ARRAY_WEIGHTS] = weights_array
|
||||||
|
|
||||||
var mesh : ArrayMesh = ArrayMesh.new()
|
var mesh : ArrayMesh = ArrayMesh.new()
|
||||||
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
|
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
|
||||||
mesh.surface_set_material(0, _materials[0])
|
mesh.surface_set_material(0, _materials[0])
|
||||||
meshes.append(mesh)
|
meshes.append(mesh)
|
||||||
|
|
||||||
if use_lod:
|
if use_lod:
|
||||||
|
|
||||||
arr = merge_mesh_array(arr)
|
arr = merge_mesh_array(arr)
|
||||||
var meshl2 : ArrayMesh = ArrayMesh.new()
|
var meshl2 : ArrayMesh = ArrayMesh.new()
|
||||||
meshl2.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
|
meshl2.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
|
||||||
@ -356,9 +367,6 @@ func editor_build(val : bool) -> void:
|
|||||||
if not is_inside_tree():
|
if not is_inside_tree():
|
||||||
return
|
return
|
||||||
|
|
||||||
if st == null:
|
|
||||||
st = SurfaceTool.new()
|
|
||||||
|
|
||||||
skeleton = get_node(skeleton_path) as Skeleton
|
skeleton = get_node(skeleton_path) as Skeleton
|
||||||
mesh_instance = get_node(mesh_instance_path) as MeshInstance
|
mesh_instance = get_node(mesh_instance_path) as MeshInstance
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user