瀏覽代碼

Use SVGTextureLoader in tpImageInputGenerator for svg files,

master
Palash Bansal 1 年之前
父節點
當前提交
3e221384cc
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 13 行新增4 行删除
  1. 2
    2
      plugins/tweakpane/package.json
  2. 11
    2
      plugins/tweakpane/src/tpImageInputGenerator.ts

+ 2
- 2
plugins/tweakpane/package.json 查看文件

{ {
"name": "@threepipe/plugin-tweakpane", "name": "@threepipe/plugin-tweakpane",
"description": "Tweakpane UI Plugin for ThreePipe", "description": "Tweakpane UI Plugin for ThreePipe",
"version": "0.5.3",
"version": "0.5.4",
"devDependencies": { "devDependencies": {
"tweakpane-image-plugin": "https://github.com/repalash/tweakpane-image-plugin/releases/download/v1.1.404/package.tgz", "tweakpane-image-plugin": "https://github.com/repalash/tweakpane-image-plugin/releases/download/v1.1.404/package.tgz",
"uiconfig-tweakpane": "^0.0.10", "uiconfig-tweakpane": "^0.0.10",
"uiconfig-tweakpane": "^0.0.10" "uiconfig-tweakpane": "^0.0.10"
}, },
"peerDependencies": { "peerDependencies": {
"threepipe": "^0.0.35"
"threepipe": "^0.0.40"
} }
} }
}, },

+ 11
- 2
plugins/tweakpane/src/tpImageInputGenerator.ts 查看文件

ThreeViewer, ThreeViewer,
upgradeTexture, upgradeTexture,
WebGLRenderTarget, WebGLRenderTarget,
SVGTextureLoader,
} from 'threepipe' } from 'threepipe'
import type {UiObjectConfig} from 'uiconfig.js' import type {UiObjectConfig} from 'uiconfig.js'
import {TweakpaneUiPlugin} from './TweakpaneUiPlugin' import {TweakpaneUiPlugin} from './TweakpaneUiPlugin'



export const makeTextSvg2 = (text: string): string => { export const makeTextSvg2 = (text: string): string => {
return `data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Ctext style='font: 8px "Roboto Mono", "Source Code Pro", Menlo, Courier, monospace; fill: white;' x='9' y='18'%3E${text}%3C/text%3E%3C/svg%3E%0A` return `data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Ctext style='font: 8px "Roboto Mono", "Source Code Pro", Menlo, Courier, monospace; fill: white;' x='9' y='18'%3E${text}%3C/text%3E%3C/svg%3E%0A`
} }
setterTex(tex, config, renderer) setterTex(tex, config, renderer)
return return
} }

// todo do same in blueprint editor
if (SVGTextureLoader.USE_CANVAS_TEXTURE && (v.src?.endsWith('.svg') || v.src?.startsWith('data:image/svg'))) {
// due to windows bug which cannot load svg files in webgl without a width and height
const canvas = document.createElement('canvas')
SVGTextureLoader.CopyImageToCanvas(canvas, v)
v = canvas
}

tex = new Texture(v) tex = new Texture(v)
upgradeTexture.call(tex) upgradeTexture.call(tex)
tex.assetType = 'texture' tex.assetType = 'texture'
config.__proxy.value_ = renderer.methods.getRawValue(config) config.__proxy.value_ = renderer.methods.getRawValue(config)


params = params ?? {} params = params ?? {}
params.extensions = ['.jpg', '.png', '.svg', '.hdr',
params.extensions = ['.jpg', '.png', '.svg', '.hdr', '.ktx2',
'.exr', /* '.mp4', '.ogg', '.mov',*/ '.jpeg', '.exr', /* '.mp4', '.ogg', '.mov',*/ '.jpeg',
'.bmp', '.gif', '.webp', '.cube'] '.bmp', '.gif', '.webp', '.cube']
if (typeof params.imageFit === 'undefined') params.imageFit = 'contain' if (typeof params.imageFit === 'undefined') params.imageFit = 'contain'

Loading…
取消
儲存