Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions ThreePlus/Classes/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Material : SceneObject

#region members

public enum Types { None, Basic, Lambert, Standard, Phong, Toon, Physical, Normal, Depth, Shadow };
public enum Types { None, Basic, Lambert, Standard, Phong, Toon, Physical, Normal, Depth, Shadow, Shader };

protected bool isDefault = true;

Expand Down Expand Up @@ -76,6 +76,9 @@ public enum Types { None, Basic, Lambert, Standard, Phong, Toon, Physical, Norma
protected double opacityIor = 1.5;
protected double refractionRatio = 1.5;

protected bool hasShader = false;
protected Shader shader = null;

#endregion

#region constructors
Expand Down Expand Up @@ -131,9 +134,9 @@ public Material(Rhino.DocObjects.Material material) : base()
public Material(Material material) : base(material)
{
this.isDefault = material.isDefault;
for (int i = 0; i < material.maps.Length; i++) if(material.maps[i]!=null) this.maps[i] = material.maps[i];
for (int i =0;i< material.maps.Length; i++) this.MapNames[i] = material.MapNames[i];

for (int i = 0; i < material.maps.Length; i++) if (material.maps[i] != null) this.maps[i] = material.maps[i];
for (int i = 0; i < material.maps.Length; i++) this.MapNames[i] = material.MapNames[i];

this.materialType = material.materialType;

Expand Down Expand Up @@ -188,6 +191,8 @@ public Material(Material material) : base(material)
this.hasOpacityIor = material.hasOpacityIor;
this.opacityIor = material.opacityIor;
this.refractionRatio = material.refractionRatio;

this.shader = material.shader; // Not sure if should create a new one (with new uuid)
}

public static Material ShadowMaterial(Sd.Color color)
Expand Down Expand Up @@ -316,6 +321,18 @@ public static Material DepthMaterial()
return material;
}

public static Material ShaderMaterial(Shader shader)
{
Material material = new Material(false);

material.type = "MeshShaderMaterial";
material.materialType = Types.Shader;

material.hasShader = true;
material.shader = shader;

return material;
}

#endregion

Expand All @@ -329,7 +346,7 @@ public virtual bool IsDefault
public virtual Sd.Bitmap[] Maps
{
get { return maps; }
}
}

