DUI3 render materials implementation
This commit is contained in:
Родитель
eefeef1ee4
Коммит
71746747fc
|
@ -395,8 +395,14 @@ const getStream = () => {
|
|||
// 'https://latest.speckle.systems/projects/5a6609a4b9/models/10f4931e8c'
|
||||
// DUI3 blocks
|
||||
// 'https://latest.speckle.systems/projects/126cd4b7bb/models/c6f3f309a2'
|
||||
'https://latest.speckle.systems/projects/126cd4b7bb/models/6b62c61a22'
|
||||
// 'https://latest.speckle.systems/projects/126cd4b7bb/models/6b62c61a22'
|
||||
// 'https://latest.speckle.systems/projects/126cd4b7bb/models/4dc5265453'
|
||||
// 'https://app.speckle.systems/projects/93200a735d/models/cbacd3eaeb'
|
||||
// DUI3 Render materials
|
||||
// 'https://latest.speckle.systems/projects/126cd4b7bb/models/7a5e738c76'
|
||||
// 'https://latest.speckle.systems/projects/126cd4b7bb/models/0a4181c73b'
|
||||
// 'https://latest.speckle.systems/projects/126cd4b7bb/models/bcf086cdc4'
|
||||
'https://latest.speckle.systems/projects/126cd4b7bb/models/6221c985c0'
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ export enum SpeckleType {
|
|||
Text = 'Text',
|
||||
Transform = 'Transform',
|
||||
InstanceProxy = 'InstanceProxy',
|
||||
RenderMaterialProxy = 'RenderMaterialProxy',
|
||||
Unknown = 'Unknown'
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ export default class SpeckleConverter {
|
|||
private instanceDefinitionLookupTable: { [id: string]: TreeNode } = {}
|
||||
private instancedObjectsLookupTable: { [id: string]: SpeckleObject } = {}
|
||||
private instanceProxies: { [id: string]: TreeNode } = {}
|
||||
private renderMaterialMap: { [id: string]: SpeckleObject } = {}
|
||||
private instanceCounter = 0
|
||||
|
||||
private readonly NodeConverterMapping: {
|
||||
|
@ -49,6 +50,7 @@ export default class SpeckleConverter {
|
|||
Dimension: this.DimensionToNode.bind(this),
|
||||
InstanceDefinitionProxy: this.InstanceDefinitionProxyToNode.bind(this),
|
||||
InstanceProxy: this.InstanceProxyToNode.bind(this),
|
||||
RenderMaterialProxy: this.RenderMaterialProxyToNode.bind(this),
|
||||
Parameter: null
|
||||
}
|
||||
|
||||
|
@ -543,6 +545,24 @@ export default class SpeckleConverter {
|
|||
return
|
||||
}
|
||||
|
||||
private async RenderMaterialProxyToNode(obj: SpeckleObject, _node: TreeNode) {
|
||||
if (!obj.value) {
|
||||
Logger.error(`Render Material Proxy ${obj.id} has no render material value!`)
|
||||
return
|
||||
}
|
||||
if (!obj.objects || !Array.isArray(obj.objects) || obj.objects.length === 0) {
|
||||
Logger.warn(`Render Material Proxy ${obj.id} has no target objects!`)
|
||||
}
|
||||
const renderMaterialValue = obj.value as SpeckleObject
|
||||
const targetObjects = obj.objects as []
|
||||
for (let k = 0; k < targetObjects.length; k++) {
|
||||
if (this.renderMaterialMap[targetObjects[k]]) {
|
||||
Logger.error(`Overwritting renderMaterial ${targetObjects[k]}`)
|
||||
}
|
||||
this.renderMaterialMap[targetObjects[k]] = renderMaterialValue
|
||||
}
|
||||
}
|
||||
|
||||
private getInstanceProxyDefinitionId(obj: SpeckleObject): string {
|
||||
return (obj.DefinitionId || obj.definitionId) as string
|
||||
}
|
||||
|
@ -650,6 +670,22 @@ export default class SpeckleConverter {
|
|||
}
|
||||
}
|
||||
|
||||
public async applyMaterials() {
|
||||
let count = Object.keys(this.renderMaterialMap).length
|
||||
/** Do a short async walk */
|
||||
await this.tree.walkAsync((node: TreeNode) => {
|
||||
if (!node.model.raw.applicationId) return true
|
||||
const applicationId = node.model.raw.applicationId.toString()
|
||||
if (this.renderMaterialMap[applicationId] !== undefined) {
|
||||
node.model.raw.renderMaterial = this.renderMaterialMap[applicationId]
|
||||
count--
|
||||
}
|
||||
/** Break out when all applicationIds are accounted for*/
|
||||
if (count === 0) return false
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
private async PointcloudToNode(obj: SpeckleObject, node: TreeNode) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
|
|
|
@ -75,6 +75,8 @@ export class SpeckleGeometryConverter extends GeometryConverter {
|
|||
case SpeckleType.Unknown:
|
||||
// console.warn(`Skipping geometry conversion for ${type}`)
|
||||
return null
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +180,7 @@ export class SpeckleGeometryConverter extends GeometryConverter {
|
|||
return null
|
||||
}
|
||||
|
||||
/** DUI3 INSTANCE PROXY */
|
||||
private InstanceProxyToGeometyData(node: NodeData): GeometryData | null {
|
||||
node
|
||||
return null
|
||||
|
@ -275,6 +278,7 @@ export class SpeckleGeometryConverter extends GeometryConverter {
|
|||
`Mesh (id ${node.raw.id}) colours are mismatched with vertice counts. The number of colours must equal the number of vertices.`
|
||||
)
|
||||
}
|
||||
/** We want the colors in linear space */
|
||||
colors = this.unpackColors(colorsRaw, true)
|
||||
}
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ export class SpeckleLoader extends Loader {
|
|||
}
|
||||
|
||||
await this.converter.convertInstances()
|
||||
await this.converter.applyMaterials()
|
||||
|
||||
const t0 = performance.now()
|
||||
const geometryConverter = new SpeckleGeometryConverter()
|
||||
|
|
|
@ -24,6 +24,7 @@ const defaultGradient: Asset = {
|
|||
export interface RenderMaterial {
|
||||
id: string
|
||||
color: number
|
||||
emissive: number
|
||||
opacity: number
|
||||
roughness: number
|
||||
metalness: number
|
||||
|
@ -122,6 +123,7 @@ export default class Materials {
|
|||
renderMaterial = {
|
||||
id: materialNode.model.raw.renderMaterial.id,
|
||||
color: materialNode.model.raw.renderMaterial.diffuse,
|
||||
emissive: materialNode.model.raw.renderMaterial.emissive,
|
||||
opacity:
|
||||
materialNode.model.raw.renderMaterial.opacity !== undefined
|
||||
? materialNode.model.raw.renderMaterial.opacity
|
||||
|
@ -664,7 +666,7 @@ export default class Materials {
|
|||
const mat: SpeckleStandardMaterial = new SpeckleStandardMaterial(
|
||||
{
|
||||
color: materialData.color,
|
||||
emissive: 0x0,
|
||||
emissive: 0x0, // materialData.emissive. Disabling this for now
|
||||
roughness: materialData.roughness,
|
||||
metalness: materialData.metalness,
|
||||
opacity: materialData.opacity,
|
||||
|
@ -677,6 +679,7 @@ export default class Materials {
|
|||
mat.depthWrite = mat.transparent ? false : true
|
||||
mat.clipShadows = true
|
||||
mat.color.convertSRGBToLinear()
|
||||
mat.emissive.convertSRGBToLinear()
|
||||
mat.updateArtificialRoughness(Materials.DEFAULT_ARTIFICIAL_ROUGHNESS)
|
||||
return mat
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче