Skip to content

Commit

Permalink
feat: fix issues Orillusion#304
Browse files Browse the repository at this point in the history
fix: texture Count Exceeded the maximum limit of 7
  • Loading branch information
hellmor committed Nov 10, 2023
1 parent 89ef8d3 commit febdf23
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 157 deletions.
53 changes: 53 additions & 0 deletions samples/gui/Sample_UIMultipleTextures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Engine3D, Scene3D, Object3D, Camera3D, View3D, UIImage, HoverCameraController, AtmosphericComponent, BitmapTexture2D, makeAloneSprite, WorldPanel, GPUCullMode, UIPanel, Color } from '@orillusion/core'

class Sample_UIMultipleTextures {
async run() {
// initializa engine
await Engine3D.init()
// create new scene as root node
let scene3D: Scene3D = new Scene3D()
scene3D.addComponent(AtmosphericComponent)
// create camera
let cameraObj: Object3D = new Object3D()
let camera = cameraObj.addComponent(Camera3D)
// adjust camera view
camera.perspective(60, Engine3D.aspect, 1, 5000.0)
// set camera controller
let controller = cameraObj.addComponent(HoverCameraController)
controller.setCamera(15, 10, 80)
// add camera node
scene3D.addChild(cameraObj)
let view = new View3D()
view.scene = scene3D
view.camera = camera
Engine3D.startRenderView(view)
// create panel root
let panelRoot: Object3D = new Object3D()
let panel: UIPanel = panelRoot.addComponent(WorldPanel)
panel.cullMode = GPUCullMode.none;
panelRoot.localScale.set(0.1, 0.1, 0.1)
let canvas = view.enableUICanvas()
canvas.addChild(panelRoot)

for (let i = 0; i < 10; i++) {
let bitmapTexture2D = new BitmapTexture2D()
bitmapTexture2D.flipY = true
await bitmapTexture2D.load('textures/digit/digit_' + i + '.png')

// create image node
let imageQuad = new Object3D()
panelRoot.addChild(imageQuad)
// create image component
let image: UIImage = imageQuad.addComponent(UIImage)
// set image size
image.uiTransform.resize(10, 10)
image.uiTransform.setXY((i - 5) * 8, 0);
image.color = Color.random();
// set image source
image.sprite = makeAloneSprite('webgpu' + i, bitmapTexture2D)
}

}
}

new Sample_UIMultipleTextures().run()
138 changes: 69 additions & 69 deletions samples/index.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
import { Sample_GraphicPath } from "./graphic/Sample_GraphicPath"
// import { Sample_GraphicPath } from "./graphic/Sample_GraphicPath"

// /******** Load all samples in /src/sample/ ********/
// {
// // find all demos in /sample
// const modules = import.meta.glob(['./*/*.ts', '!./*/_*.ts'])
// // create menu
// let title = '', list = `<svg onclick="document.body.classList.remove('show')" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" class="close"><path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path></svg>`
// for (const path in modules) {
// if (!path.includes('Sample_')) continue
// const arr = path.split('/')
// const _title = arr[1]
// const _demo = arr[2].replace(/Sample_|\.ts/g, '')
// if (_title != title) {
// list += `<p>${_title}</p>`
// title = _title
// }
// list += `<a id="${path}">${_demo}</a>`
// }
// const menu = document.createElement('div')
// menu.className = 'menu'
// menu.innerHTML = list
// document.body.appendChild(menu)
/******** Load all samples in /src/sample/ ********/
{
// find all demos in /sample
const modules = import.meta.glob(['./*/*.ts', '!./*/_*.ts'])
// create menu
let title = '', list = `<svg onclick="document.body.classList.remove('show')" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" class="close"><path fill="currentColor" d="M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"></path></svg>`
for (const path in modules) {
if (!path.includes('Sample_')) continue
const arr = path.split('/')
const _title = arr[1]
const _demo = arr[2].replace(/Sample_|\.ts/g, '')
if (_title != title) {
list += `<p>${_title}</p>`
title = _title
}
list += `<a id="${path}">${_demo}</a>`
}
const menu = document.createElement('div')
menu.className = 'menu'
menu.innerHTML = list
document.body.appendChild(menu)


// // change sessionStorage.target on click, and reload iframe
// menu.addEventListener('click', (e: Event) => {
// const button = e.target as HTMLElement
// if (!button.id)
// return
// // remove prev iframe to clear memory
// document.querySelector('iframe')?.remove()
// const target = button.id
// if (target && modules[target]) {
// addIframe()
// document.querySelector('.active')?.classList.remove('active')
// button.classList.add('active')
// sessionStorage.top = menu.scrollTop
// sessionStorage.target = target
// }
// })
// change sessionStorage.target on click, and reload iframe
menu.addEventListener('click', (e: Event) => {
const button = e.target as HTMLElement
if (!button.id)
return
// remove prev iframe to clear memory
document.querySelector('iframe')?.remove()
const target = button.id
if (target && modules[target]) {
addIframe()
document.querySelector('.active')?.classList.remove('active')
button.classList.add('active')
sessionStorage.top = menu.scrollTop
sessionStorage.target = target
}
})

// // load target on refresh
// if (sessionStorage.target) {
// const target = sessionStorage.target
// const a = document.querySelector(`[id="${target}"]`)
// if (a) {
// addIframe()
// a.classList.add('active')
// menu.scrollTop = sessionStorage.top
// }
// } else {
// document.querySelector('a')?.click()
// }
// load target on refresh
if (sessionStorage.target) {
const target = sessionStorage.target
const a = document.querySelector(`[id="${target}"]`)
if (a) {
addIframe()
a.classList.add('active')
menu.scrollTop = sessionStorage.top
}
} else {
document.querySelector('a')?.click()
}

// // create an iframe inside page to load sample
// function addIframe() {
// const iframe = document.createElement('iframe') as HTMLIFrameElement
// iframe.srcdoc = `
// <style>html,body{margin:0;padding:0;overflow:hidden}canvas{touch-action:none}</style>
// <script>
// let target = sessionStorage.target
// if(target)
// import('./samples/'+target).then(m=>{
// for(let i in m){
// new m[i]().run()
// break
// }
// })
// </script>`
// document.body.appendChild(iframe)
// }
// }
// create an iframe inside page to load sample
function addIframe() {
const iframe = document.createElement('iframe') as HTMLIFrameElement
iframe.srcdoc = `
<style>html,body{margin:0;padding:0;overflow:hidden}canvas{touch-action:none}</style>
<script>
let target = sessionStorage.target
if(target)
import('./samples/'+target).then(m=>{
for(let i in m){
new m[i]().run()
break
}
})
</script>`
document.body.appendChild(iframe)
}
}

