-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support shader float and color uniforms
- Loading branch information
Showing
75 changed files
with
849 additions
and
95 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
use crate::figma_schema::FigmaColor; | ||
use dc_bundle::definition::view::shader_uniform_value::FloatVec; | ||
use dc_bundle::definition::view::shader_uniform_value::ValueType::{ | ||
FloatColorValue, FloatValue, FloatVecValue, | ||
}; | ||
use dc_bundle::definition::view::{ShaderUniform, ShaderUniformValue}; | ||
use log::error; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)] | ||
pub struct ShaderUniformJson { | ||
#[serde(rename = "uniformName")] | ||
pub uniform_name: String, | ||
#[serde(rename = "uniformType")] | ||
pub uniform_type: String, | ||
#[serde(rename = "uniformValue")] | ||
pub uniform_value: serde_json::Value, | ||
} | ||
|
||
impl Into<(String, ShaderUniform)> for ShaderUniformJson { | ||
fn into(self) -> (String, ShaderUniform) { | ||
let uniform_value = match self.uniform_type.as_str() { | ||
"float" => { | ||
if let Some(float_val) = self.uniform_value.as_f64() { | ||
Some(ShaderUniformValue { value_type: Some(FloatValue(float_val as f32)) }) | ||
} else { | ||
error!("Error parsing float for shader float uniform {}", self.uniform_name); | ||
None | ||
} | ||
} | ||
"float2" | "float3" | "float4" => { | ||
if let Some(uniform_array) = self.uniform_value.as_array() { | ||
let float_array: Vec<f32> = uniform_array | ||
.iter() | ||
.filter_map(|value| value.as_f64().map(|v| v as f32)) | ||
.collect(); | ||
match float_array.len() { | ||
2 if self.uniform_type == "float2" => Some(float_array), | ||
3 if self.uniform_type == "float3" => Some(float_array), | ||
4 if self.uniform_type == "float4" => Some(float_array), | ||
_ => None, | ||
} | ||
.map(|float_vec| ShaderUniformValue { | ||
value_type: Some(FloatVecValue(FloatVec { floats: float_vec })), | ||
}) | ||
} else { | ||
error!( | ||
"Error parsing float array for shader {} uniform {}", | ||
self.uniform_type, self.uniform_name | ||
); | ||
None | ||
} | ||
} | ||
"color" => serde_json::from_str::<FigmaColor>(self.uniform_value.to_string().as_str()) | ||
.ok() | ||
.map(|figma_color| (&figma_color).into()) | ||
.map(|parsed_color| ShaderUniformValue { | ||
value_type: Some(FloatColorValue(parsed_color)), | ||
}), | ||
_ => None, | ||
}; | ||
|
||
( | ||
self.uniform_name.clone(), | ||
ShaderUniform { | ||
name: self.uniform_name.clone(), | ||
r#type: self.uniform_type, | ||
value: uniform_value, | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
-79 Bytes
(100%)
designcompose/src/main/assets/figma/DesignSwitcherDoc_Ljph4e3sC0lHcynfXpoh9f.dcf
Binary file not shown.
Oops, something went wrong.