public virtual Types MaterialType
{
Expand Down Expand Up @@ -376,7 +393,7 @@ public virtual Sd.Color DiffuseColor

public virtual bool HasTextureMap
{
get { return (Maps[0]!=null); }
get { return (Maps[0] != null); }
}

public virtual string TextureMapName
Expand All @@ -387,7 +404,7 @@ public virtual string TextureMapName
public virtual Sd.Bitmap TextureMap
{
set { maps[0] = new Sd.Bitmap(value); }
get
get
{
if (maps[0] != null)
{
Expand Down Expand Up @@ -1267,6 +1284,23 @@ public virtual double RefractionRatio
get { return refractionRatio; }
}

#region 26 | SHADER
public virtual bool HasShader
{
get
{
return shader != null;
}
}
public virtual Shader Shader
{
get
{
return shader;
}
}
#endregion

#endregion

#region methods
Expand All @@ -1284,7 +1318,7 @@ public void SetTextureMap(Sd.Color diffuseColor, Sd.Bitmap map = null)
public void SetBumpMap(Sd.Bitmap map, double intensity = 1.0)
{
this.bumpIntensity = intensity;
if(map!=null) this.BumpMap = new Sd.Bitmap(map);
if (map != null) this.BumpMap = new Sd.Bitmap(map);
}

public void SetClearcoatMap(double clearcoat, Sd.Bitmap map = null)
Expand Down Expand Up @@ -1312,7 +1346,7 @@ public void SetDisplacementMap(Sd.Bitmap map, double scale = 1.0)
{
this.hasDisplacement = (map != null);
this.displacementScale = scale;
if(map != null)this.DisplacementMap = new Sd.Bitmap(map);
if (map != null) this.DisplacementMap = new Sd.Bitmap(map);
}

public void SetEmissivity(double intensity, Sd.Color color, Sd.Bitmap map = null)
Expand Down Expand Up @@ -1403,7 +1437,7 @@ public void SetVolume(double transmission, double ior, double refractionRatio, S

public override string ToString()
{
return "Material | "+ materialType.ToString();
return "Material | " + materialType.ToString();
}

#endregion
Expand Down
33 changes: 21 additions & 12 deletions ThreePlus/Classes/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Text;
using System.Threading.Tasks;

using Sd=System.Drawing;
using Sd = System.Drawing;

namespace ThreePlus
{
public class Scene:MetaData
public class Scene : MetaData
{

#region members
Expand All @@ -26,7 +26,7 @@ public class Scene:MetaData
public Axes Axes = new Axes();

public List<Model> Models = new List<Model>();
public List<Camera> Cameras = new List<Camera> {new Camera() };
public List<Camera> Cameras = new List<Camera> { new Camera() };
protected List<Light> lights = new List<Light>();
public List<Script> Scripts = new List<Script>();

Expand All @@ -37,14 +37,14 @@ public class Scene:MetaData

#region constructors

public Scene():base()
public Scene() : base()
{
this.type = "Scene";
this.objectType = "Scene";
this.name = "Scene";
}

public Scene(Scene scene):base(scene)
public Scene(Scene scene) : base(scene)
{
this.Grid = new Grid(scene.Grid);
this.Axes = new Axes(scene.Axes);
Expand All @@ -66,7 +66,6 @@ public Scene(Scene scene):base(scene)
{
this.Scripts.Add(new Script(script));
}

this.Environment = new Environment(scene.Environment);
this.Atmosphere = new Atmosphere(scene.Atmosphere);

Expand All @@ -75,7 +74,7 @@ public Scene(Scene scene):base(scene)

this.hasShadows = scene.hasShadows;
this.shadowThreshold = scene.shadowThreshold;
}
}

#endregion

Expand All @@ -90,6 +89,14 @@ public virtual bool HasCurves
}
}

public virtual bool HasShaders
{
get
{
return Models.Any(m => m.Material.MaterialType == Material.Types.Shader);
}
}

public List<Light> Lights
{
get { return lights; }
Expand All @@ -112,11 +119,12 @@ public Camera Camera

public bool ContainsSpotLights
{
get {
get
{
bool isType = false;
foreach(Light light in lights)
foreach (Light light in lights)
{
if(light.LightType == Light.Types.Spot)
if (light.LightType == Light.Types.Spot)
{
isType = true;
break;
Expand Down Expand Up @@ -162,7 +170,7 @@ public void AddLight(Light light)
hasShadows = true;
if (light.Threshold > this.shadowThreshold) shadowThreshold = light.Threshold;
}
lights.Add(new Light(light));
lights.Add(new Light(light));
}

#endregion
Expand All @@ -171,10 +179,11 @@ public void AddLight(Light light)

public override string ToString()
{
return "Image(m:" + this.Models.Count + " l:" + this.lights.Count+ ")";
return "Image(m:" + this.Models.Count + " l:" + this.lights.Count + ")";
}

#endregion

}
}

92 changes: 92 additions & 0 deletions ThreePlus/Classes/Shader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ThreePlus
{
public class Shader : SceneObject
{

#region members
protected string vertexShaderCode = string.Empty;
protected string fragmentShaderCode = string.Empty;
protected List<KeyValuePair<string, object>> uniforms = null;
#endregion

#region constructors

public Shader() : base()
{
this.type = "Shader";
}

public Shader(Shader script) : base(script)
{
this.vertexShaderCode = script.vertexShaderCode;
this.fragmentShaderCode = script.fragmentShaderCode;
this.uniforms = new List<KeyValuePair<string, object>>(script.uniforms);
}

public Shader(string vertexShaderCode, string fragmentShaderCode) : base()
{
this.type = "Shader";

this.vertexShaderCode = vertexShaderCode;
this.fragmentShaderCode = fragmentShaderCode;
}
public Shader(string vertexShaderCode, string fragmentShaderCode, List<KeyValuePair<string, object>> uniforms) : base()
{
this.type = "Shader";

this.vertexShaderCode = vertexShaderCode;
this.fragmentShaderCode = fragmentShaderCode;
this.uniforms = uniforms;
}
#endregion

#region properties

public virtual string VertexShaderCode
{
get { return vertexShaderCode; }
}
public virtual string FragmentShaderCode
{
get { return fragmentShaderCode; }
}
public bool HasUniforms
{
get
{
return uniforms != null && uniforms.Count > 0;
}
}
public List<KeyValuePair<string, object>> Uniforms
{
get { return uniforms; }
}

#endregion

#region methods



#endregion

#region overrides

public override string ToString()
{
return "Shader";
}

#endregion



}
}

Loading