mirror of
https://github.com/eliasstepanik/voxel-simulation.git
synced 2026-01-11 13:58:30 +00:00
Added Rotation and scale sync
This commit is contained in:
parent
8673ff7c88
commit
9442befb27
17
.idea/runConfigurations/PublishServer_OSX.xml
generated
Normal file
17
.idea/runConfigurations/PublishServer_OSX.xml
generated
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="PublishServer OSX" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/publish_server.sh" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/zsh" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||||
|
<envs />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
17
.idea/runConfigurations/PublishServer_Win.xml
generated
Normal file
17
.idea/runConfigurations/PublishServer_Win.xml
generated
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="PublishServer Win" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/publish_server.bat" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="$PROJECT_DIR$/../../../../Windows/System32/WindowsPowerShell/v1.0/powershell.exe" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="true" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||||
|
<envs />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@ -6,7 +6,7 @@ use bevy_render::camera::{Exposure, PhysicalCameraParameters, Projection};
|
|||||||
use bevy_window::CursorGrabMode;
|
use bevy_window::CursorGrabMode;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use random_word::Lang;
|
use random_word::Lang;
|
||||||
use crate::module_bindings::{set_name, set_position, spawn_entity, DbVector3};
|
use crate::module_bindings::{set_name, set_position, spawn_entity, DbTransform, DbVector3, DbVector4};
|
||||||
use crate::plugins::network::systems::database::DbConnectionResource;
|
use crate::plugins::network::systems::database::DbConnectionResource;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@ -117,10 +117,25 @@ pub fn camera_controller_system(
|
|||||||
}
|
}
|
||||||
if keyboard_input.just_pressed(KeyCode::KeyE) {
|
if keyboard_input.just_pressed(KeyCode::KeyE) {
|
||||||
let rand_position = random_vec3(-10.0,10.0);
|
let rand_position = random_vec3(-10.0,10.0);
|
||||||
ctx.0.reducers.spawn_entity(DbVector3{
|
let rand_rotation = random_vec3(-10.0,10.0);
|
||||||
x: rand_position.x,
|
let rand_scale = random_vec3(0.1,1.0);
|
||||||
y: rand_position.y,
|
ctx.0.reducers.spawn_entity(DbTransform{
|
||||||
z: rand_position.z,
|
position: DbVector3{
|
||||||
|
x: rand_position.x,
|
||||||
|
y: rand_position.y,
|
||||||
|
z: rand_position.z,
|
||||||
|
},
|
||||||
|
rotation: DbVector4 {
|
||||||
|
x: rand_rotation.x,
|
||||||
|
y: rand_rotation.y,
|
||||||
|
z: rand_position.z,
|
||||||
|
w: 0.0,
|
||||||
|
},
|
||||||
|
scale: DbVector3 {
|
||||||
|
x: rand_scale.x,
|
||||||
|
y: rand_scale.x,
|
||||||
|
z: rand_scale.x,
|
||||||
|
},
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use bevy::math::Vec3;
|
use bevy::math::Vec3;
|
||||||
use bevy::pbr::{MeshMaterial3d, StandardMaterial};
|
use bevy::pbr::{MeshMaterial3d, StandardMaterial};
|
||||||
use bevy::prelude::{default, Bundle, Commands, Component, Cuboid, DespawnRecursiveExt, Entity, GlobalTransform, Mesh, Query, Res, ResMut, Sphere, Transform};
|
use bevy::prelude::{default, Bundle, Commands, Component, Cuboid, DespawnRecursiveExt, Entity, GlobalTransform, Mesh, Quat, Query, Res, ResMut, Sphere, Transform};
|
||||||
use bevy_asset::Assets;
|
use bevy_asset::Assets;
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::Reflect;
|
||||||
use bevy_render::mesh::Mesh3d;
|
use bevy_render::mesh::Mesh3d;
|
||||||
@ -33,11 +33,7 @@ pub fn init(mut commands: Commands,
|
|||||||
commands.spawn((
|
commands.spawn((
|
||||||
Mesh3d(meshes.add(Cuboid::default()),),
|
Mesh3d(meshes.add(Cuboid::default()),),
|
||||||
MeshMaterial3d(debug_material.clone ()),
|
MeshMaterial3d(debug_material.clone ()),
|
||||||
Transform::from_xyz(
|
db_transfrom_to_transfrom(entity.transform.clone()),
|
||||||
entity.transform.position.x,
|
|
||||||
entity.transform.position.y,
|
|
||||||
entity.transform.position.z,
|
|
||||||
),
|
|
||||||
EntityDto{
|
EntityDto{
|
||||||
entity_id: entity.entity_id,
|
entity_id: entity.entity_id,
|
||||||
transform: entity.transform
|
transform: entity.transform
|
||||||
@ -97,12 +93,7 @@ pub fn sync_entities_system(
|
|||||||
};
|
};
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
db_transfrom_to_transfrom(db_entity.transform.clone()),
|
||||||
Transform::from_xyz(
|
|
||||||
db_entity.transform.position.x,
|
|
||||||
db_entity.transform.position.y,
|
|
||||||
db_entity.transform.position.z,
|
|
||||||
),
|
|
||||||
GlobalTransform::default(),
|
GlobalTransform::default(),
|
||||||
entity_type,
|
entity_type,
|
||||||
MeshMaterial3d(debug_material),
|
MeshMaterial3d(debug_material),
|
||||||
@ -122,4 +113,25 @@ pub fn sync_entities_system(
|
|||||||
commands.entity(entity).despawn_recursive();
|
commands.entity(entity).despawn_recursive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn db_transfrom_to_transfrom(db_transform: DbTransform) -> Transform{
|
||||||
|
Transform::from_xyz(
|
||||||
|
db_transform.position.x,
|
||||||
|
db_transform.position.y,
|
||||||
|
db_transform.position.z,
|
||||||
|
).with_rotation(
|
||||||
|
Quat::from_xyzw(
|
||||||
|
db_transform.rotation.x,
|
||||||
|
db_transform.rotation.y,
|
||||||
|
db_transform.rotation.z,
|
||||||
|
db_transform.rotation.w
|
||||||
|
)
|
||||||
|
).with_scale(
|
||||||
|
Vec3::new(
|
||||||
|
db_transform.scale.x,
|
||||||
|
db_transform.scale.y,
|
||||||
|
db_transform.scale.z,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@ -24,16 +24,11 @@ pub enum EntityType {
|
|||||||
|
|
||||||
|
|
||||||
#[spacetimedb::reducer]
|
#[spacetimedb::reducer]
|
||||||
pub fn spawn_entity(ctx: &ReducerContext, position: DbVector3) -> Result<(), String> {
|
pub fn spawn_entity(ctx: &ReducerContext, transform: DbTransform) -> Result<(), String> {
|
||||||
|
|
||||||
ctx.db.entity().try_insert(Entity {
|
ctx.db.entity().try_insert(Entity {
|
||||||
entity_id: 0,
|
entity_id: 0,
|
||||||
transform: DbTransform{
|
transform,
|
||||||
position: position,
|
|
||||||
rotation: DBVector4{x: 0.0, y: 0.0, z: 0.0, w: 1.0},
|
|
||||||
scale: DbVector3 {x: 1.0, y: 1.0, z: 1.0 },
|
|
||||||
|
|
||||||
},
|
|
||||||
entity_type: EntityType::Cube,
|
entity_type: EntityType::Cube,
|
||||||
}).expect("TODO: panic message");
|
}).expect("TODO: panic message");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user