alright last patch, I think I just doubled the framerate...
This commit is contained in:
@@ -6,7 +6,7 @@ use mint::{Quaternion, Vector3};
|
|||||||
use protostar::xdg::{DesktopFile, get_desktop_files};
|
use protostar::xdg::{DesktopFile, get_desktop_files};
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use single::{APP_SIZE, App, BTN_COLOR, BTN_SELECTED_COLOR, MODEL_SCALE};
|
use single::{APP_SIZE, App, BTN_COLOR, BTN_SELECTED_COLOR, MODEL_SCALE, DEFAULT_HEX_COLOR};
|
||||||
use stardust_xr_asteroids::{
|
use stardust_xr_asteroids::{
|
||||||
ClientState, CustomElement, Element, Migrate, Reify, Transformable, client,
|
ClientState, CustomElement, Element, Migrate, Reify, Transformable, client,
|
||||||
elements::{Button, Grabbable, Model, ModelPart, PointerMode, Spatial},
|
elements::{Button, Grabbable, Model, ModelPart, PointerMode, Spatial},
|
||||||
@@ -225,11 +225,7 @@ impl ClientState for HexagonLauncher {
|
|||||||
))
|
))
|
||||||
.part(ModelPart::new("Hex").mat_param(
|
.part(ModelPart::new("Hex").mat_param(
|
||||||
"color",
|
"color",
|
||||||
MaterialParameter::Color(if self.open {
|
MaterialParameter::Color(DEFAULT_HEX_COLOR),
|
||||||
BTN_SELECTED_COLOR
|
|
||||||
} else {
|
|
||||||
BTN_COLOR
|
|
||||||
}),
|
|
||||||
))
|
))
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
@@ -275,47 +271,74 @@ impl ClientState for HexagonLauncher {
|
|||||||
// use snapshot instead of reify_substate (cheap, immutable)
|
// use snapshot instead of reify_substate (cheap, immutable)
|
||||||
let snap = self.snapshots[i].clone();
|
let snap = self.snapshots[i].clone();
|
||||||
let pos = self.positions[i];
|
let pos = self.positions[i];
|
||||||
// build spatial + cheap model from snapshot (no per-app state access)
|
|
||||||
let mut spatial = Spatial::default().pos(pos).build();
|
|
||||||
|
|
||||||
// attach model from snapshot (gltf preferred, else namespaced + texture)
|
// start from a fresh spatial element
|
||||||
if let Some(gltf) = snap.cached_gltf {
|
let base = Spatial::default().pos(pos).build();
|
||||||
if let Ok(builder) = Model::direct(gltf.to_string_lossy().to_string()) {
|
|
||||||
spatial = spatial.child(
|
// ensure both branches return the same element type by always
|
||||||
builder
|
// attaching a Model child (either GLTF builder or namespaced fallback)
|
||||||
|
let with_model = match snap.cached_gltf {
|
||||||
|
Some(ref gltf) => {
|
||||||
|
if let Ok(builder) =
|
||||||
|
Model::direct(gltf.to_string_lossy().to_string())
|
||||||
|
{
|
||||||
|
base.child(
|
||||||
|
builder
|
||||||
|
.transform(Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0)
|
||||||
|
* Quat::from_rotation_y(PI),
|
||||||
|
[MODEL_SCALE; 3],
|
||||||
|
))
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// fallback to namespaced model if direct GLTF build fails
|
||||||
|
let mut mb = Model::namespaced("protostar", "hexagon/hexagon")
|
||||||
.transform(Transform::from_rotation_scale(
|
.transform(Transform::from_rotation_scale(
|
||||||
Quat::from_rotation_x(PI / 2.0)
|
Quat::from_rotation_x(PI / 2.0)
|
||||||
* Quat::from_rotation_y(PI),
|
* Quat::from_rotation_y(PI),
|
||||||
[MODEL_SCALE; 3],
|
[MODEL_SCALE; 3],
|
||||||
))
|
))
|
||||||
.build(),
|
.part(ModelPart::new("Hex").mat_param(
|
||||||
);
|
"color",
|
||||||
|
MaterialParameter::Color(if self.open {
|
||||||
|
BTN_SELECTED_COLOR
|
||||||
|
} else {
|
||||||
|
BTN_COLOR
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
if let Some(tex) = snap.cached_texture {
|
||||||
|
mb = mb.part(ModelPart::new("Icon").mat_param(
|
||||||
|
"diffuse",
|
||||||
|
MaterialParameter::Texture(tex),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
base.child(mb.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
None => {
|
||||||
let mut mb = Model::namespaced("protostar", "hexagon/hexagon")
|
let mut mb = Model::namespaced("protostar", "hexagon/hexagon")
|
||||||
.transform(Transform::from_rotation_scale(
|
.transform(Transform::from_rotation_scale(
|
||||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
Quat::from_rotation_x(PI / 2.0)
|
||||||
[MODEL_SCALE; 3],
|
* Quat::from_rotation_y(PI),
|
||||||
))
|
[MODEL_SCALE; 3],
|
||||||
.part(ModelPart::new("Hex").mat_param(
|
))
|
||||||
"color",
|
.part(ModelPart::new("Hex").mat_param(
|
||||||
MaterialParameter::Color(if self.open {
|
"color",
|
||||||
BTN_SELECTED_COLOR
|
MaterialParameter::Color(DEFAULT_HEX_COLOR),
|
||||||
} else {
|
));
|
||||||
BTN_COLOR
|
if let Some(tex) = snap.cached_texture {
|
||||||
}),
|
mb = mb.part(ModelPart::new("Icon").mat_param(
|
||||||
));
|
"diffuse",
|
||||||
if let Some(tex) = snap.cached_texture {
|
MaterialParameter::Texture(tex),
|
||||||
mb = mb.part(ModelPart::new("Icon").mat_param(
|
));
|
||||||
"diffuse",
|
}
|
||||||
MaterialParameter::Texture(tex),
|
base.child(mb.build())
|
||||||
));
|
|
||||||
}
|
}
|
||||||
spatial = spatial.child(mb.build());
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// attach a Button that mutates real state when used (captures index)
|
// attach a Button that mutates real state when used (captures index)
|
||||||
spatial.child(
|
with_model.child(
|
||||||
Button::new(move |state: &mut HexagonLauncher| {
|
Button::new(move |state: &mut HexagonLauncher| {
|
||||||
tracing::debug!(index = i, "app button pressed");
|
tracing::debug!(index = i, "app button pressed");
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user