-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestore_lib.patch
More file actions
182 lines (182 loc) · 13.4 KB
/
restore_lib.patch
File metadata and controls
182 lines (182 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
--- src/lib.rs
+++ src/lib.rs
@@ -616,6 +616,161 @@
+ Ok(model) => {
+ let meshes = fbx_loader::model_to_all_meshes(&model);
+ for (i, mesh) in meshes.into_iter().enumerate() {
+ let mat = crate::world::Material {
+ color: [entity_data.material.albedo_color[0], entity_data.material.albedo_color[1], entity_data.material.albedo_color[2], 1.0],
+ albedo_texture: entity_data.material.albedo_texture.clone(),
+ roughness: entity_data.material.roughness,
+ metallic: entity_data.material.metallic,
+ };
+
+ let spawn_tuple = (
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ mat,
+ );
+
+ let entity = state.world.ecs.spawn(spawn_tuple);
+
+ // Attach animator if this is the first mesh and config exists
+ if i == 0 {
+ if let Some(anim_config) = &entity_data.animator_config {
+ if let Some(skeleton) = &model.skeleton {
+ let clips = model.animations.iter().map(|a| Arc::new(a.clone())).collect();
+ let mut animator = Animator::new(Arc::new(skeleton.clone()), clips);
+ animator.speed = anim_config.speed;
+ let anim_state = AnimationState::new(skeleton.bones.len());
+ let _ = state.world.ecs.insert(entity, (animator, anim_state));
+ info!("Attached Animator to entity {:?}", entity);
+ }
+ }
+ }
+
+ resource_loader.queue_mesh(entity, mesh);
+ info!("Queued mesh upload for entity {:?} (sub-mesh {})", entity, i);
+ }
+ }
+ Err(e) => error!("Failed to load model {}: {:?}", path, e),
+ }
+ } else {
+ warn!("Asset not found in bundle: {} (looked for {})", path, filename);
+ }
+ }
+ EntityType::Primitive(pt) => {
+ let material = crate::world::Material {
+ color: [entity_data.material.albedo_color[0], entity_data.material.albedo_color[1], entity_data.material.albedo_color[2], 1.0],
+ albedo_texture: entity_data.material.albedo_texture.clone(),
+ roughness: entity_data.material.roughness,
+ metallic: entity_data.material.metallic,
+ };
+
+ // Map PrimitiveType to handle
+ let handle = match pt {
+ PrimitiveType::Cube => 0,
+ PrimitiveType::Sphere => 1,
+ PrimitiveType::Cylinder => 2,
+ PrimitiveType::Plane => 3,
+ PrimitiveType::Capsule => 4,
+ PrimitiveType::Cone => 5,
+ };
+
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::world::MeshHandle(handle),
+ material,
+ ));
+ }
+ EntityType::Camera => {
+ state.world.player_start_transform.position = pos;
+ state.world.player_start_transform.rotation = rot;
+ }
+ EntityType::Light { light_type, color, intensity, range } => {
+ // Spawn Light
+ let engine_light_type = match light_type {
+ crate::project::scene::LightType::Point => crate::lighting::LightType::Point,
+ crate::project::scene::LightType::Spot => crate::lighting::LightType::Spot,
+ crate::project::scene::LightType::Directional => crate::lighting::LightType::Directional,
+ };
+
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::lighting::Light {
+ light_type: engine_light_type,
+ color: glam::Vec3::from(color),
+ intensity,
+ range,
+ ..Default::default()
+ }
+ ));
+ }
+ EntityType::Ground => {
+ let material = crate::world::Material {
+ color: [entity_data.material.albedo_color[0], entity_data.material.albedo_color[1], entity_data.material.albedo_color[2], 1.0],
+ albedo_texture: entity_data.material.albedo_texture.clone(),
+ roughness: entity_data.material.roughness,
+ metallic: entity_data.material.metallic,
+ };
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::world::MeshHandle(3), // Plane
+ material,
+ ));
+ }
+ EntityType::Building { height: _ } => {
+ let material = crate::world::Material {
+ color: [entity_data.material.albedo_color[0], entity_data.material.albedo_color[1], entity_data.material.albedo_color[2], 1.0],
+ albedo_texture: entity_data.material.albedo_texture.clone(),
+ roughness: entity_data.material.roughness,
+ metallic: entity_data.material.metallic,
+ };
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::world::MeshHandle(0), // Cube
+ material,
+ ));
+ }
+ EntityType::Vehicle => {
+ let material = crate::world::Material {
+ color: [entity_data.material.albedo_color[0], entity_data.material.albedo_color[1], entity_data.material.albedo_color[2], 1.0],
+ albedo_texture: entity_data.material.albedo_texture.clone(),
+ roughness: entity_data.material.roughness,
+ metallic: entity_data.material.metallic,
+ };
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::world::MeshHandle(0), // Cube placeholder
+ crate::world::Vehicle { speed: 0.0, max_speed: 10.0, steering: 0.0, accelerating: false },
+ material,
+ ));
+ info!("Spawned Vehicle at {:?}", pos);
+ }
+ EntityType::CrowdAgent { state: agent_state_str, speed } => {
+ let material = crate::world::Material {
+ color: [entity_data.material.albedo_color[0], entity_data.material.albedo_color[1], entity_data.material.albedo_color[2], 1.0],
+ albedo_texture: entity_data.material.albedo_texture.clone(),
+ roughness: entity_data.material.roughness,
+ metallic: entity_data.material.metallic,
+ };
+ let agent_state = match agent_state_str.as_str() {
+ "Idle" => crate::world::AgentState::Idle,
+ "Walking" => crate::world::AgentState::Walking,
+ "Running" => crate::world::AgentState::Running,
+ _ => crate::world::AgentState::Idle,
+ };
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::world::MeshHandle(4), // Capsule placeholder
+ crate::world::CrowdAgent {
+ velocity: glam::Vec3::ZERO,
+ target: pos,
+ state: agent_state,
+ max_speed: speed,
+ stuck_timer: 0.0,
+ last_pos: pos,
+ },
+ material,
+ ));
+ info!("Spawned CrowdAgent at {:?}", pos);
+ }
+ EntityType::AudioSource { sound_id, volume, looping, max_distance, .. } => {
+ state.world.ecs.spawn((
+ crate::world::Transform { position: pos, rotation: rot, scale: scale },
+ crate::world::AudioSource {
+ sound_id,
+ volume,
+ looping,
+ max_distance,
+ playing: true,
+ runtime_handle: None,
+ },
+ ));
+ info!("Spawned AudioSource at {:?}", pos);
+ }
+ _ => {}
+ }
+ }
+ } else {
+ error!("Failed to deserialize scene JSON");
+ }
+ }
+ } else {