Support vertex colors
This commit is contained in:
@@ -9,6 +9,7 @@ import arm.util.UVUtil;
|
||||
import arm.util.RenderUtil;
|
||||
import arm.util.ParticleUtil;
|
||||
import arm.ui.UITrait;
|
||||
import arm.ui.UINodes;
|
||||
import arm.node.MaterialParser;
|
||||
import arm.Tool;
|
||||
import arm.Project;
|
||||
@@ -55,6 +56,7 @@ class Context {
|
||||
MaterialParser.parsePaintMaterial();
|
||||
UITrait.inst.hwnd1.redraws = 2;
|
||||
UITrait.inst.headerHandle.redraws = 2;
|
||||
UINodes.inst.hwnd.redraws = 2;
|
||||
|
||||
var decal = tool == ToolDecal || tool == ToolText;
|
||||
if (decal) {
|
||||
|
||||
@@ -255,6 +255,11 @@ class Project {
|
||||
if (ui.isHovered) ui.tooltip("Load per-object transforms from .fbx");
|
||||
}
|
||||
|
||||
if (path.toLowerCase().endsWith(".fbx") || path.toLowerCase().endsWith(".blend")) {
|
||||
UITrait.inst.parseVCols = ui.check(Id.handle({selected: UITrait.inst.parseVCols}), "Parse Vertex Colors");
|
||||
if (ui.isHovered) ui.tooltip("Import vertex color data");
|
||||
}
|
||||
|
||||
ui.row([0.5, 0.5]);
|
||||
if (ui.button("Cancel")) {
|
||||
UIBox.show = false;
|
||||
|
||||
@@ -97,11 +97,10 @@ class ImportMesh {
|
||||
if (mesh.texa != null) raw.vertex_arrays.push({ values: mesh.texa, attrib: "tex" });
|
||||
}
|
||||
else {
|
||||
if (mesh.texa == null) {
|
||||
equirectUnwrap(mesh);
|
||||
}
|
||||
raw = rawMesh(mesh);
|
||||
if (mesh.texa == null) equirectUnwrap(mesh);
|
||||
raw.vertex_arrays.push({ values: mesh.texa, attrib: "tex" });
|
||||
if (mesh.cola != null) raw.vertex_arrays.push({ values: mesh.cola, attrib: "col" });
|
||||
}
|
||||
|
||||
new MeshData(raw, function(md: MeshData) {
|
||||
|
||||
@@ -25,6 +25,7 @@ class MakePaint {
|
||||
con_paint.data.color_writes_green = [true, true, true, true];
|
||||
con_paint.data.color_writes_blue = [true, true, true, true];
|
||||
con_paint.data.color_writes_alpha = [true, true, true, true];
|
||||
con_paint.allow_vcols = Context.paintObject.data.geom.cols != null;
|
||||
|
||||
var vert = con_paint.make_vert();
|
||||
var frag = con_paint.make_frag();
|
||||
|
||||
@@ -211,6 +211,10 @@ class Material {
|
||||
vert.add_out("vec4 wvpposition");
|
||||
vert.write_end('wvpposition = gl_Position;');
|
||||
}
|
||||
if (con.is_elem('col')) {
|
||||
vert.add_out('vec3 vcolor');
|
||||
vert.write_attrib('vcolor = col.rgb;');
|
||||
}
|
||||
}
|
||||
|
||||
static function parse_output(node: TNode): TShaderOut {
|
||||
@@ -378,9 +382,13 @@ class Material {
|
||||
|
||||
if (node.type == "ATTRIBUTE") {
|
||||
if (socket == node.outputs[0]) { // Color
|
||||
curshader.context.add_elem("col", "short4norm"); // Vcols only for now
|
||||
// return "vcolor";
|
||||
return "vec3(0.0, 0.0, 0.0)";
|
||||
if (curshader.context.allow_vcols) {
|
||||
curshader.context.add_elem("col", "short4norm"); // Vcols only for now
|
||||
}
|
||||
else {
|
||||
curshader.write_attrib("vec3 vcolor = vec3(1.0, 1.0, 1.0);");
|
||||
}
|
||||
return "vcolor";
|
||||
}
|
||||
else { // Vector
|
||||
curshader.context.add_elem("tex", "short2norm"); // UVMaps only for now
|
||||
|
||||
@@ -22,6 +22,7 @@ class MaterialShaderContext {
|
||||
public var tesc:MaterialShader;
|
||||
public var tese:MaterialShader;
|
||||
public var data:TShaderContext;
|
||||
public var allow_vcols = false;
|
||||
var material:TMaterial;
|
||||
var constants:Array<TShaderConstant>;
|
||||
var tunits:Array<TTextureUnit>;
|
||||
|
||||
@@ -204,6 +204,7 @@ class TabMaterials {
|
||||
|
||||
static function updateMaterial() {
|
||||
UITrait.inst.headerHandle.redraws = 2;
|
||||
UINodes.inst.hwnd.redraws = 2;
|
||||
MaterialParser.parsePaintMaterial();
|
||||
RenderUtil.makeMaterialPreview();
|
||||
var decal = Context.tool == ToolDecal || Context.tool == ToolText;
|
||||
|
||||
@@ -118,6 +118,7 @@ class UITrait {
|
||||
public var isSubsSpace = 0;
|
||||
public var splitBy = SplitObject;
|
||||
public var parseTransform = false;
|
||||
public var parseVCols = false;
|
||||
public var hwnd = Id.handle();
|
||||
public var hwnd1 = Id.handle();
|
||||
public var hwnd2 = Id.handle();
|
||||
|
||||
Reference in New Issue
Block a user