This commit is contained in:
syuilo 2026-05-24 05:09:52 +09:00
commit a3b6dc0899
5 changed files with 72 additions and 23 deletions

View file

@ -3582,3 +3582,11 @@ _miRoom:
imageFit_stretch: "引き伸ばす"
material_metallic: "光沢"
material_roughness: "粗さ"
light_brightness: "明るさ"
_objects:
woodRingFloorLamp: "リングシェードフロアランプ"
_woodRingFloorLamp:
shadeMat: "シェードの素材"
bodyMat: "本体の素材"
light: "照明"

View file

@ -24,6 +24,15 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts._miRoom.material_roughness }}</template>
</MkRange>
</div>
<div v-else-if="s.type === 'light'" class="_gaps_s">
<!-- debounce or throttleしないとカラーピッカー上で高速でなぞったときになぜか無限ループになるワーカーとの間でラグがあるため少し前の値がまたmodelValueとしてフィードバックされてしまうためだと思われる -->
<MkInput :modelValue="getHex(options[k].color)" type="color" :throttle="300" @update:modelValue="v => { const c = getRgb(v); if (c != null) updateLightColor(k, c); }">
<template #label>{{ i18n.ts.color }}</template>
</MkInput>
<MkRange :continuousUpdate="true" :min="0" :max="1" :step="0.1" :modelValue="options[k].brightness" @update:modelValue="v => updateLightBrightness(k, v)">
<template #label>{{ i18n.ts._miRoom.light_brightness }}</template>
</MkRange>
</div>
<div v-else-if="s.type === 'boolean'">
<MkSwitch :modelValue="options[k]" @update:modelValue="v => emit('update', k, v)"></MkSwitch>
</div>
@ -133,6 +142,14 @@ function updateMaterialMetallic(k: string, metallic: number) {
function updateMaterialRoughness(k: string, roughness: number) {
emit('update', k, { ...props.options[k], roughness });
}
function updateLightColor(k: string, color: { r: number; g: number; b: number }) {
emit('update', k, { ...props.options[k], color });
}
function updateLightBrightness(k: string, brightness: number) {
emit('update', k, { ...props.options[k], brightness });
}
</script>
<style lang="scss" module>

View file

@ -62,6 +62,11 @@ type MaterialOptionSchema = {
label: string;
};
type LightOptionSchema = {
type: 'light';
label: string;
};
type EnumOptionSchema = {
type: 'enum';
label: string;
@ -93,7 +98,7 @@ type SeedOptionSchema = {
label: string;
};
type OptionsSchema = Record<string, NumberOptionSchema | BooleanOptionSchema | StringOptionSchema | ColorOptionSchema | MaterialOptionSchema | EnumOptionSchema | RangeOptionSchema | ImageOptionSchema | SeedOptionSchema>;
type OptionsSchema = Record<string, NumberOptionSchema | BooleanOptionSchema | StringOptionSchema | ColorOptionSchema | MaterialOptionSchema | LightOptionSchema | EnumOptionSchema | RangeOptionSchema | ImageOptionSchema | SeedOptionSchema>;
export type RawOptions = Record<string, unknown> & {
readonly __brand: unique symbol;
@ -111,6 +116,7 @@ type GetRawOptionsSchemaValues<T extends OptionsSchema> = {
T[K] extends StringOptionSchema ? string :
T[K] extends ColorOptionSchema ? [number, number, number] :
T[K] extends MaterialOptionSchema ? { color: [number, number, number]; metallic: number; roughness: number; } :
T[K] extends LightOptionSchema ? { color: [number, number, number]; brightness: number; } :
T[K] extends EnumOptionSchema ? T[K]['enum'][number]['value'] :
T[K] extends RangeOptionSchema ? number :
T[K] extends ImageOptionSchema ? RawImageValue<T[K]['presets'][number]['value']> :
@ -125,6 +131,7 @@ type GetConvertedOptionsSchemaValues<T extends OptionsSchema> = {
T[K] extends StringOptionSchema ? string :
T[K] extends ColorOptionSchema ? [number, number, number] :
T[K] extends MaterialOptionSchema ? { color: [number, number, number]; metallic: number; roughness: number; } :
T[K] extends LightOptionSchema ? { color: [number, number, number]; brightness: number; } :
T[K] extends EnumOptionSchema ? T[K]['enum'][number]['value'] :
T[K] extends RangeOptionSchema ? number :
T[K] extends ImageOptionSchema ? ConvertedImageValue<T[K]['presets'][number]['value']> :

View file

@ -7,37 +7,33 @@ import * as BABYLON from '@babylonjs/core';
import { defineObject } from '../object.js';
import { getLightRangeFactorByGraphicsQuality } from '../utility.js';
import { cm, WORLD_SCALE } from '@/world/utility.js';
import { i18n } from '@/i18n.js';
export const woodRingFloorLamp = defineObject({
id: 'woodRingFloorLamp',
name: 'Wood Ring Floor Lamp',
name: i18n.ts._miRoom._objects.woodRingFloorLamp,
options: {
schema: {
shadeMat: {
type: 'material',
label: 'Shade material',
label: i18n.ts._miRoom._objects._woodRingFloorLamp.shadeMat,
},
bodyMat: {
type: 'material',
label: 'Body material',
label: i18n.ts._miRoom._objects._woodRingFloorLamp.bodyMat,
},
lightColor: {
type: 'color',
label: 'Light color',
},
lightBrightness: {
type: 'range',
label: 'Light brightness',
min: 0,
max: 1,
step: 0.01,
light: {
type: 'light',
label: i18n.ts._miRoom._objects._woodRingFloorLamp.light,
},
},
default: {
shadeMat: { color: [0.21, 0.04, 0], metallic: 0, roughness: 0.5 },
bodyMat: { color: [0.05, 0.05, 0.05], metallic: 1, roughness: 0.5 },
lightColor: [1, 0.5, 0.2],
lightBrightness: 0.5,
light: {
color: [1, 0.5, 0.2],
brightness: 0.5,
},
},
},
placement: 'floor',
@ -74,13 +70,11 @@ export const woodRingFloorLamp = defineObject({
}
const applyLightColor = () => {
const [r, g, b] = options.lightColor;
for (const light of lights) {
light.diffuse = new BABYLON.Color3(r, g, b);
light.diffuse = new BABYLON.Color3(options.light.color[0], options.light.color[1], options.light.color[2]);
}
for (const lamp of lamps) {
const emissive = lamp.material as BABYLON.PBRMaterial;
emissive.emissiveColor = new BABYLON.Color3(r, g, b);
(lamp.material as BABYLON.PBRMaterial).emissiveColor = new BABYLON.Color3(options.light.color[0], options.light.color[1], options.light.color[2]);
}
};
@ -88,12 +82,11 @@ export const woodRingFloorLamp = defineObject({
const applyLightBrightness = () => {
for (const light of lights) {
light.intensity = 1 * options.lightBrightness * WORLD_SCALE * WORLD_SCALE;
light.intensity = 1 * options.light.brightness * WORLD_SCALE * WORLD_SCALE;
light.range = cm(200) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
}
for (const lamp of lamps) {
const emissive = lamp.material as BABYLON.PBRMaterial;
emissive.emissiveIntensity = options.lightBrightness * 10;
(lamp.material as BABYLON.PBRMaterial).emissiveIntensity = options.light.brightness * 10;
}
};

View file

@ -13366,5 +13366,29 @@ export interface Locale extends ILocale {
*
*/
"material_roughness": string;
/**
*
*/
"light_brightness": string;
"_objects": {
/**
*
*/
"woodRingFloorLamp": string;
"_woodRingFloorLamp": {
/**
*
*/
"shadeMat": string;
/**
*
*/
"bodyMat": string;
/**
*
*/
"light": string;
};
};
};
}