// import { Sample_GraphicMesh_Trailing } from "./graphic/Sample_GraphicMesh_Trailing";
// new Sample_GraphicMesh_Trailing().run();

new Sample_GraphicPath().run();
// new Sample_GraphicPath().run();
8 changes: 4 additions & 4 deletions samples/pick/Sample_PixelPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ class Sample_PixelPick {
let obj = this.getPickObject(e);
if (obj) {
let msc = obj.getComponent(MaterialStateComponent);
msc.changeColor(new Color(2, 0, 0, 1), 120);
msc.changeColor(new Color(1.2, 0, 0, 1), 120);
}
}

private onMouseDown(e: PointerEvent3D) {
let obj = this.getPickObject(e);
if (obj) {
let msc = obj.getComponent(MaterialStateComponent);
msc.changeColor(new Color(2, 2, 0, 1), 120);
msc.changeColor(new Color(1, 1.2, 0, 1), 120);
}
}

private onMousePick(e: PointerEvent3D) {
let obj = this.getPickObject(e);
if (obj) {
let msc = obj.getComponent(MaterialStateComponent);
msc.changeColor(new Color(2, 0, 0, 1), 120);
msc.changeColor(new Color(1.2, 0, 0.5, 1), 120);
}
}

private onMouseOver(e: PointerEvent3D) {
let obj = this.getPickObject(e);
if (obj) {
let msc = obj.getComponent(MaterialStateComponent);
msc.changeColor(new Color(1, 0.64, 0.8, 2.5), 100);
msc.changeColor(new Color(1, 0.64, 0.8, 1.5), 100);
}
}

Expand Down
47 changes: 35 additions & 12 deletions src/components/gui/core/GUIGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ export class GUIGeometry extends GeometryBase {
this.maxQuadCount = max;
}

updateSubGeometry(index: number, start: number, count: number) {
let geom = this.subGeometries[index];
if (geom) {
let desc = geom.lodLevels[0];
desc.indexStart = start;
desc.indexCount = count;
desc.index = index;
} else {
geom = this.addSubGeometry({
indexStart: start,
indexCount: count,
vertexStart: 0,
vertexCount: 0,
firstStart: 0,
index: index,
topology: 0,
});
}
return geom;
}

resetSubGeometries() {
for (let item of this.subGeometries) {
let desc = item.lodLevels[0];
desc.indexStart = 0;
desc.indexCount = 0;
desc.index = 0;
}
}

/**
* the bounds will be set to infinity
* @returns GUIGeometry
Expand All @@ -59,23 +89,23 @@ export class GUIGeometry extends GeometryBase {
return this;
}

public get vPositionBuffer(): StorageGPUBuffer {
public getPositionBuffer(): StorageGPUBuffer {
if (this._onPositionChange) {
this._posAttribute.buffer.apply();
this._onPositionChange = false;
}
return this._posAttribute.buffer;
}

public get vSpriteBuffer(): StorageGPUBuffer {
public getSpriteBuffer(): StorageGPUBuffer {
if (this._onSpriteChange) {
this._spriteAttribute.buffer.apply();
this._onSpriteChange = false;
}
return this._spriteAttribute.buffer;
}

public get vColorBuffer(): StorageGPUBuffer {
public getColorBuffer(): StorageGPUBuffer {
if (this._onColorChange) {
this._colorAttribute.buffer.apply();
this._onColorChange = false;
Expand Down Expand Up @@ -120,15 +150,8 @@ export class GUIGeometry extends GeometryBase {
this.setAttribute(VertexAttributeName.uv, this._attributeUV);
this.setAttribute(VertexAttributeName.vIndex, this._attributeVIndex);

this.addSubGeometry({
indexStart: 0,
indexCount: this._faceIndexes.length,
vertexStart: 0,
vertexCount: 0,
firstStart: 0,
index: 0,
topology: 0,
});
this.updateSubGeometry(0, 0, this._faceIndexes.length);

return this;
}

Expand Down
Loading

0 comments on commit febdf23

Please sign in to comment.