Skip to content

Commit

Permalink
refactor: Update color depth options in RenderFormFields
Browse files Browse the repository at this point in the history
  • Loading branch information
jer-nc committed Jul 30, 2024
1 parent cf49e46 commit def3f83
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const SelectItem = React.forwardRef<
<SelectPrimitive.Item
ref={ref}
className={cn(
"relative flex w-full text-muted-foreground cursor-default select-none items-center rounded py-2 pl-8 pr-2 text-xs outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex w-full text-white cursor-default select-none items-center rounded py-2 pl-8 pr-2 text-xs outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}
Expand Down
35 changes: 33 additions & 2 deletions src/features/render/render-inputs/select/RenderSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Scene } from "../../project-settings/ProjectSettings.types"
type FormRenderSchema = z.infer<typeof formRenderSchema>;
type FieldName = keyof FormRenderSchema;


interface RenderSelectProps {
form: UseFormReturn<z.infer<typeof formRenderSchema>>
fieldName: FieldName
Expand All @@ -36,7 +37,7 @@ const RenderSelect = ({ defaultValue, fieldName, form, label, options, isCustom,

// detect if fieldName is camera_name and if "" then setformstateerror

if(fieldName === "camera_name") {
if (fieldName === "camera_name") {
// console.log('camera name', value)
if (value === "") {
form.setError('camera_name', {
Expand Down Expand Up @@ -97,6 +98,36 @@ const RenderSelect = ({ defaultValue, fieldName, form, label, options, isCustom,
form.setValue(fieldName, value)
}

const formatColorDepth: { [key: string]: number | number[] } = {
BMP: 8,
IRIS: [8, 16],
PNG: [8, 16],
JPEG: 8,
JPEG2000: [8, 12, 16],
TARGA: [8, 16],
TARGA_RAW: [8, 16],
CINEON: [8, 10, 12, 16],
DPX: [8, 10, 12, 16],
OPEN_EXR: [16, 32],
OPEN_EXR_MULTILAYER: [16, 32],
// HDR: [32],
TIFF: [8, 16, 32],
WEBP: [8],
};


const isOptionDisabled = (option: string) => {
const currentValue = form.watch(fieldName);
console.log('current value', currentValue)
// Example logic to disable options based on the current form value and file format
if ((fieldName === "output.color.color_depth" as any) && formatColorDepth[form.watch("output.output_format")]) {
const allowedDepths = formatColorDepth[form.watch("output.output_format")];
const depthsArray = Array.isArray(allowedDepths) ? allowedDepths : [allowedDepths];
return !depthsArray.includes(Number(option));
}
return false;
}

return (
<FormField
control={form.control}
Expand All @@ -118,7 +149,7 @@ const RenderSelect = ({ defaultValue, fieldName, form, label, options, isCustom,
<SelectContent>
{options.map((option, index: number) => (
<SelectItem key={index} value={option}
disabled={currentPathname === '/render-cpu' && option === 'OPTIX' ? true : false}
disabled={currentPathname === '/render-cpu' && option === 'OPTIX' ? true : false || isOptionDisabled(option)}
>
{option}
</SelectItem>
Expand Down
2 changes: 1 addition & 1 deletion src/features/render/render-settings/RenderFormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const RenderFormFields = ({ form, sectionType }: RenderFormFieldsProps) => {
{renderSelectField("output.output_format", "Output Format", ['BMP', 'IRIS', 'PNG', 'JPEG', 'JPEG2000', 'TARGA', 'TARGA_RAW', 'CINEON', 'DPX', 'OPEN_EXR_MULTILAYER', 'OPEN_EXR', 'HDR', 'TIFF', 'WEBP'], scene.output.output_format)}
{renderInputField("output.compression", "Compression (%)", "number", "Compression", scene.output.compression, 0, 100)}
{renderSelectField("output.color.color_mode", "Color Mode", ['BW', 'RGB', 'RGBA'], scene.output.color.color_mode)}
{renderSelectField("output.color.color_depth", "Color Depth", ["8", "16"], scene.output.color.color_depth)}
{renderSelectField("output.color.color_depth", "Color Depth", ["8", "16", "32"], scene.output.color.color_depth)}
{renderCheckboxField("use_compositor", "Use Compositor", scene.use_compositor)}
{renderCheckboxField("use_sequencer", "Use Sequencer", scene.use_sequencer)}
{renderCheckboxField("use_stamp", "Stamp Metadata", scene.use_stamp)}
Expand Down

0 comments on commit def3f83

Please sign in to comment.