-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playground: Fix connection lengths and let them be based on node inpu…
…t/output types (#27891) * Test proper input and output coloring * Add Type library for colors and in/output lengths * Overwrite node nodetype with predefined nodetype if necessary * Add DataType entries for matrices * Calculate output length based on data type * Improve code style and spacings * Reduce color length from 4 to 3 * further clean up code; Allow color to be null
- Loading branch information
Showing
20 changed files
with
227 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
export const typeToLengthLib = { | ||
// gpu | ||
string: 1, | ||
float: 1, | ||
bool: 1, | ||
vec2: 2, | ||
vec3: 3, | ||
vec4: 4, | ||
color: 3, | ||
mat2: 1, | ||
mat3: 1, | ||
mat4: 1, | ||
// cpu | ||
String: 1, | ||
Number: 1, | ||
Vector2: 2, | ||
Vector3: 3, | ||
Vector4: 4, | ||
Color: 3, | ||
// cpu: other stuff | ||
Material: 1, | ||
Object3D: 1, | ||
CodeNode: 1, | ||
Texture: 1, | ||
URL: 1, | ||
node: 1 | ||
}; | ||
|
||
export const defaultLength = 1; | ||
|
||
export function getLengthFromType( type ) { | ||
|
||
return typeToLengthLib[ type ] || defaultLength; | ||
|
||
} | ||
|
||
export function getLengthFromNode( value ) { | ||
|
||
let type = getTypeFromNode( value ); | ||
|
||
return getLengthFromType( type ); | ||
|
||
} | ||
|
||
export const typeToColorLib = { | ||
// gpu | ||
string: '#ff0000', | ||
float: '#eeeeee', | ||
bool: '#00dd00', | ||
mat2: '#70d030', | ||
mat3: '#70d030', | ||
mat4: '#70d030', | ||
// cpu | ||
String: '#ff0000', | ||
Number: '#eeeeee', | ||
// cpu: other stuff | ||
Material: '#228b22', | ||
Object3D: '#00a1ff', | ||
CodeNode: '#ff00ff', | ||
Texture: '#ffa500', | ||
URL: '#ff0080' | ||
}; | ||
|
||
export function getColorFromType( type ) { | ||
|
||
return typeToColorLib[ type ] || null; | ||
|
||
} | ||
|
||
export function getColorFromNode( value ) { | ||
|
||
let type = getTypeFromNode( value ); | ||
|
||
return getColorFromType( type ); | ||
|
||
} | ||
|
||
function getTypeFromNode( value ) { | ||
|
||
if ( value ) { | ||
|
||
if ( value.isMaterial ) return 'Material'; | ||
|
||
return value.nodeType === 'ArrayBuffer' ? 'URL' : ( value.nodeType || getTypeFromValue( value.value ) ); | ||
} | ||
|
||
} | ||
|
||
function getTypeFromValue( value ) { | ||
|
||
if ( value && value.isScriptableValueNode ) value = value.value; | ||
if ( ! value ) return; | ||
|
||
if ( value.isNode && value.nodeType === 'string' ) return 'string'; | ||
if ( value.isNode && value.nodeType === 'ArrayBuffer' ) return 'URL'; | ||
|
||
for ( const type of Object.keys( typeToLengthLib ).reverse() ) { | ||
|
||
if ( value[ 'is' + type ] === true ) return type; | ||
|
||
} | ||
|
||
} | ||
|
||
export function setInputAestheticsFromType( element, type ) { | ||
|
||
element.setInput( getLengthFromType( type ) ); | ||
|
||
const color = getColorFromType( type ); | ||
|
||
if ( color ) { | ||
|
||
element.setInputColor( color ); | ||
|
||
} | ||
|
||
return element; | ||
|
||
} | ||
|
||
export function setOutputAestheticsFromNode( element, node ) { | ||
|
||
if ( ! node ) { | ||
|
||
element.setOutput( 0 ); | ||
|
||
return element; | ||
|
||
} | ||
|
||
return setOutputAestheticsFromType( element, getTypeFromNode( node ) ); | ||
|
||
} | ||
|
||
export function setOutputAestheticsFromType( element, type ) { | ||
|
||
if ( ! type ) { | ||
|
||
element.setOutput( 1 ); | ||
|
||
return element; | ||
|
||
} | ||
|
||
if ( type == 'void' ) { | ||
|
||
element.setOutput( 0 ); | ||
|
||
return element; | ||
|
||
} | ||
|
||
element.setOutput( getLengthFromType( type ) ); | ||
|
||
const color = getColorFromType( type ); | ||
|
||
if ( color ) { | ||
|
||
element.setOutputColor( color ); | ||
|
||
} | ||
|
||
return element; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.