├── README.md ├── Sources ├── THREE.Avalonia │ ├── GlobalUsing.cs │ ├── Resources │ │ ├── ltc_1.png │ │ └── ltc_2.png │ ├── Extras │ │ ├── Curves │ │ │ ├── LineCurve.cs │ │ │ ├── ArcCurve.cs │ │ │ ├── QuadraticBezierCurve3.cs │ │ │ ├── LineCurve3.cs │ │ │ ├── CubicBezierCurve3.cs │ │ │ └── SplineCurve.cs │ │ ├── Objects │ │ │ └── ImmediateRenderObject.cs │ │ └── Core │ │ │ ├── CurveInterface.cs │ │ │ ├── Shape.cs │ │ │ └── Interpolations.cs │ ├── Geometries │ │ ├── WireframeGeometry.cs │ │ ├── ConeGeometry.cs │ │ ├── TetrahedronGeometry.cs │ │ ├── OctahedronGeometry.cs │ │ ├── IcosahedronGeometry.cs │ │ ├── TextGeometry.cs │ │ └── DodecahedronGeometry.cs │ ├── Renderers │ │ ├── IExtensionsProvider.cs │ │ ├── gl │ │ │ ├── IGLProgram.cs │ │ │ ├── IGLAttribute.cs │ │ │ ├── GLAttribute.cs │ │ │ ├── GLShader.cs │ │ │ ├── IGLTextures.cs │ │ │ ├── IStructuredUniform.cs │ │ │ ├── ISingleUniform.cs │ │ │ ├── GLUniforms.cs │ │ │ ├── IPureArrayUniform.cs │ │ │ ├── GLUniform.cs │ │ │ ├── GLExtensions.cs │ │ │ ├── GLRenderLists.cs │ │ │ ├── GLBufferRenderer.cs │ │ │ ├── GLRenderState.cs │ │ │ ├── GLIndexedBufferRenderer.cs │ │ │ ├── GLRenderStates.cs │ │ │ ├── GLInfo.cs │ │ │ └── GLProperties.cs │ │ ├── GLMultisampleRenderTarget.cs │ │ ├── GLMultiviewRenderTarget.cs │ │ ├── Shaders │ │ │ └── UniformsUtils.cs │ │ └── IGLRenderer.cs │ ├── Materials │ │ ├── UniformLocation.cs │ │ ├── MeshMatcapMaterial.cs │ │ ├── MeshFaceMaterial.cs │ │ ├── ShadowMaterial.cs │ │ ├── RawShaderMaterial.cs │ │ ├── LineDashedMaterial.cs │ │ ├── PointsMaterial.cs │ │ ├── SpriteMaterial.cs │ │ ├── MeshDepthMaterial.cs │ │ ├── MeshDistanceMaterial.cs │ │ ├── MeshPhysicalMaterial.cs │ │ ├── MeshNormalMaterial.cs │ │ ├── PointCloudMaterial.cs │ │ ├── LineBasicMaterial.cs │ │ ├── MeshToonMaterial.cs │ │ ├── MeshLambertMaterial.cs │ │ └── MeshPhongMaterial.cs │ ├── Math │ │ ├── Cylindrical.cs │ │ ├── Rectangle.cs │ │ ├── Spherical.cs │ │ └── Vector.cs │ ├── Extensions │ │ ├── ThreeObjectExtension.cs │ │ ├── ShaderExtension.cs │ │ ├── GLUniformsLoader.cs │ │ └── ImageExtension.cs │ ├── Lights │ │ ├── DirectionalLightShadow.cs │ │ ├── AmbientLight.cs │ │ ├── SpotLightShadow.cs │ │ ├── HemisphereLight.cs │ │ ├── DirectionalLight.cs │ │ ├── RectAreaLight.cs │ │ ├── LightProbe.cs │ │ ├── PointLight.cs │ │ ├── Light.cs │ │ ├── SpotLight.cs │ │ └── PointLightShadow.cs │ ├── Loaders │ │ ├── FontLoader.cs │ │ ├── CubeTextureLoader.cs │ │ ├── TextureLoader.cs │ │ └── BufferGeometryLoader.cs │ ├── Core │ │ ├── IBufferAttribute.cs │ │ ├── GLObject.cs │ │ ├── GeometryGroup.cs │ │ ├── Layers.cs │ │ ├── InstancedInterleavedBuffer.cs │ │ ├── InstancedBufferAttribute.cs │ │ ├── DisposableObject.cs │ │ ├── BasicObject.cs │ │ ├── InstancedBufferGeometry.cs │ │ ├── Face3.cs │ │ ├── InterleavedBuffer.cs │ │ └── GLBufferAttribute.cs │ ├── Objects │ │ ├── Bone.cs │ │ ├── LineLoop.cs │ │ └── Group.cs │ ├── Scenes │ │ ├── FogExp2.cs │ │ ├── SceneUtils.cs │ │ ├── Fog.cs │ │ └── Scene.cs │ ├── AvaloniaGraphicsContext.cs │ ├── app.config │ ├── Cameras │ │ └── ArrayCamera.cs │ ├── Textures │ │ ├── DataTexture3D.cs │ │ ├── DataTexture2DArray.cs │ │ ├── VideoTexture.cs │ │ ├── CompressedTexture.cs │ │ ├── CubeTexture.cs │ │ ├── DataTexture.cs │ │ └── DepthTexture.cs │ ├── ControlsContainer.cs │ ├── Helpers │ │ ├── TreeHelpers.cs │ │ ├── AxesHelper.cs │ │ ├── PointLightHelper.cs │ │ ├── GridHelper.cs │ │ └── PlaneHelper.cs │ ├── Shaders │ │ ├── CopyShader.cs │ │ ├── GammaCorrectionShader.cs │ │ ├── LuminosityShader.cs │ │ ├── PixelShader.cs │ │ ├── ColorifyShader.cs │ │ ├── RGBShiftShader.cs │ │ ├── MirrorShader.cs │ │ ├── KaleidoShader.cs │ │ ├── SepiaShader.cs │ │ ├── ColorCorrectionShader.cs │ │ ├── BrightnessContrastShader.cs │ │ ├── TriangleBlurShader.cs │ │ ├── LuminosityHighPassShader.cs │ │ ├── BleachBypassShader.cs │ │ ├── DotScreenShader.cs │ │ ├── VignetteShader.cs │ │ ├── VerticalBlurShader.cs │ │ ├── HorizontalBlurShader.cs │ │ ├── HueSaturationShader.cs │ │ ├── VerticalTiltShiftShader.cs │ │ ├── HorizontalTiltShiftShader.cs │ │ ├── FilmShader.cs │ │ └── ConvolutionShader.cs │ ├── THREE.Avalonia.csproj │ ├── Postprocessing │ │ ├── ClearPass.cs │ │ ├── TexturePass.cs │ │ ├── ShaderPass.cs │ │ ├── DotScreenPass.cs │ │ ├── FilmPass.cs │ │ └── HalftonePass.cs │ ├── InteractiveThreeControlBase.cs │ └── IControlsContainer.cs ├── THREE.Avalonia.TestApp │ ├── Assets │ │ ├── Scene.glb │ │ ├── boss.glb │ │ ├── scene1.glb │ │ ├── teapot.bin │ │ ├── textures │ │ │ ├── T_AK.jpg │ │ │ ├── cat.png │ │ │ ├── T_Batya.jpg │ │ │ ├── T_Dutch.jpg │ │ │ ├── T_Joe.jpg │ │ │ ├── T_Joe_2.jpg │ │ │ ├── Bomb_Base.jpg │ │ │ ├── T_Shotgun.jpg │ │ │ ├── T_roadSet.PNG │ │ │ ├── test-dxt1.dds │ │ │ ├── test-dxt1.jpg │ │ │ ├── Bricks_Base.jpg │ │ │ ├── Grass_1_Base.jpg │ │ │ ├── T_Container.jpg │ │ │ ├── T_Dutch_Patrol.jpg │ │ │ ├── T_PoliceCar_01.PNG │ │ │ └── T_colorPalette.PNG │ │ ├── zombies_male.glb │ │ ├── 2CylinderEngine.glb │ │ ├── PB_TC_SniperMission_Scene2.glb │ │ └── butterfly │ │ │ ├── butterflywings.png │ │ │ └── butterfly.mtl │ └── Program.cs ├── THREE.GltfLoader │ ├── Extensions │ │ ├── IMaterialExtension.cs │ │ └── GLTFMaterialsIorExtension.cs │ └── THREE.Loaders.GltfLoader.csproj └── THREE.Avalonia.sln ├── LICENSE.txt └── .gitattributes /README.md: -------------------------------------------------------------------------------- 1 | # THREE.Avalonia -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/GlobalUsing.cs: -------------------------------------------------------------------------------- 1 | global using IGraphicsContext = OpenTK.Windowing.Common.IGraphicsContext; -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Resources/ltc_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia/Resources/ltc_1.png -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Resources/ltc_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia/Resources/ltc_2.png -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/Scene.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/Scene.glb -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/boss.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/boss.glb -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/scene1.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/scene1.glb -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/teapot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/teapot.bin -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Curves/LineCurve.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class LineCurve : Curve 5 | { 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_AK.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_AK.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/cat.png -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/zombies_male.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/zombies_male.glb -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/WireframeGeometry.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE 3 | { 4 | [Serializable] 5 | public class WireframeGeometry 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/IExtensionsProvider.cs: -------------------------------------------------------------------------------- 1 | namespace THREE; 2 | 3 | public interface IExtensionsProvider 4 | { 5 | HashSet Extensions { get; } 6 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/2CylinderEngine.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/2CylinderEngine.glb -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Batya.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Batya.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Dutch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Dutch.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Joe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Joe.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Joe_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Joe_2.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/Bomb_Base.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/Bomb_Base.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Shotgun.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Shotgun.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_roadSet.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_roadSet.PNG -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/test-dxt1.dds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/test-dxt1.dds -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/test-dxt1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/test-dxt1.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/Bricks_Base.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/Bricks_Base.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/Grass_1_Base.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/Grass_1_Base.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Container.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Container.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_Dutch_Patrol.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_Dutch_Patrol.jpg -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_PoliceCar_01.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_PoliceCar_01.PNG -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/textures/T_colorPalette.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/textures/T_colorPalette.PNG -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/PB_TC_SniperMission_Scene2.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/PB_TC_SniperMission_Scene2.glb -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/butterfly/butterflywings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gritsenko/THREE.Avalonia/master/Sources/THREE.Avalonia.TestApp/Assets/butterfly/butterflywings.png -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/IGLProgram.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace THREE 6 | { 7 | public interface IGLProgram 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/UniformLocation.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public struct UniformLocation 5 | { 6 | public GLUniform Uniform; 7 | public int Location; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Math/Cylindrical.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE 3 | { 4 | [Serializable] 5 | public class Cylindrical 6 | { 7 | public float Radius; 8 | public float Theta; 9 | public float Y; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/IGLAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace THREE 4 | { 5 | public interface IGLAttribute 6 | { 7 | string Name { get; set; } 8 | Type Type { get; set; } 9 | int ItemSize { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extensions/ThreeObjectExtension.cs: -------------------------------------------------------------------------------- 1 | namespace THREE; 2 | 3 | [Serializable] 4 | public static class ThreeObjectExtension 5 | { 6 | public static T DeepCopy(this T source) where T : new() 7 | { 8 | return (T)FastDeepCloner.DeepCloner.Clone(source); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/DirectionalLightShadow.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class DirectionalLightShadow : LightShadow 5 | { 6 | public DirectionalLightShadow() : base(new OrthographicCamera(-5, 5, 5, -5, 0.5f, 500)) 7 | { 8 | 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Loaders/FontLoader.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class FontLoader 5 | { 6 | public FontLoader() 7 | { 8 | 9 | } 10 | public static Font Load(string jsonFile) 11 | { 12 | return new Font(jsonFile); 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/IBufferAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | public interface IBufferAttribute 6 | { 7 | bool NeedsUpdate { get; set; } 8 | 9 | int Buffer { get; set; } 10 | 11 | int Length { get; } 12 | 13 | int ItemSize { get; } 14 | 15 | Type Type { get; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/THREE.GltfLoader/Extensions/IMaterialExtension.cs: -------------------------------------------------------------------------------- 1 | using THREE; 2 | 3 | namespace OpenGLTest.Loaders.Extensions; 4 | 5 | public interface IMaterialExtension 6 | { 7 | string Name { get; } 8 | THREE.Material GetMaterial(); 9 | } 10 | 11 | public interface IMaterialExtension : IMaterialExtension 12 | { 13 | void ApplyMaterialParams(object param); 14 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Objects/Bone.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class Bone : Object3D 8 | { 9 | public Bone() : base() 10 | { 11 | this.type = "Bone"; 12 | } 13 | public Bone(SerializationInfo info, StreamingContext context) : base(info, context) { } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Scenes/FogExp2.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE 3 | { 4 | [Serializable] 5 | public class FogExp2 : Fog 6 | { 7 | 8 | public float Density; 9 | 10 | public FogExp2(Color color, float? density = null) 11 | { 12 | this.Name = ""; 13 | this.Density = density != null ? density.Value : (float)0.00025; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Curves/ArcCurve.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class ArcCurve : EllipseCurve 5 | { 6 | public ArcCurve(float? aX = null, float? aY = null, float? aRadius = null, float? aStartAngle = null, float? aEndAngle = null, bool? clockwise = null) : base(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, clockwise, null) 7 | { 8 | 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Objects/LineLoop.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class LineLoop : Line 8 | { 9 | 10 | public LineLoop(Geometry geometry, Material material) : base(geometry, material) 11 | { 12 | } 13 | public LineLoop(SerializationInfo info, StreamingContext context) : base(info, context) { } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/GLMultisampleRenderTarget.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLMultisampleRenderTarget : GLRenderTarget 8 | { 9 | public int Samples = 4; 10 | public GLMultisampleRenderTarget(int width, int height, Hashtable option = null) 11 | : base(width, height, option) 12 | { 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/GLObject.cs: -------------------------------------------------------------------------------- 1 | using THREE; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class GLObject 7 | { 8 | public long Id { get; set; } 9 | 10 | public BaseGeometry buffer {get;set; } 11 | 12 | public Object3D object3D { get; set; } 13 | 14 | public Material material { get; set; } 15 | 16 | public float z { get; set; } 17 | 18 | public bool render { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Objects/Group.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class Group : Object3D 8 | { 9 | public List MaterialLibraries; 10 | 11 | public Group() 12 | : base() 13 | { 14 | } 15 | public Group(SerializationInfo info, StreamingContext context) : base(info, context) { } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class GLAttribute : Dictionary,IGLAttribute 7 | { 8 | public string Name { get; set; } 9 | public Type Type { get; set; } 10 | public int ItemSize { get; set; } 11 | //public VertexAttribPointerType type; 12 | 13 | //public int bytesPerElement; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLShader.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class GLShader 5 | { 6 | public string Name { get; set; } 7 | public int Type { get; set; } 8 | public string Code { get; set; } 9 | public string VertexShader { get; set; } 10 | public string FragmentShader { get; set; } 11 | public GLUniforms Uniforms { get; set; } 12 | 13 | public int ShaderId { get; set; } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/IGLTextures.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace THREE 6 | { 7 | public interface IGLTextures 8 | { 9 | int AllocateTextureUnit(); 10 | void SafeSetTexture2D(Texture texture, int slot); 11 | void SetTexture3D(Texture texture, int slot); 12 | void SafeSetTextureCube(Texture texture, int slot); 13 | void SetTexture2DArray(Texture texture, int slot); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/AvaloniaGraphicsContext.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.OpenGL; 2 | 3 | namespace THREE; 4 | 5 | public class AvaloniaGraphicsContext(GlInterface gl) : IGraphicsContext 6 | { 7 | public void SwapBuffers() => throw new NotImplementedException(); 8 | 9 | public void MakeCurrent() => throw new NotImplementedException(); 10 | 11 | public void MakeNoneCurrent() => throw new NotImplementedException(); 12 | 13 | public bool IsCurrent => true; 14 | public int SwapInterval { get; set; } 15 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshMatcapMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class MeshMatcapMaterial : Material 7 | { 8 | public Texture Matcap; 9 | 10 | public MeshMatcapMaterial() 11 | : base() 12 | { 13 | this.type = "MeshMatcapMaterial"; 14 | } 15 | 16 | public MeshMatcapMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/GLMultiviewRenderTarget.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class GLMultiviewRenderTarget : GLRenderTarget 7 | { 8 | public int numViews; 9 | 10 | public GLMultiviewRenderTarget(int width, int height, int numViews, Hashtable options = null) : base(width, height, options) 11 | { 12 | this.IsGLMultiviewRenderTarget = true; 13 | this.numViews = numViews; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshFaceMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class MeshFaceMaterial : Material 8 | { 9 | public List Materials; 10 | 11 | public MeshFaceMaterial() : base() 12 | { 13 | this.type = "MeshFaceMaterial"; 14 | } 15 | public MeshFaceMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/ShadowMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class ShadowMaterial : Material 7 | { 8 | public ShadowMaterial() 9 | { 10 | this.type = "ShadowMaterial"; 11 | 12 | this.Transparent = true; 13 | 14 | this.Color = new Color().SetHex(0x000000); 15 | } 16 | public ShadowMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/RawShaderMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class RawShaderMaterial : ShaderMaterial 8 | { 9 | public RawShaderMaterial(Hashtable parameters = null) 10 | { 11 | this.type = "RawShaderMaterial"; 12 | 13 | this.SetValues(parameters); 14 | } 15 | public RawShaderMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Scenes/SceneUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class SceneUtils 8 | { 9 | public static Group CreateMultiMaterialObject(Geometry geometry, List materials) 10 | { 11 | Group group = new Group(); 12 | 13 | for (int i = 0; i < materials.Count; i++) 14 | { 15 | group.Add(new Mesh(geometry, materials[i])); 16 | } 17 | return group; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Sources/THREE.GltfLoader/THREE.Loaders.GltfLoader.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | enable 6 | THREE.Loaders 7 | latest 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/IStructuredUniform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Text; 6 | using THREE.Renderers.Shaders; 7 | 8 | namespace THREE 9 | { 10 | public interface IStructuredUniform 11 | { 12 | public List Seq { get; set; } 13 | void SetValue(IStructuredUniform uniform, object value, IGLTextures textures = null); 14 | void SetValue(object value, IGLTextures textures); 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Cameras/ArrayCamera.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace THREE 8 | { 9 | [Serializable] 10 | public class ArrayCamera : PerspectiveCamera 11 | { 12 | public List Cameras = new List(); 13 | 14 | 15 | public ArrayCamera() : base() 16 | { 17 | 18 | } 19 | public ArrayCamera(List array) 20 | : base() 21 | { 22 | this.Cameras = array; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/AmbientLight.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class AmbientLight : Light 7 | { 8 | public AmbientLight(Color color, float? intensity = null) 9 | : base(color, intensity) 10 | { 11 | this.type = "AmbientLight"; 12 | } 13 | public AmbientLight(SerializationInfo info, StreamingContext context) : base(info, context) { } 14 | 15 | public AmbientLight(int color, float? intensity = null) : this(Color.Hex(color), intensity) { } 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/LineDashedMaterial.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class LineDashedMaterial : LineBasicMaterial 8 | { 9 | public float Scale = 1; 10 | 11 | public float DashSize = 3; 12 | 13 | public float GapSize = 1; 14 | 15 | public LineDashedMaterial() : base() 16 | { 17 | this.type = "LineDashedMaterial"; 18 | } 19 | public LineDashedMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Objects/ImmediateRenderObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class ImmediateRenderObject : Object3D 7 | { 8 | public ImmediateRenderObject(Material material) : base() 9 | { 10 | this.Material = material; 11 | } 12 | 13 | protected ImmediateRenderObject(ImmediateRenderObject other) : base(other) 14 | { 15 | this.Material = (Material)other.Material.Clone(); 16 | } 17 | 18 | public void Render(Action renderCAllback) 19 | { 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Program.cs: -------------------------------------------------------------------------------- 1 | var lifetime = new ClassicDesktopStyleApplicationLifetime { Args = args, ShutdownMode = ShutdownMode.OnLastWindowClose }; 2 | AppBuilder.Configure() 3 | .UsePlatformDetect() 4 | .SetupWithLifetime(lifetime); 5 | 6 | var wnd = new Window() { Title = "Avalonia OpenGl", Width = 800, Height = 600 } 7 | .Content( 8 | new Grid() { Background = Brushes.WhiteSmoke } 9 | .Cols("*,*") 10 | .Children( 11 | new OpenGLTest.ThreeView().ColSpan(2) 12 | ) 13 | ); 14 | 15 | lifetime.MainWindow = wnd; 16 | lifetime.Start(args); -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extensions/ShaderExtension.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace THREE 9 | { 10 | [Serializable] 11 | public static class ShaderExtension 12 | { 13 | public static void SetShaderType(this GLShader shader, ShaderType type, string code) 14 | { 15 | shader.Type = (int)type; 16 | 17 | shader.Code = code; 18 | 19 | shader.ShaderId = GL.CreateShader(type); 20 | 21 | GL.ShaderSource(shader.ShaderId, code); 22 | 23 | GL.CompileShader(shader.ShaderId); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/DataTexture3D.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class DataTexture3D : Texture 5 | { 6 | public int Width; 7 | public int Height; 8 | public int Depth; 9 | 10 | public byte[] Data; 11 | 12 | public DataTexture3D(byte[] array, int width, int height, int depth) : base() 13 | { 14 | this.Data = array; 15 | this.Width = width; 16 | this.Height = height; 17 | 18 | this.WrapR = Constants.ClampToEdgeWrapping; 19 | 20 | this.GenerateMipmaps = false; 21 | 22 | this.flipY = false; 23 | 24 | this.NeedsUpdate = true; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/DataTexture2DArray.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class DataTexture2DArray : Texture 5 | { 6 | public int Width; 7 | public int Height; 8 | public int Depth; 9 | 10 | public byte[] Data; 11 | 12 | public DataTexture2DArray(byte[] array, int width, int height, int depth) : base() 13 | { 14 | this.Data = array; 15 | this.Width = width; 16 | this.Height = height; 17 | 18 | this.WrapR = Constants.ClampToEdgeWrapping; 19 | 20 | this.GenerateMipmaps = false; 21 | 22 | this.flipY = false; 23 | 24 | this.NeedsUpdate = true; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/VideoTexture.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System.Drawing; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class VideoTexture : Texture 8 | { 9 | public VideoTexture(SKBitmap video = null, int? mapping = null, int wrapS = 0, int wrapT = 0, int magFilter = 0, int minFilter = 0, int format = 0, int type = 0, int anisotropy = 1) 10 | : base(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, null) 11 | { 12 | this.GenerateMipmaps = false; 13 | 14 | } 15 | public void Update() 16 | { 17 | var video = this.Image; 18 | 19 | this.NeedsUpdate = true; 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Scenes/Fog.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE 3 | { 4 | [Serializable] 5 | public class Fog 6 | { 7 | public string Name; 8 | 9 | public Color Color; 10 | 11 | public float Near; 12 | 13 | public float Far; 14 | 15 | public Fog() 16 | { 17 | } 18 | public Fog(Color color, float? near = null, float? far = null) 19 | { 20 | this.Name = ""; 21 | 22 | this.Color = color; 23 | 24 | this.Near = near != null ? near.Value : 1; 25 | 26 | this.Far = far != null ? far.Value : 1000; 27 | 28 | } 29 | public Fog(int color, float? near = null, float? far = null) : this(Color.Hex(color), near, far) { } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/PointsMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class PointsMaterial : Material 7 | { 8 | public float Size = 1; 9 | 10 | public PointsMaterial() : base() 11 | { 12 | this.type = "PointsMaterial"; 13 | 14 | this.Color = new Color().SetHex(0xffffff); 15 | 16 | this.Map = null; 17 | 18 | this.AlphaMap = null; 19 | 20 | this.Size = 1; 21 | 22 | this.SizeAttenuation = true; 23 | 24 | this.MorphTargets = false; 25 | } 26 | public PointsMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/GeometryGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class GeometryGroup : BaseGeometry 7 | { 8 | protected static int GeometryGroupIdCount; 9 | public GeometryGroup() 10 | { 11 | Id = GeometryGroupIdCount++; 12 | } 13 | public override void ComputeBoundingBox() 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | public override void ComputeBoundingSphere() 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | public override void ComputeVertexNormals(bool areaWeighted = false) 22 | { 23 | throw new NotImplementedException(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/ISingleUniform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | 6 | namespace THREE 7 | { 8 | public interface ISingleUniform 9 | { 10 | public void SetValue(int v); 11 | public void SetValue(float v); 12 | public void SetValue(Vector2 v); 13 | public void SetValue(Vector3 v); 14 | public void SetValue(Vector4 v); 15 | public void SetValue(Matrix3 matrix); 16 | public void SetValue(Matrix4 matrix); 17 | public void SetValue(Color color); 18 | public void SetValue(float[] color); 19 | 20 | public void SetValue(Texture v, IGLTextures textures); 21 | 22 | public void SetValue(object v, IGLTextures textures = null); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/SpriteMaterial.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class SpriteMaterial : Material 8 | { 9 | 10 | //public bool SizeAttenuation = true; 11 | 12 | public SpriteMaterial() 13 | { 14 | this.type = "SpriteMaterial"; 15 | 16 | this.Color = new Color().SetHex(0x000000); 17 | 18 | this.Transparent = true; 19 | 20 | this.Map = null; 21 | 22 | this.AlphaMap = null; 23 | 24 | this.Rotation = 0; 25 | 26 | this.SizeAttenuation = true; 27 | 28 | this.Transparent = true; 29 | 30 | } 31 | public SpriteMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshDepthMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class MeshDepthMaterial : Material 7 | { 8 | public MeshDepthMaterial() : base() 9 | { 10 | this.type = "MeshDepthMaterial"; 11 | 12 | this.Skinning = false; 13 | 14 | this.MorphTargets = false; 15 | 16 | this.AlphaMap = null; 17 | 18 | this.DisplacementMap = null; 19 | 20 | this.DisplacementScale = 1.0f; 21 | 22 | this.DisplacementBias = 0.0f; 23 | 24 | this.Wireframe = false; 25 | 26 | this.WireframeLineWidth = 1; 27 | 28 | this.Fog = false; 29 | 30 | } 31 | public MeshDepthMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/CompressedTexture.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class CompressedTexture : Texture 8 | { 9 | private int Width; 10 | private int Height; 11 | public CompressedTexture(List mipmaps, int width, int height, int? mapping = null, int? wrapS = null, int? wrapT = null, int? magFilter = null, int? minFilter = null, int? format = null, int? type = null, int? anisotropy = null, int? encoding = null) : 12 | base(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) 13 | { 14 | this.Width = width; 15 | this.Height = height; 16 | this.Mipmaps = mipmaps; 17 | 18 | this.flipY = false; 19 | 20 | this.GenerateMipmaps = false; 21 | 22 | } 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/ControlsContainer.cs: -------------------------------------------------------------------------------- 1 | namespace THREE; 2 | 3 | public class Keys 4 | { 5 | public const string Left = "Left"; 6 | public const string Right = "Right"; 7 | public const string Up = "Up"; 8 | public const string W = "W"; 9 | public const string A = "A"; 10 | public const string Down = "Down"; 11 | public const string S = "S"; 12 | public const string D = "D"; 13 | public const string R = "R"; 14 | public const string F = "F"; 15 | public const string Q = "Q"; 16 | public const string E = "E"; 17 | public const string LeftControl = nameof(LeftControl); 18 | public const string LeftShift = nameof(LeftShift); 19 | public const string RightShift = nameof(RightShift); 20 | public const string RightControl = nameof(RightControl); 21 | public static string LeftAlt = nameof(LeftAlt); 22 | public static string RightAlt = nameof(RightAlt); 23 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshDistanceMaterial.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class MeshDistanceMaterial : Material 8 | { 9 | public Vector3 ReferencePosition = Vector3.Zero(); 10 | 11 | public float NearDistance = 1; 12 | 13 | public float FarDistance = 1000; 14 | 15 | 16 | public MeshDistanceMaterial() : base() 17 | { 18 | this.type = "MeshDistanceMaterial"; 19 | 20 | this.Skinning = false; 21 | 22 | this.MorphTargets = false; 23 | 24 | this.DisplacementMap = null; 25 | 26 | this.DisplacementScale = 1; 27 | 28 | this.DisplacementBias = 0; 29 | 30 | this.Fog = false; 31 | } 32 | public MeshDistanceMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/THREE.GltfLoader/Extensions/GLTFMaterialsIorExtension.cs: -------------------------------------------------------------------------------- 1 | using THREE; 2 | 3 | namespace OpenGLTest.Loaders.Extensions; 4 | 5 | public class GltfMaterialsIorExtension : IMaterialExtension 6 | { 7 | public string Name => "SharpGLTF.Schema2.MaterialIOR"; 8 | public Material GetMaterial() => new MeshPhysicalMaterial(); 9 | 10 | public void ApplyMaterialParams(object param) 11 | { 12 | //materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5; 13 | } 14 | 15 | } 16 | public class GltfMaterialSpecularExtension : IMaterialExtension 17 | { 18 | public string Name => "SharpGLTF.Schema2.MaterialSpecular"; 19 | public Material GetMaterial() => new MeshPhysicalMaterial(); 20 | 21 | public void ApplyMaterialParams(object param) 22 | { 23 | //materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/SpotLightShadow.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class SpotLightShadow : LightShadow 5 | { 6 | public SpotLightShadow() 7 | : base(new PerspectiveCamera(50, 1, 0.5f, 500)) 8 | { 9 | } 10 | 11 | public override void UpdateMatrices(Light light) 12 | { 13 | var fov = 180 / System.Math.PI * 2 * light.Angle; 14 | var aspect = this.MapSize.X / this.MapSize.Y; 15 | var far = light.Distance != 0 ? light.Distance : Camera.Far; 16 | 17 | if (fov != Camera.Fov || aspect != Camera.Aspect || far != Camera.Far) 18 | { 19 | Camera.Fov = (float)fov; 20 | Camera.Aspect = aspect; 21 | Camera.Far = far; 22 | Camera.UpdateProjectionMatrix(); 23 | } 24 | base.UpdateMatrices(light); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Core/CurveInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace THREE 6 | { 7 | public interface CurveInterface 8 | { 9 | 10 | Vector3 GetPoint(float t, Vector3 optionalTarget = null); 11 | 12 | Vector3 GetPointAt(float u, Vector3 optionalTarget = null); 13 | 14 | List GetPoints(float? divisions = null); 15 | 16 | 17 | List GetSpacedPoints(float? divisions = null); 18 | 19 | float GetLength(); 20 | 21 | List GetLengths(float? divisions = null); 22 | 23 | void UpdateArcLengths(); 24 | 25 | float GetUtoTmapping(float u, float? distance = null); 26 | 27 | Vector3 GetTangent(float t); 28 | 29 | Vector3 GetTangentAt(float u); 30 | 31 | Hashtable ComputeFrenetFrames(int segments, bool closed); 32 | 33 | object Clone(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshPhysicalMaterial.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class MeshPhysicalMaterial : MeshStandardMaterial 8 | { 9 | 10 | public float Transparency = 0.0f; 11 | 12 | public MeshPhysicalMaterial() : base() 13 | { 14 | this.type = "MeshPhysicalMaterial"; 15 | 16 | //this.Defines.Add("STANDARD", ""); already inserted from MeshStandardMaterial 17 | this.Defines.Add("PHYSICAL", ""); 18 | 19 | this.Clearcoat = 0.0f; 20 | this.ClearcoatRoughness = 0.0f; 21 | 22 | this.Reflectivity = 0.5f; 23 | 24 | this.ClearcoatNormalScale = new Vector2(1, 1); 25 | 26 | this.ClearcoatNormalMap = null; 27 | } 28 | 29 | public MeshPhysicalMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Scenes/Scene.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class Scene : Object3D 8 | { 9 | public Fog Fog; 10 | 11 | public Material OverrideMaterial; 12 | 13 | public bool AutoUpdate; 14 | 15 | public object Background = null; 16 | 17 | public bool ClearBeforeRender = true; 18 | 19 | public Texture Environment; 20 | 21 | public bool IsScene = true; 22 | public Scene() 23 | { 24 | this.type = "Scene"; 25 | this.Background = null; 26 | this.Environment = null; 27 | this.Fog = null; 28 | this.OverrideMaterial = null; 29 | 30 | this.AutoUpdate = true; 31 | } 32 | public Scene(SerializationInfo info, StreamingContext context) : base(info, context) { } 33 | 34 | public virtual void Resize(float width, float height) 35 | { 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.TestApp/Assets/butterfly/butterfly.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'butterfly.blend' 2 | # Material Count: 4 3 | newmtl butterfly_body 4 | Ns 0.000000 5 | Ka 0.000000 0.000000 0.000000 6 | Kd 0.564706 0.329412 0.599216 7 | Ks 0.000000 0.000000 0.000000 8 | Ni 1.000000 9 | d 1.000000 10 | illum 1 11 | 12 | 13 | newmtl butterfly_eyes 14 | Ns 65.007344 15 | Ka 0.000000 0.000000 0.000000 16 | Kd 0.000000 0.000000 0.000000 17 | Ks 2.000000 2.000000 2.000000 18 | Ni 1.000000 19 | d 1.000000 20 | illum 2 21 | 22 | 23 | newmtl butterfly_legs 24 | Ns 0.000000 25 | Ka 0.000000 0.000000 0.000000 26 | Kd 0.375324 0.157953 0.402333 27 | Ks 0.000000 0.000000 0.000000 28 | Ni 1.000000 29 | d 1.000000 30 | illum 1 31 | 32 | 33 | newmtl butterfly_wings_butterflywings.png 34 | Ns 21.568627 35 | Ka 0.000000 0.000000 0.000000 36 | Kd 0.664280 0.453170 0.744248 37 | Ks 0.124165 0.124165 0.124165 38 | Ni 1.000000 39 | d 0.000000 40 | illum 2 41 | 42 | #change these 43 | map_Kd butterflywings.png 44 | map_d butterflywings.png 45 | 46 | 47 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Loaders/CubeTextureLoader.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class CubeTextureLoader 9 | { 10 | public CubeTextureLoader() 11 | { 12 | 13 | } 14 | public static CubeTexture Load(List filePath) 15 | { 16 | CubeTexture texture = new CubeTexture(); 17 | for (int i = 0; i < filePath.Count; i++) 18 | { 19 | SKBitmap bitmap = SKBitmap.Decode(filePath[i]); 20 | //bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); 21 | 22 | Texture image = new Texture(); 23 | image.Image = bitmap; 24 | image.Format = Constants.RGBFormat; 25 | image.NeedsUpdate = true; 26 | 27 | texture.Images[i] = image; 28 | } 29 | texture.NeedsUpdate = true; 30 | return texture; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLUniforms.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLUniforms : StructuredUniform 8 | { 9 | public int Program { get; set; } = 0; 10 | public GLUniforms() :base() 11 | { 12 | UniformKind = "GLUniforms"; 13 | } 14 | public GLUniforms(string id) : base(id) 15 | { 16 | UniformKind = "GLUniforms"; 17 | } 18 | public GLUniforms(string id, string kind) : base(id) 19 | { 20 | UniformKind = kind; 21 | } 22 | public GLUniforms(SerializationInfo info, StreamingContext context) : base(info, context) { } 23 | 24 | public new object Clone() 25 | { 26 | return this.DeepCopy(); 27 | } 28 | 29 | public GLUniforms Copy(GLUniforms original) 30 | { 31 | return original.DeepCopy(); 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/IPureArrayUniform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Text; 5 | 6 | namespace THREE 7 | { 8 | public interface IPureArrayUniform 9 | { 10 | int Size { get; set; } 11 | void UpdateCache(object[] data); 12 | void UpdateCache(List data); 13 | void SetValue(float[] v); 14 | void SetValue(Vector2 v); 15 | void SetValue(Vector3 v); 16 | void SetValue(Vector2[] v); // setValueV2fArray 17 | void SetValue(Vector3[] v);// setValueV3fArray 18 | void SetValue(Color[] v); 19 | void SetValue(Vector4[] v); 20 | // setValueM3Array 21 | void SetValue(Matrix3[] v); 22 | // setValueM4Array 23 | void SetValue(Matrix4[] v); 24 | 25 | // Array of textures(2D/Cube) 26 | //setValueT1Array 27 | void SetValue(Texture[] v, IGLTextures textures); 28 | void SetValue(object v, IGLTextures textures = null); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Helpers/TreeHelpers.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class TreeHelpers 5 | { 6 | public static LineSegments AxesHelper(int size) 7 | { 8 | float[] vertices = 9 | { 10 | 0,0,0,size,0,0, 11 | 0,0,0,0,size,0, 12 | 0,0,0,0,0,size 13 | }; 14 | 15 | float[] colors = 16 | { 17 | 1,0,0, 1,0.6f,0, 18 | 0,1,0, 0.6f,1,0, 19 | 0,0,0, 0,0.6f,1 20 | }; 21 | 22 | var geometry = new BufferGeometry(); 23 | geometry.SetAttribute("position", new BufferAttribute(vertices, 3)); 24 | geometry.SetAttribute("color", new BufferAttribute(colors, 3)); 25 | 26 | var material = new LineBasicMaterial(); 27 | 28 | material.VertexColors = Constants.VertexColors > 0 ? true : false; 29 | 30 | return new LineSegments(geometry, material); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/HemisphereLight.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class HemisphereLight : Light 7 | { 8 | public HemisphereLight(Color skyColor, Color groundColor, float? itensity = null) 9 | : base(skyColor, itensity) 10 | { 11 | this.CastShadow = false; 12 | 13 | this.Position.Copy(Object3D.DefaultUp); 14 | 15 | this.UpdateMatrix(); 16 | 17 | this.GroundColor = groundColor; 18 | 19 | this.type = "HemisphereLight"; 20 | } 21 | public HemisphereLight(int color, int gcolor, float? intensity) : this(Color.Hex(color), Color.Hex(gcolor), intensity) { } 22 | 23 | public HemisphereLight(SerializationInfo info, StreamingContext context) : base(info, context) { } 24 | 25 | protected HemisphereLight(HemisphereLight other) : base(other) 26 | { 27 | this.type = "HemisphereLight"; 28 | this.GroundColor = other.GroundColor; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshNormalMaterial.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class MeshNormalMaterial : Material 8 | { 9 | public MeshNormalMaterial() : base() 10 | { 11 | this.type = "MeshNormalMaterial"; 12 | 13 | this.BumpMap = null; 14 | this.BumpScale = 1; 15 | 16 | this.NormalMap = null; 17 | this.NormalMapType = Constants.TangentSpaceNormalMap; 18 | this.NormalScale = new Vector2(1, 1); 19 | 20 | this.DisplacementMap = null; 21 | this.DisplacementScale = 1; 22 | this.DisplacementBias = 0; 23 | 24 | this.Wireframe = false; 25 | this.WireframeLineWidth = 1; 26 | 27 | this.Fog = false; 28 | 29 | this.Skinning = false; 30 | this.MorphTargets = false; 31 | this.MorphNormals = false; 32 | } 33 | public MeshNormalMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/Layers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class Layers 7 | { 8 | public int Mask = 1 | 0; 9 | 10 | public Layers() 11 | { 12 | } 13 | 14 | public void Set(int channel) 15 | { 16 | this.Mask = 1 << channel | 0; 17 | } 18 | 19 | public void Enable(int channel) 20 | { 21 | this.Mask |= 1 << channel | 0; 22 | } 23 | 24 | public void EnableAll() 25 | { 26 | this.Mask = Convert.ToInt32(0xffffffff | 0); 27 | } 28 | 29 | public void Toggle(int channel) 30 | { 31 | this.Mask ^= 1 << channel | 0; 32 | } 33 | 34 | public void Disable(int channel) 35 | { 36 | this.Mask &= ~(1 << channel | 0); 37 | } 38 | 39 | public void DisableAll() 40 | { 41 | this.Mask = 0; 42 | } 43 | public bool Test(Layers layers) 44 | { 45 | return (this.Mask & layers.Mask) != 0; 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/CubeTexture.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE 3 | { 4 | [Serializable] 5 | public class CubeTexture : Texture 6 | { 7 | public CubeTexture() : base() 8 | { 9 | this.Mapping = Constants.CubeReflectionMapping; 10 | this.Format = Constants.RGBAFormat; 11 | 12 | this.flipY = false; 13 | } 14 | public CubeTexture(Texture[] images, int? mapping = null, int? wrapS = null, int? wrapT = null, int? magFilter = null, int? minFilter = null, int? format = null, int? type = null, int? anisotropy = null, int? encoding = null) 15 | : base(null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) 16 | { 17 | if (images != null && images.Length > 0) 18 | Images = images; 19 | 20 | 21 | this.Mapping = mapping != null ? mapping.Value : (int)Constants.CubeReflectionMapping; 22 | this.Format = format != null ? format.Value : (int)Constants.RGBAFormat; 23 | this.NeedsFlipEnvMap = true; 24 | this.flipY = false; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/ConeGeometry.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | //float radiusTop, float radiusBottom ,float height, int? radialSegments=null, int? heightSegments=null, bool? openEnded = null, float? thetaStart = null, float? thetaLength = null 5 | public class ConeGeometry : CylinderGeometry 6 | { 7 | public ConeGeometry(float radius, float height, int? radialSegments = null, int? heightSegments = null, bool? openEnded = null, float? thetaStart = null, float? thetaLength = null) : 8 | base(0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) 9 | { 10 | 11 | } 12 | } 13 | 14 | [Serializable] 15 | public class ConeBufferGeometry : CylinderBufferGeometry 16 | { 17 | public ConeBufferGeometry(float radius, float height, int? radialSegments = null, int? heightSegments = null, bool? openEnded = null, float? thetaStart = null, float? thetaLength = null) : 18 | base(0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) 19 | { 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLUniform.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Runtime.Serialization; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class GLUniform : Dictionary,ICloneable 9 | { 10 | public string Id { get; set; } 11 | 12 | public int Addr { get; set; } 13 | 14 | public string UniformKind { get; set; } 15 | 16 | public int UniformType { get; set; } 17 | 18 | public List Cache = new List(); 19 | 20 | public GLUniform() : base() 21 | { 22 | UniformKind = "GLUniform"; 23 | } 24 | 25 | public GLUniform(string id) : this() 26 | { 27 | Id = id; 28 | } 29 | 30 | public GLUniform(SerializationInfo info, StreamingContext context) : base(info, context) { } 31 | 32 | public object Clone() 33 | { 34 | return this.DeepCopy(); 35 | } 36 | 37 | public GLUniform Copy(GLUniform original) 38 | { 39 | return original.DeepCopy(); 40 | } 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/InstancedInterleavedBuffer.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class InstancedInterleavedBuffer : InterleavedBuffer 7 | { 8 | public int MeshPerAttribute 9 | { 10 | get 11 | { 12 | return (int)this["meshPerAttribute"]; 13 | } 14 | set 15 | { 16 | this["meshPerAttribute"] = value; 17 | } 18 | } 19 | 20 | public InstancedInterleavedBuffer() 21 | { 22 | this.Add("meshPerAttribute", 1); 23 | } 24 | public InstancedInterleavedBuffer(SerializationInfo info, StreamingContext context) : base(info, context) { } 25 | 26 | public InstancedInterleavedBuffer(T[] array, int stride, int? meshPerAttribute = null) : this() 27 | { 28 | this.Array = array; 29 | this.Stride = stride; 30 | this.UpdateRange = new UpdateRange { Offset = 0, Count = -1 }; 31 | this.MeshPerAttribute = meshPerAttribute != null ? (int)meshPerAttribute : 1; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/Shaders/UniformsUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class UniformsUtils 9 | { 10 | public static GLUniforms CloneUniforms(GLUniforms src) 11 | { 12 | return src.Copy(src); 13 | } 14 | 15 | public static GLUniforms Merge(List uniforms) 16 | { 17 | var merged = new GLUniforms(); 18 | 19 | foreach (var uniform in uniforms) 20 | { 21 | foreach (var entry in uniform) 22 | { 23 | if (merged.ContainsKey(entry.Key)) 24 | { 25 | Trace.TraceWarning("key is already exist. this key skipped"); 26 | merged[entry.Key] = entry.Value; 27 | } 28 | else 29 | { 30 | merged.Add(entry.Key, entry.Value); 31 | } 32 | } 33 | } 34 | return merged; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/DirectionalLight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class DirectionalLight : Light, ICloneable 8 | { 9 | 10 | public DirectionalLight(Color color, float? intensity = null) : base(color, intensity) 11 | { 12 | this.Position.Copy(Object3D.DefaultUp); 13 | 14 | this.UpdateMatrix(); 15 | 16 | this.Target = new Object3D(); 17 | 18 | this.Shadow = new DirectionalLightShadow(); 19 | 20 | this.type = "DirectionalLight"; 21 | } 22 | public DirectionalLight() : this(new Color(), null) { } 23 | public DirectionalLight(int color, float? intensity = null) : this(Color.Hex(color), intensity) { } 24 | protected DirectionalLight(DirectionalLight other) : base(other) 25 | { 26 | this.Target = other.Target; 27 | 28 | this.type = "DirectionalLight"; 29 | 30 | this.Shadow = (LightShadow)other.Shadow.Clone(); 31 | } 32 | public DirectionalLight(SerializationInfo info, StreamingContext context) : base(info, context) { } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/DataTexture.cs: -------------------------------------------------------------------------------- 1 | 2 | using SkiaSharp; 3 | using System.Drawing; 4 | 5 | 6 | namespace THREE 7 | { 8 | [Serializable] 9 | public class DataTexture : Texture 10 | { 11 | public byte[] byteData; 12 | public float[] floatData; 13 | public int[] intData; 14 | 15 | public DataTexture() : base() { } 16 | public DataTexture(SKBitmap image, int width, int height, int format, int type, int? mapping = null, int? wrapS = null, int? wrapT = null, int? magFilter = null, int? minFilter = null, int? anisotropy = null, int? encoding = null) 17 | : base(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) 18 | { 19 | 20 | this.MagFilter = magFilter != null ? (int)magFilter : Constants.NearestFilter; 21 | this.MinFilter = minFilter != null ? (int)minFilter : Constants.NearestFilter; 22 | 23 | this.GenerateMipmaps = false; 24 | this.flipY = false; 25 | this.UnpackAlignment = 1; 26 | 27 | this.ImageSize.Width = width; 28 | this.ImageSize.Height = height; 29 | this.NeedsUpdate = true; 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/InstancedBufferAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class InstancedBufferAttribute : BufferAttribute 7 | { 8 | public int MeshPerAttribute = 1; 9 | 10 | 11 | public InstancedBufferAttribute() 12 | { 13 | 14 | } 15 | public InstancedBufferAttribute(SerializationInfo info, StreamingContext context) : base(info, context) { } 16 | 17 | public InstancedBufferAttribute(T[] array, int itemSize, bool? normalized = null, int? meshPerAttribute = null) 18 | : base(array, itemSize, normalized) 19 | { 20 | 21 | } 22 | protected InstancedBufferAttribute(InstancedBufferAttribute source) : this(source.Array, source.ItemSize, source.Normalized, source.MeshPerAttribute) 23 | { 24 | 25 | } 26 | public InstancedBufferAttribute Clone() 27 | { 28 | return new InstancedBufferAttribute(this); 29 | } 30 | public InstancedBufferAttribute Copy(InstancedBufferAttribute source) 31 | { 32 | return new InstancedBufferAttribute(source); 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/CopyShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class CopyShader : ShaderMaterial 7 | { 8 | public CopyShader() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("opacity", new GLUniform { { "value", 1.0f } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform float opacity; 30 | 31 | uniform sampler2D tDiffuse; 32 | 33 | varying vec2 vUv; 34 | 35 | void main() { 36 | 37 | vec4 texel = texture2D( tDiffuse, vUv ); 38 | gl_FragColor = opacity * texel; 39 | 40 | }" 41 | ; 42 | } 43 | 44 | public CopyShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Helpers/AxesHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class AxesHelper : LineSegments 7 | { 8 | public AxesHelper(int size) 9 | { 10 | float[] vertices = 11 | { 12 | 0,0,0,size,0,0, 13 | 0,0,0,0,size,0, 14 | 0,0,0,0,0,size 15 | }; 16 | 17 | float[] colors = 18 | { 19 | 1,0,0, 1,0.6f,0, 20 | 0,1,0, 0.6f,1,0, 21 | 0,0,0, 0,0.6f,1 22 | }; 23 | 24 | var geometry = new BufferGeometry(); 25 | geometry.SetAttribute("position", new BufferAttribute(vertices, 3)); 26 | geometry.SetAttribute("color", new BufferAttribute(colors, 3)); 27 | 28 | var material = new LineBasicMaterial() { ToneMapped = false }; 29 | 30 | material.VertexColors = Constants.VertexColors > 0 ? true : false; 31 | 32 | this.Geometry = geometry; 33 | this.Material = material; 34 | } 35 | public AxesHelper(SerializationInfo info, StreamingContext context) : base(info, context) { } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/RectAreaLight.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class RectAreaLight : Light 7 | { 8 | public RectAreaLight():base() 9 | { 10 | this.Width = 10; 11 | this.Height = 10; 12 | this.type = "RectAreaLight"; 13 | } 14 | public RectAreaLight(Color color, float? itensity = null, int? width = null, int? height = null) : base(color, itensity) 15 | { 16 | this.Width = (width != null) ? (int)width : 10; 17 | this.Height = (height != null) ? (int)height : 10; 18 | this.type = "RectAreaLight"; 19 | } 20 | public RectAreaLight(int color, float? itensity = null, int? width = null, int? height = null) : this(Color.Hex(color), itensity) 21 | { 22 | 23 | } 24 | public RectAreaLight(SerializationInfo info, StreamingContext context) : base(info, context) { } 25 | 26 | protected RectAreaLight(RectAreaLight other) : base(other) 27 | { 28 | this.Width = other.Width; 29 | this.Height = other.Height; 30 | this.type = "RectAreaLight"; 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/PointCloudMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class PointCloudMaterial : Material 8 | { 9 | //public Color Color = Color.White; 10 | 11 | // IMap 12 | 13 | //public Texture Map { get; set; } 14 | 15 | //public Texture AlphaMap { get; set; } 16 | 17 | //public Texture SpecularMap { get; set; } 18 | 19 | //public Texture NormalMap { get; set; } // TODO: not in ThreeJs, just to be an IMap. Must be NULL 20 | 21 | //public Texture BumpMap { get; set; } // TODO: not in ThreeJs, just to be an IMap. Must be NULL 22 | 23 | //public Texture LightMap { get; set; } 24 | 25 | //public Texture EnvMap { get; set; } 26 | 27 | public float Size = 1; 28 | 29 | //public bool SizeAttenuation = true; 30 | 31 | public PointCloudMaterial(Hashtable parameters = null) 32 | { 33 | this.type = "PointCloudMaterial"; 34 | 35 | this.SetValues(parameters); 36 | } 37 | 38 | public PointCloudMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/GammaCorrectionShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GammaCorrectionShader : ShaderMaterial 8 | { 9 | public GammaCorrectionShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform sampler2D tDiffuse; 30 | 31 | 32 | varying vec2 vUv; 33 | 34 | void main() { 35 | 36 | vec4 tex = texture2D( tDiffuse, vUv ); 37 | 38 | gl_FragColor = LinearTosRGB( tex ); // optional: LinearToGamma( tex, float( GAMMA_FACTOR ) ); 39 | 40 | } 41 | 42 | "; 43 | } 44 | 45 | public GammaCorrectionShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/LuminosityShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class LuminosityShader : ShaderMaterial 8 | { 9 | public LuminosityShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | 13 | 14 | VertexShader = @" 15 | varying vec2 vUv; 16 | 17 | 18 | void main() { 19 | 20 | vUv = uv; 21 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 22 | 23 | } 24 | 25 | 26 | " 27 | ; 28 | 29 | FragmentShader = @" 30 | #include 31 | 32 | 33 | uniform sampler2D tDiffuse; 34 | 35 | varying vec2 vUv; 36 | 37 | void main() { 38 | 39 | vec4 texel = texture2D( tDiffuse, vUv ); 40 | 41 | float l = linearToRelativeLuminance( texel.rgb ); 42 | 43 | gl_FragColor = vec4( l, l, l, texel.w ); 44 | 45 | } 46 | 47 | "; 48 | } 49 | 50 | public LuminosityShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/LightProbe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Runtime.Serialization; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class LightProbe : Light, ICloneable 9 | { 10 | 11 | public LightProbe() : base(Color.ColorName(ColorKeywords.white), null) 12 | { 13 | sh = new SphericalHarmonics3(); 14 | } 15 | public LightProbe(SerializationInfo info, StreamingContext context) : base(info, context) { } 16 | 17 | public LightProbe(SphericalHarmonics3 sh, int? intensity) : base(Color.ColorName(ColorKeywords.white), intensity) 18 | { 19 | if (sh != null) this.sh = sh; 20 | else sh = new SphericalHarmonics3(); 21 | } 22 | 23 | protected LightProbe(LightProbe other) 24 | { 25 | this.sh = (SphericalHarmonics3)other.sh.Clone(); 26 | this.Intensity = other.Intensity; 27 | } 28 | public LightProbe Copy(LightProbe source) 29 | { 30 | if (source.sh != null && source.sh.Coefficients.Count > 0) this.sh.Coefficients = source.sh.Coefficients.ToList(); ; 31 | Intensity = source.Intensity; 32 | return this; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/DisposableObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public abstract class DisposableObject 7 | { 8 | public event EventHandler Disposed; 9 | 10 | public DisposableObject() 11 | { 12 | 13 | } 14 | ~DisposableObject() 15 | { 16 | this.Dispose(false); 17 | } 18 | 19 | public bool IsDisposed() 20 | { 21 | return this.disposed; 22 | } 23 | 24 | public virtual void Dispose() 25 | { 26 | Dispose(disposed); 27 | } 28 | protected virtual void RaiseDisposed() 29 | { 30 | var handler = this.Disposed; 31 | if (handler != null) 32 | handler(this, new EventArgs()); 33 | } 34 | private bool disposed; 35 | protected virtual void Dispose(bool disposing) 36 | { 37 | if (this.disposed) return; 38 | try 39 | { 40 | this.RaiseDisposed(); 41 | this.disposed = true; 42 | } 43 | finally 44 | { 45 | 46 | } 47 | this.disposed = true; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLExtensions.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | using System.Collections.Generic; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLExtensions 8 | { 9 | public List ExtensionsName = new List(); 10 | public Dictionary Extensions = new Dictionary(); 11 | public GLExtensions() 12 | { 13 | ExtensionsName = new List((GL.GetString(StringName.Extensions)).Split(' ')); 14 | } 15 | public GLExtensions(IExtensionsProvider extensionsProvider) 16 | { 17 | ExtensionsName = extensionsProvider.Extensions.ToList(); 18 | } 19 | 20 | public int Get(string name) 21 | { 22 | int index = -1; 23 | 24 | int value; 25 | 26 | if (Extensions.TryGetValue(name, out value)) 27 | { 28 | return value; 29 | } 30 | else 31 | { 32 | index = ExtensionsName.IndexOf(name); 33 | if (index >= 0) 34 | { 35 | Extensions.Add(name, index); 36 | } 37 | return index; 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/THREE.Avalonia.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | latest 6 | enable 7 | enable 8 | True 9 | THREE 10 | THREE 11 | https://github.com/hjoykim/THREE/tree/master 12 | three.js opengl 13 | MIT 14 | True 15 | 1.0.0.1 16 | 1.0.0.1 17 | C# port of Three.js 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLRenderLists.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class GLRenderLists : Hashtable 7 | { 8 | GLProperties properties; 9 | public GLRenderLists(GLProperties properties) 10 | { 11 | this.properties = properties; 12 | } 13 | 14 | public GLRenderList Get(Scene scene, int renderCallDepth) 15 | { 16 | GLRenderList list = null; 17 | 18 | if (!this.ContainsKey(scene)) 19 | { 20 | list = new GLRenderList(properties); 21 | List lists = new List() { list }; 22 | 23 | this.Add(scene, lists); 24 | } 25 | else 26 | { 27 | 28 | if (renderCallDepth >= (this[scene] as List).Count) 29 | { 30 | list = new GLRenderList(properties); 31 | (this[scene] as List).Add(list); 32 | } 33 | else 34 | { 35 | list = (this[scene] as List)[renderCallDepth]; 36 | } 37 | } 38 | 39 | return list; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Textures/DepthTexture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class DepthTexture : Texture 7 | { 8 | 9 | public DepthTexture(int width, int height, int? type, int? mapping = null, int? wrapS = null, int? wrapT = null, int? magFilter = null, int? minFilter = null, int? anisotropy = null, int? format = null) 10 | : base(null, mapping, wrapS, wrapT, magFilter, minFilter, format, anisotropy) 11 | { 12 | this.Format = format != null ? (int)format : Constants.DepthFormat; 13 | 14 | if (this.Format != Constants.DepthFormat && this.Format != Constants.DepthStencilFormat) 15 | { 16 | throw new Exception("DepthTexture format must be either Constants.DepthFormat or Constants.DepthStencilFormat"); 17 | } 18 | 19 | if (type == 0 && this.Format == Constants.DepthFormat) this.Type = Constants.UnsignedShortType; 20 | if (type == 0 && this.Format == Constants.DepthStencilFormat) this.Type = Constants.UnsignedInt248Type; 21 | 22 | this.ImageSize.Width = width; 23 | this.ImageSize.Height = height; 24 | 25 | this.flipY = false; 26 | this.GenerateMipmaps = false; 27 | 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/BasicObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Runtime.Serialization; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public abstract class BasicObject : Hashtable, IDisposable 9 | { 10 | public event EventHandler Disposed; 11 | public BasicObject() 12 | { 13 | 14 | } 15 | public BasicObject(SerializationInfo info, StreamingContext context) : base(info, context) { } 16 | ~BasicObject() 17 | { 18 | this.Dispose(false); 19 | } 20 | public virtual void Dispose() 21 | { 22 | Dispose(disposed); 23 | } 24 | protected virtual void RaiseDisposed() 25 | { 26 | var handler = this.Disposed; 27 | if (handler != null) 28 | handler(this, new EventArgs()); 29 | } 30 | private bool disposed; 31 | protected virtual void Dispose(bool disposing) 32 | { 33 | if (this.disposed) return; 34 | try 35 | { 36 | this.RaiseDisposed(); 37 | this.disposed = true; 38 | } 39 | finally 40 | { 41 | 42 | } 43 | this.disposed = true; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/TetrahedronGeometry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class TetrahedronGeometry : Geometry 8 | { 9 | public Hashtable parameters; 10 | 11 | public TetrahedronGeometry(float? radius = null, float? detail = null) : base() 12 | { 13 | parameters = new Hashtable() 14 | { 15 | {"radius",radius }, 16 | { "detail",detail } 17 | }; 18 | 19 | this.FromBufferGeometry(new TetrahedronBufferGeometry(radius, detail)); 20 | this.MergeVertices(); 21 | } 22 | } 23 | 24 | [Serializable] 25 | public class TetrahedronBufferGeometry : PolyhedronBufferGeometry 26 | { 27 | static List vertices = new List() 28 | { 29 | 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1 30 | }; 31 | 32 | static List indices = new List() 33 | { 34 | 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1 35 | }; 36 | 37 | public TetrahedronBufferGeometry(float? radius = null, float? detail = null) : base(vertices, indices, radius, detail) 38 | { 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Helpers/PointLightHelper.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class PointLightHelper : Mesh 8 | { 9 | public Light Light; 10 | 11 | public Color? Color; 12 | 13 | public PointLightHelper(Light light, float? sphereSize = null, Color? color = null) : base() 14 | { 15 | this.Light = light; 16 | this.Light.UpdateMatrixWorld(); 17 | 18 | 19 | this.Color = color; 20 | 21 | 22 | var geometry = new SphereBufferGeometry(sphereSize != null ? sphereSize.Value : 1, 4, 2); 23 | var material = new MeshBasicMaterial() { Wireframe = true, Fog = false }; 24 | 25 | 26 | this.InitGeometry(geometry, material); 27 | 28 | 29 | this.Matrix = this.Light.MatrixWorld; 30 | this.MatrixAutoUpdate = false; 31 | 32 | this.Update(); 33 | } 34 | public PointLightHelper(SerializationInfo info, StreamingContext context) : base(info, context) { } 35 | 36 | public void Update() 37 | { 38 | if (this.Color != null) 39 | this.Material.Color = this.Color; 40 | else 41 | this.Material.Color = this.Light.Color; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/PixelShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class PixelShader : ShaderMaterial 8 | { 9 | public PixelShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("resolution", new GLUniform { { "value", new Vector2(256, 256) } }); 13 | Uniforms.Add("pixelSize", new GLUniform { { "value", 1.0f } }); 14 | 15 | 16 | VertexShader = @" 17 | varying vec2 vUv; 18 | 19 | 20 | void main() { 21 | 22 | vUv = uv; 23 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 24 | 25 | } 26 | 27 | 28 | " 29 | ; 30 | 31 | FragmentShader = @" 32 | uniform sampler2D tDiffuse; 33 | uniform float pixelSize; 34 | uniform vec2 resolution; 35 | 36 | varying highp vec2 vUv; 37 | 38 | void main(){ 39 | 40 | vec2 dxy = pixelSize / resolution; 41 | vec2 coord = dxy * floor( vUv / dxy ); 42 | gl_FragColor = texture2D(tDiffuse, coord); 43 | 44 | } 45 | 46 | 47 | "; 48 | } 49 | 50 | public PixelShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/ColorifyShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class ColorifyShader : ShaderMaterial 7 | { 8 | public ColorifyShader() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("color", new GLUniform { { "value", THREE.Color.Hex(0xffffff) } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform vec3 color; 30 | 31 | uniform sampler2D tDiffuse; 32 | 33 | varying vec2 vUv; 34 | 35 | void main() { 36 | 37 | vec4 texel = texture2D( tDiffuse, vUv ); 38 | 39 | vec3 luma = vec3( 0.299, 0.587, 0.114 ); 40 | float v = dot( texel.xyz, luma ); 41 | 42 | gl_FragColor = vec4( v * color, texel.w ); 43 | 44 | } 45 | 46 | "; 47 | 48 | } 49 | 50 | public ColorifyShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/LineBasicMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class LineBasicMaterial : Material 8 | { 9 | //public Color Color; 10 | 11 | public string LineCap = "round"; 12 | 13 | public string LineJoin = "round"; 14 | 15 | 16 | public LineBasicMaterial(Hashtable parameters = null) 17 | { 18 | this.Color = new Color().SetHex(0xffffff); 19 | 20 | this.type = "LineBasicMaterial"; 21 | 22 | this.LineWidth = 1.0f; 23 | this.LineCap = "round"; 24 | this.LineJoin = "round"; 25 | 26 | if (parameters != null) 27 | this.SetValues(parameters); 28 | } 29 | protected LineBasicMaterial(LineBasicMaterial source) : base(source) 30 | { 31 | this.Color = source.Color; 32 | 33 | this.LineWidth = source.LineWidth; 34 | 35 | this.LineCap = source.LineCap; 36 | 37 | this.LineJoin = source.LineJoin; 38 | } 39 | public LineBasicMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 40 | 41 | public new LineBasicMaterial Clone() 42 | { 43 | return new LineBasicMaterial(this); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Curves/QuadraticBezierCurve3.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class QuadraticBezierCurve3 : Curve 5 | { 6 | public Vector3 V0, V1, V2; 7 | 8 | public QuadraticBezierCurve3(Vector3 v0 = null, Vector3 v1 = null, Vector3 v2 = null, Vector3 v3 = null) 9 | { 10 | this.V0 = v0 != null ? v0 : new Vector3(); 11 | this.V1 = v1 != null ? v1 : new Vector3(); 12 | this.V2 = v2 != null ? v2 : new Vector3(); 13 | } 14 | 15 | protected QuadraticBezierCurve3(QuadraticBezierCurve3 source) 16 | { 17 | this.V0.Copy(source.V0); 18 | this.V1.Copy(source.V1); 19 | this.V2.Copy(source.V2); 20 | } 21 | public new object Clone() 22 | { 23 | return new QuadraticBezierCurve3(this); 24 | } 25 | public override Vector3 GetPoint(float t, Vector3 optionalTarget = null) 26 | { 27 | var point = optionalTarget != null ? optionalTarget : new Vector3(); 28 | 29 | 30 | point.Set( 31 | Interpolations.QuadraticBezier(t, V0.X, V1.X, V2.X), 32 | Interpolations.QuadraticBezier(t, V0.Y, V1.Y, V2.Y), 33 | Interpolations.QuadraticBezier(t, V0.Z, V1.Z, V2.Z) 34 | ); 35 | 36 | return point; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Curves/LineCurve3.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE 3 | { 4 | [Serializable] 5 | public class LineCurve3 : Curve 6 | { 7 | public Vector3 V1; 8 | 9 | public Vector3 V2; 10 | 11 | public LineCurve3(Vector3 v1 = null, Vector3 v2 = null) : base() 12 | { 13 | V1 = v1 != null ? v1 : new Vector3(); 14 | V2 = v2 != null ? v2 : new Vector3(); 15 | } 16 | protected LineCurve3(LineCurve3 other) 17 | { 18 | this.V1.Copy(other.V1); 19 | this.V2.Copy(other.V2); 20 | 21 | } 22 | public new object Clone() 23 | { 24 | return new LineCurve3(this); 25 | } 26 | public override Vector3 GetPoint(float t, Vector3 optionalTarget = null) 27 | { 28 | var point = optionalTarget != null ? optionalTarget : new Vector3(); 29 | 30 | if (t == 1) 31 | { 32 | point.Copy(this.V2); 33 | } 34 | else 35 | { 36 | point.Copy(this.V2).Sub(this.V1); 37 | point.MultiplyScalar(t).Add(this.V1); 38 | } 39 | 40 | return point; 41 | } 42 | 43 | public override Vector3 GetPointAt(float u, Vector3 optionalTarget = null) 44 | { 45 | return this.GetPoint(u, optionalTarget); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/OctahedronGeometry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class OctahedronGeometry : Geometry 9 | { 10 | public Hashtable parameters; 11 | public OctahedronGeometry(float? radius = null, float? detail = null) : base() 12 | { 13 | parameters = new Hashtable() 14 | { 15 | {"radius",radius }, 16 | {"detail",detail } 17 | }; 18 | 19 | this.FromBufferGeometry(new OctahedronBufferGeometry(radius, detail)); 20 | this.MergeVertices(); 21 | } 22 | } 23 | 24 | [Serializable] 25 | public class OctahedronBufferGeometry : PolyhedronBufferGeometry 26 | { 27 | static List vertices = new List() 28 | { 29 | 1, 0, 0, -1, 0, 0, 0, 1, 0, 30 | 0, -1, 0, 0, 0, 1, 0, 0, - 1 31 | }; 32 | 33 | static List indices = new List() 34 | { 35 | 0, 2, 4, 0, 4, 3, 0, 3, 5, 36 | 0, 5, 2, 1, 2, 5, 1, 5, 3, 37 | 1, 3, 4, 1, 4, 2 38 | }; 39 | public OctahedronBufferGeometry(float? radius = null, float? detail = null) : base(vertices, indices, radius, detail) 40 | { 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Math/Rectangle.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace THREE { 3 | 4 | [Serializable] 5 | public struct Rectangle 6 | { 7 | public static readonly Rectangle Empty; 8 | 9 | private int x; 10 | private int y; 11 | private int width; 12 | private int height; 13 | 14 | public Rectangle(int x, int y, int width, int height) 15 | { 16 | this.x = x; 17 | this.y = y; 18 | this.width = width; 19 | this.height = height; 20 | } 21 | 22 | public int X 23 | { 24 | readonly get => x; 25 | set => x = value; 26 | } 27 | 28 | public int Y 29 | { 30 | readonly get => y; 31 | set => y = value; 32 | } 33 | 34 | public int Width 35 | { 36 | readonly get => width; 37 | set => width = value; 38 | } 39 | 40 | 41 | public int Height 42 | { 43 | readonly get => height; 44 | set => height = value; 45 | } 46 | 47 | public readonly int Left => X; 48 | 49 | public readonly int Top => Y; 50 | 51 | public readonly int Right => unchecked(X + Width); 52 | 53 | public readonly int Bottom => unchecked(Y + Height); 54 | 55 | public readonly bool IsEmpty => height == 0 && width == 0 && x == 0 && y == 0; 56 | 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/RGBShiftShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class RGBShiftShader : ShaderMaterial 7 | { 8 | public RGBShiftShader() : base() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("amount", new GLUniform { { "value", 0.005f } }); 12 | Uniforms.Add("angle", new GLUniform { { "value", 0.0f } }); 13 | 14 | 15 | VertexShader = @" 16 | varying vec2 vUv; 17 | 18 | 19 | void main() { 20 | 21 | vUv = uv; 22 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 23 | 24 | } 25 | 26 | 27 | " 28 | ; 29 | 30 | FragmentShader = @" 31 | uniform sampler2D tDiffuse; 32 | uniform float amount; 33 | uniform float angle; 34 | 35 | varying vec2 vUv; 36 | 37 | void main() { 38 | 39 | vec2 offset = amount * vec2( cos(angle), sin(angle)); 40 | vec4 cr = texture2D(tDiffuse, vUv + offset); 41 | vec4 cga = texture2D(tDiffuse, vUv); 42 | vec4 cb = texture2D(tDiffuse, vUv - offset); 43 | gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a); 44 | 45 | } 46 | 47 | "; 48 | } 49 | 50 | public RGBShiftShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/PointLight.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class PointLight : Light 7 | { 8 | public new float Power 9 | { 10 | get 11 | { 12 | return (float)(this.Intensity * 4 * System.Math.PI); 13 | } 14 | set 15 | { 16 | this.Intensity = (float)(value / (4 * System.Math.PI)); 17 | } 18 | } 19 | 20 | public PointLight() : base() 21 | { 22 | this.Distance = 0; 23 | this.Decay = 1; 24 | this.Shadow = new PointLightShadow(); 25 | this.type = "PointLight"; 26 | } 27 | public PointLight(Color color, float? intensity = null, float? distance = null, float? decay = null) 28 | : base(color, intensity) 29 | { 30 | this.Distance = distance != null ? (float)distance : 0; 31 | this.Decay = decay != null ? (float)decay : 1; 32 | 33 | this.Shadow = new PointLightShadow(); 34 | 35 | this.type = "PointLight"; 36 | } 37 | 38 | public PointLight(SerializationInfo info, StreamingContext context) : base(info, context) { } 39 | public PointLight(int color, float? intensity = null, float? distance = null, float? decay = null) : this(Color.Hex(color), intensity, distance, decay) { } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/MirrorShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class MirrorShader : ShaderMaterial 7 | { 8 | public MirrorShader() : base() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("side", new GLUniform { { "value", 1 } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform sampler2D tDiffuse; 30 | uniform int side; 31 | 32 | varying vec2 vUv; 33 | 34 | void main() { 35 | 36 | vec2 p = vUv; 37 | if (side == 0){ 38 | if (p.x > 0.5) p.x = 1.0 - p.x; 39 | }else if (side == 1){ 40 | if (p.x < 0.5) p.x = 1.0 - p.x; 41 | }else if (side == 2){ 42 | if (p.y < 0.5) p.y = 1.0 - p.y; 43 | }else if (side == 3){ 44 | if (p.y > 0.5) p.y = 1.0 - p.y; 45 | } 46 | vec4 color = texture2D(tDiffuse, p); 47 | gl_FragColor = color; 48 | 49 | } 50 | 51 | 52 | "; 53 | } 54 | 55 | public MirrorShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLBufferRenderer.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLBufferRenderer 8 | { 9 | private GLRenderer renderer; 10 | 11 | private GLExtensions extensions; 12 | 13 | public GLInfo info; 14 | 15 | private GLCapabilities capabilities; 16 | 17 | public PrimitiveType mode; 18 | 19 | public bool IsGL2; 20 | 21 | public GLBufferRenderer(GLRenderer renderer, GLExtensions extensions, GLInfo info, GLCapabilities capabilities) 22 | { 23 | this.renderer = renderer; 24 | 25 | this.extensions = extensions; 26 | 27 | this.info = info; 28 | 29 | this.capabilities = capabilities; 30 | } 31 | 32 | public void SetMode(PrimitiveType value) 33 | { 34 | this.mode = value; 35 | } 36 | 37 | public virtual void Render(int start, int count) 38 | { 39 | GL.DrawArrays(this.mode, start, count); 40 | 41 | this.info.Update(count, (int)mode); 42 | } 43 | 44 | public virtual void RenderInstances(Geometry geometry, int start, int count, int primcount) 45 | { 46 | if (primcount == 0) return; 47 | 48 | GL.DrawArraysInstanced(this.mode, start, count, primcount); 49 | 50 | this.info.Update(count, (int)mode, primcount); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Curves/CubicBezierCurve3.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class CubicBezierCurve3 : Curve 5 | { 6 | public Vector3 V0, V1, V2, V3; 7 | 8 | public CubicBezierCurve3(Vector3 v0 = null, Vector3 v1 = null, Vector3 v2 = null, Vector3 v3 = null) 9 | { 10 | this.V0 = v0 != null ? v0 : new Vector3(); 11 | this.V1 = v1 != null ? v1 : new Vector3(); 12 | this.V2 = v2 != null ? v2 : new Vector3(); 13 | this.V3 = v3 != null ? v3 : new Vector3(); 14 | } 15 | 16 | protected CubicBezierCurve3(CubicBezierCurve3 source) 17 | { 18 | this.V0.Copy(source.V0); 19 | this.V1.Copy(source.V1); 20 | this.V2.Copy(source.V2); 21 | this.V3.Copy(source.V3); 22 | } 23 | 24 | public new object Clone() 25 | { 26 | return new CubicBezierCurve3(this); 27 | } 28 | public override Vector3 GetPoint(float t, Vector3 optionalTarget = null) 29 | { 30 | var point = optionalTarget != null ? optionalTarget : new Vector3(); 31 | 32 | 33 | point.Set( 34 | Interpolations.CubicBezier(t, V0.X, V1.X, V2.X, V3.X), 35 | Interpolations.CubicBezier(t, V0.Y, V1.Y, V2.Y, V3.Y), 36 | Interpolations.CubicBezier(t, V0.Z, V1.Z, V2.Z, V3.Z) 37 | ); 38 | 39 | return point; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/KaleidoShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class KaleidoShader : ShaderMaterial 8 | { 9 | public KaleidoShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("sides", new GLUniform { { "value", 6.0f } }); 13 | Uniforms.Add("angle", new GLUniform { { "value", 0.0f } }); 14 | 15 | VertexShader = @" 16 | varying vec2 vUv; 17 | 18 | 19 | void main() { 20 | 21 | vUv = uv; 22 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 23 | 24 | } 25 | 26 | 27 | " 28 | ; 29 | 30 | FragmentShader = @" 31 | uniform sampler2D tDiffuse; 32 | uniform float sides; 33 | uniform float angle; 34 | 35 | varying vec2 vUv; 36 | 37 | void main() { 38 | 39 | vec2 p = vUv - 0.5; 40 | float r = length(p); 41 | float a = atan(p.y, p.x) + angle; 42 | float tau = 2. * 3.1416 ; 43 | a = mod(a, tau/sides); 44 | a = abs(a - tau/sides/2.) ; 45 | p = r * vec2(cos(a), sin(a)); 46 | vec4 color = texture2D(tDiffuse, p + 0.5); 47 | gl_FragColor = color; 48 | 49 | } 50 | 51 | 52 | "; 53 | } 54 | 55 | public KaleidoShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/IGLRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace THREE 6 | { 7 | public interface IGLRenderer 8 | { 9 | bool IsGL2 { get; set; } 10 | bool AutoClear { get; set; } 11 | bool AutoClearColor { get; set; } 12 | bool AutoClearDepth { get; set; } 13 | bool AutoClearStencil { get; set; } 14 | //IGLState state_todo { get; set; } 15 | 16 | void Clear(bool? color = null, bool? depth = null, bool? stencil = null); 17 | Color GetClearColor(); 18 | void SetClearColor(Color color, float depth = 1.0f); 19 | float GetClearAlpha(); 20 | void SetClearAlpha(float alpha); 21 | void ClearDepth(); 22 | Vector2 GetSize(Vector2 target = null); 23 | float GetPixelRatio(); 24 | Vector4 GetCurrentViewport(Vector4 target); 25 | GLRenderTarget GetRenderTarget(); 26 | void SetRenderTarget(GLRenderTarget target,int? activeCubeFace=null, int? activeMipmapLevel=null); 27 | void Render(Scene scene, Camera camera); 28 | void RenderBufferDirect(Camera camera, Scene scene, Geometry geometry, Material material, Object3D object3D, DrawRange? group); 29 | void ReadRenderTargetPixels(GLRenderTarget renderTarget, float x, float y, int width, int height, byte[] buffer, int? activeCubeFaceIndex); 30 | void CopyFramebufferToTexture(Vector2 position, Texture texture, int? level = null); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/IcosahedronGeometry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class IcosahedronGeometry : Geometry 7 | { 8 | public IcosahedronGeometry(float radius, float? detail = null) : base() 9 | { 10 | this.FromBufferGeometry(new IcosahedronBufferGeometry(radius, detail)); 11 | this.MergeVertices(); 12 | } 13 | } 14 | 15 | [Serializable] 16 | public class IcosahedronBufferGeometry : PolyhedronBufferGeometry 17 | { 18 | 19 | static float t = (1 + (float)System.Math.Sqrt(5)) / 2; 20 | 21 | static List vertices = new List() 22 | { 23 | - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0, 24 | 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 25 | t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1 26 | }; 27 | 28 | 29 | static List indices = new List() 30 | { 31 | 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 32 | 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 33 | 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 34 | 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1 35 | }; 36 | public IcosahedronBufferGeometry(float radius, float? detail = null) : base(vertices, indices, radius, detail) 37 | { 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/InstancedBufferGeometry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public struct InstancedGroups 8 | { 9 | public int Start; 10 | 11 | public int Count; 12 | 13 | public int Instances; 14 | } 15 | [Serializable] 16 | public class InstancedBufferGeometry : BufferGeometry 17 | { 18 | public new List Groups = new List(); 19 | 20 | public int? MaxInstanceCount; 21 | 22 | public int InstanceCount = int.MaxValue; 23 | 24 | public InstancedBufferGeometry() : base() 25 | { 26 | 27 | } 28 | protected InstancedBufferGeometry(InstancedBufferGeometry source) 29 | { 30 | Copy(source); 31 | } 32 | public new InstancedBufferGeometry Clone() 33 | { 34 | return new InstancedBufferGeometry(this); 35 | } 36 | public InstancedBufferGeometry Copy(InstancedBufferGeometry source) 37 | { 38 | this.Groups = new List(source.Groups); 39 | this.MaxInstanceCount = source.MaxInstanceCount; 40 | this.InstanceCount = source.InstanceCount; 41 | 42 | return this; 43 | } 44 | public override void AddGroup(int start, int count, int instances) 45 | { 46 | this.Groups.Add(new InstancedGroups { Start = start, Count = count, Instances = instances }); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/SepiaShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class SepiaShader : ShaderMaterial 7 | { 8 | public SepiaShader() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("amount", new GLUniform { { "value", 1.0f } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform float amount; 30 | 31 | 32 | uniform sampler2D tDiffuse; 33 | 34 | varying vec2 vUv; 35 | 36 | void main() { 37 | 38 | vec4 color = texture2D( tDiffuse, vUv ); 39 | vec3 c = color.rgb; 40 | 41 | color.r = dot( c, vec3( 1.0 - 0.607 * amount, 0.769 * amount, 0.189 * amount ) ); 42 | color.g = dot( c, vec3( 0.349 * amount, 1.0 - 0.314 * amount, 0.168 * amount ) ); 43 | color.b = dot( c, vec3( 0.272 * amount, 0.534 * amount, 1.0 - 0.869 * amount ) ); 44 | 45 | gl_FragColor = vec4( min( vec3( 1.0 ), color.rgb ), color.a ); 46 | 47 | } 48 | " 49 | ; 50 | } 51 | 52 | public SepiaShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Postprocessing/ClearPass.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class ClearPass : Pass 8 | { 9 | Color? clearColor = null; 10 | float clearAlpha = 0; 11 | 12 | public ClearPass(Color? clearColor = null, float? clearAlpha = null) 13 | { 14 | this.NeedsSwap = false; 15 | 16 | this.clearColor = clearColor != null ? clearColor.Value : Color.Hex(0x000000); 17 | this.clearAlpha = clearAlpha != null ? clearAlpha.Value : 0.0f; 18 | } 19 | public override void Render(GLRenderer renderer, GLRenderTarget writeBuffer, GLRenderTarget readBuffer, float? deltaTime = null, bool? maskActive = null) 20 | { 21 | Color oldClearColor = Color.Hex(0x000000); 22 | float oldClearAlpha = 0.0f; 23 | 24 | if (this.clearColor != null) 25 | { 26 | 27 | oldClearColor = renderer.GetClearColor(); 28 | oldClearAlpha = renderer.GetClearAlpha(); 29 | 30 | renderer.SetClearColor(this.clearColor.Value, this.clearAlpha); 31 | 32 | } 33 | 34 | renderer.SetRenderTarget(this.RenderToScreen ? null : readBuffer); 35 | renderer.Clear(); 36 | 37 | if (this.clearColor != null) 38 | { 39 | 40 | renderer.SetClearColor(oldClearColor, oldClearAlpha); 41 | 42 | } 43 | } 44 | 45 | public override void SetSize(float width, float height) 46 | { 47 | 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLRenderState.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class GLRenderState 7 | { 8 | private List lightsArray = new List(); 9 | 10 | private List shadowsArray = new List(); 11 | 12 | private GLLights lights; 13 | 14 | public struct RenderState 15 | { 16 | public List LightsArray; 17 | 18 | public List ShadowsArray; 19 | 20 | public GLLights Lights; 21 | } 22 | 23 | public RenderState State; 24 | 25 | public GLRenderState(GLExtensions extensions, GLCapabilities capabilities) 26 | { 27 | lights = new GLLights(extensions, capabilities); 28 | State.LightsArray = lightsArray; 29 | State.ShadowsArray = shadowsArray; 30 | State.Lights = lights; 31 | } 32 | 33 | public void Init() 34 | { 35 | lightsArray.Clear(); 36 | shadowsArray.Clear(); 37 | } 38 | 39 | public void SetupLights() 40 | { 41 | lights.Setup(lightsArray); 42 | } 43 | public void SetupLightsView(Camera camera) 44 | { 45 | lights.SetupView(lightsArray, camera); 46 | } 47 | public void PushLight(Light light) 48 | { 49 | lightsArray.Add(light); 50 | } 51 | 52 | public void PushShadow(Light shadowLight) 53 | { 54 | shadowsArray.Add(shadowLight); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/ColorCorrectionShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class ColorCorrectionShader : ShaderMaterial 8 | { 9 | public ColorCorrectionShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("powRGB", new GLUniform { { "value", new Vector3(2, 2, 2) } }); 13 | Uniforms.Add("mulRGB", new GLUniform { { "value", new Vector3(1, 1, 1) } }); 14 | Uniforms.Add("addRGB", new GLUniform { { "value", new Vector3(0, 0, 0) } }); 15 | 16 | VertexShader = @" 17 | varying vec2 vUv; 18 | 19 | 20 | void main() { 21 | 22 | vUv = uv; 23 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 24 | 25 | } 26 | 27 | 28 | " 29 | ; 30 | 31 | FragmentShader = @" 32 | uniform sampler2D tDiffuse; 33 | 34 | uniform vec3 powRGB; 35 | uniform vec3 mulRGB; 36 | uniform vec3 addRGB; 37 | 38 | varying vec2 vUv; 39 | 40 | void main() { 41 | 42 | gl_FragColor = texture2D( tDiffuse, vUv ); 43 | gl_FragColor.rgb = mulRGB * pow( ( gl_FragColor.rgb + addRGB ), powRGB ); 44 | 45 | } 46 | "; 47 | } 48 | 49 | public ColorCorrectionShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/InteractiveThreeControlBase.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Input; 2 | using OpenTK.Windowing.Common; 3 | 4 | namespace THREE; 5 | 6 | public abstract class InteractiveThreeControlBase : ThreeControlBase, IControlsContainer 7 | { 8 | public Rectangle ClientRectangle => new((int)Bounds.Left, (int)Bounds.Top, (int)ScaledWidth, (int)ScaledHeight); 9 | 10 | public event Action? MouseDown; 11 | public event Action? MouseUp; 12 | public event Action? MouseMove; 13 | public event Action? MouseWheel; 14 | public event Action? MouseEnter; 15 | public event Action? MouseLeave; 16 | public event Action? SizeChanged; 17 | public event Action? KeyDown; 18 | public event Action? KeyUp; 19 | public event Action? KeyPress; 20 | 21 | protected override void OnPointerPressed(PointerPressedEventArgs e) => MouseDown?.Invoke(new PointerControlContainerEventArgs(this, e)); 22 | protected override void OnPointerMoved(PointerEventArgs e) => MouseMove?.Invoke(new PointerControlContainerEventArgs(this, e)); 23 | protected override void OnPointerReleased(PointerReleasedEventArgs e) => MouseUp?.Invoke(new PointerControlContainerEventArgs(this, e)); 24 | protected override void OnPointerWheelChanged(PointerWheelEventArgs e) => MouseWheel?.Invoke(new PointerControlContainerEventArgs(this, e, e.Delta.Y * 120)); //win forms compatibility 25 | } -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Core/Shape.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class Shape : Path 9 | { 10 | public Guid Uuid = Guid.NewGuid(); 11 | 12 | public List Holes; 13 | 14 | public Shape(List points = null) : base(points) 15 | { 16 | Holes = new List(); 17 | } 18 | 19 | protected Shape(Shape source) 20 | { 21 | Holes = new List(); 22 | for (int i = 0; i < source.Holes.Count; i++) 23 | { 24 | 25 | var hole = source.Holes[i]; 26 | 27 | this.Holes.Add(hole.Clone() as Path); 28 | 29 | } 30 | 31 | } 32 | 33 | public new object Clone() 34 | { 35 | return new Shape(this); 36 | } 37 | public List> GetPointsHoles(float divisions) 38 | { 39 | var holePts = new List>(); 40 | 41 | for (int i = 0; i < this.Holes.Count; i++) 42 | { 43 | if (this.Holes[i] == null) continue; 44 | holePts.Add(this.Holes[i].GetPoints(divisions)); 45 | } 46 | 47 | return holePts; 48 | } 49 | 50 | public Hashtable ExtractPoints(float divisions) 51 | { 52 | return new Hashtable() 53 | { 54 | {"shape",this.GetPoints(divisions) }, 55 | {"holes",this.GetPointsHoles(divisions) } 56 | }; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Loaders/TextureLoader.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class TextureLoader 7 | { 8 | public TextureLoader() 9 | { 10 | } 11 | 12 | public static Texture Load(string filePath) 13 | { 14 | SKBitmap bitmap = LoadBitmapAsRgba(filePath); 15 | //bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); 16 | Texture texture = new Texture(); 17 | texture.Image = bitmap; 18 | texture.Format = Constants.RGBAFormat; 19 | texture.NeedsUpdate = true; 20 | 21 | return texture; 22 | } 23 | 24 | static SKBitmap LoadBitmapAsRgba(string filePath) 25 | { 26 | using var codec = SKCodec.Create(filePath); 27 | return SKBitmap.Decode(codec, 28 | new SKImageInfo(codec.Info.Width, codec.Info.Height, SKColorType.Rgba8888, SKAlphaType.Premul) 29 | ); 30 | } 31 | 32 | public static Texture LoadEmbedded(string EmbeddedPath) 33 | { 34 | string embeddedNameBase = "THREE.Resources."; 35 | //Bitmap bitmap = new Bitmap(typeof(THREE.Object3D).GetTypeInfo().Assembly.GetManifestResourceStream(embeddedNameBase + EmbeddedPath)); 36 | 37 | //bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); 38 | 39 | Texture texture = new Texture(); 40 | texture.Image = SKBitmap.Decode(embeddedNameBase + EmbeddedPath); 41 | texture.Format = Constants.RGBFormat; 42 | texture.NeedsUpdate = true; 43 | 44 | return texture; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/BrightnessContrastShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class BrightnessContrastShader : ShaderMaterial 8 | { 9 | public BrightnessContrastShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("brightness", new GLUniform { { "value", 0.0f } }); 13 | Uniforms.Add("contrast", new GLUniform { { "value", 0.0f } }); 14 | 15 | VertexShader = @" 16 | varying vec2 vUv; 17 | 18 | 19 | void main() { 20 | 21 | vUv = uv; 22 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 23 | 24 | } 25 | 26 | 27 | " 28 | ; 29 | 30 | FragmentShader = @" 31 | uniform sampler2D tDiffuse; 32 | 33 | uniform float brightness; 34 | uniform float contrast; 35 | 36 | varying vec2 vUv; 37 | 38 | void main() { 39 | 40 | gl_FragColor = texture2D( tDiffuse, vUv ); 41 | 42 | gl_FragColor.rgb += brightness; 43 | 44 | if (contrast > 0.0) { 45 | gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) / (1.0 - contrast) + 0.5; 46 | } else { 47 | gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5; 48 | } 49 | 50 | } 51 | 52 | "; 53 | } 54 | 55 | public BrightnessContrastShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/TriangleBlurShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class TriangleBlurShader : ShaderMaterial 8 | { 9 | public TriangleBlurShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("delta", new GLUniform { { "value", new Vector2(1, 1) } }); 13 | 14 | 15 | 16 | VertexShader = @" 17 | varying vec2 vUv; 18 | 19 | 20 | void main() { 21 | 22 | vUv = uv; 23 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 24 | 25 | } 26 | 27 | 28 | " 29 | ; 30 | 31 | FragmentShader = @" 32 | #include 33 | 34 | #define ITERATIONS 10.0 35 | 36 | uniform sampler2D tDiffuse; 37 | uniform vec2 delta; 38 | 39 | varying vec2 vUv; 40 | 41 | void main() { 42 | 43 | vec4 color = vec4( 0.0 ); 44 | 45 | float total = 0.0; 46 | 47 | // randomize the lookup values to hide the fixed number of samples 48 | 49 | float offset = rand( vUv ); 50 | 51 | for ( float t = -ITERATIONS; t <= ITERATIONS; t ++ ) { 52 | 53 | float percent = ( t + offset - 0.5 ) / ITERATIONS; 54 | float weight = 1.0 - abs( percent ); 55 | 56 | color += texture2D( tDiffuse, vUv + delta * percent ) * weight; 57 | total += weight; 58 | 59 | } 60 | 61 | gl_FragColor = color / total; 62 | 63 | } 64 | 65 | 66 | "; 67 | } 68 | 69 | public TriangleBlurShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshToonMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class MeshToonMaterial : Material 7 | { 8 | 9 | public MeshToonMaterial() 10 | { 11 | 12 | this.type = "MeshToonMaterial"; 13 | 14 | Defines.Add("TOON", ""); 15 | 16 | Color = new Color().SetHex(0xffffff); 17 | Specular = new Color().SetHex(0x111111); 18 | Shininess = 30; 19 | 20 | Map = null; 21 | GradientMap = null; 22 | 23 | LightMap = null; 24 | LightMapIntensity = 1.0f; 25 | 26 | AoMap = null; 27 | AoMapIntensity = 1.0f; 28 | 29 | Emissive = THREE.Color.Hex(0x000000); 30 | EmissiveIntensity = 1.0f; 31 | EmissiveMap = null; 32 | 33 | BumpMap = null; 34 | BumpScale = 1; 35 | 36 | NormalMap = null; 37 | NormalMapType = Constants.TangentSpaceNormalMap; 38 | NormalScale = new Vector2(1, 1); 39 | 40 | DisplacementMap = null; 41 | DisplacementScale = 1; 42 | DisplacementBias = 0; 43 | 44 | SpecularMap = null; 45 | 46 | AlphaMap = null; 47 | 48 | Wireframe = false; 49 | 50 | WireframeLineWidth = 1; 51 | 52 | WireframeLineCap = "round"; 53 | 54 | WireframeLineJoin = "round"; 55 | 56 | Skinning = false; 57 | 58 | MorphTargets = false; 59 | 60 | MorphNormals = false; 61 | 62 | 63 | } 64 | public MeshToonMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/LuminosityHighPassShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class LuminosityHighPassShader : ShaderMaterial 8 | { 9 | public LuminosityHighPassShader() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("luminosityThreshold", new GLUniform { { "value", 1.0f } }); 13 | Uniforms.Add("smoothWidth", new GLUniform { { "value", 1.0f } }); 14 | Uniforms.Add("defaultColor", new GLUniform { { "value", new Color(0x000000) } }); 15 | Uniforms.Add("defaultOpacity", new GLUniform { { "value", 0.0f } }); 16 | 17 | VertexShader = @" 18 | varying vec2 vUv; 19 | 20 | 21 | void main() { 22 | 23 | vUv = uv; 24 | 25 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 26 | 27 | } 28 | 29 | "; 30 | 31 | FragmentShader = @" 32 | uniform sampler2D tDiffuse; 33 | uniform vec3 defaultColor; 34 | uniform float defaultOpacity; 35 | uniform float luminosityThreshold; 36 | uniform float smoothWidth; 37 | 38 | varying vec2 vUv; 39 | 40 | void main() { 41 | 42 | vec4 texel = texture2D( tDiffuse, vUv ); 43 | 44 | vec3 luma = vec3( 0.299, 0.587, 0.114 ); 45 | 46 | float v = dot( texel.xyz, luma ); 47 | 48 | vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity ); 49 | 50 | float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v ); 51 | 52 | gl_FragColor = mix( outputColor, texel, alpha ); 53 | 54 | } 55 | 56 | "; 57 | 58 | } 59 | 60 | public LuminosityHighPassShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/BleachBypassShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class BleachBypassShader : ShaderMaterial 7 | { 8 | 9 | public BleachBypassShader() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("opacity", new GLUniform { { "value", 1.0f } }); 13 | 14 | VertexShader = @" 15 | varying vec2 vUv; 16 | 17 | 18 | void main() { 19 | 20 | vUv = uv; 21 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 22 | 23 | } 24 | 25 | 26 | " 27 | ; 28 | 29 | FragmentShader = @" 30 | uniform float opacity; 31 | 32 | uniform sampler2D tDiffuse; 33 | 34 | varying vec2 vUv; 35 | 36 | void main() { 37 | 38 | vec4 base = texture2D( tDiffuse, vUv ); 39 | 40 | vec3 lumCoeff = vec3( 0.25, 0.65, 0.1 ); 41 | float lum = dot( lumCoeff, base.rgb ); 42 | vec3 blend = vec3( lum ); 43 | 44 | float L = min( 1.0, max( 0.0, 10.0 * ( lum - 0.45 ) ) ); 45 | 46 | vec3 result1 = 2.0 * base.rgb * blend; 47 | vec3 result2 = 1.0 - 2.0 * ( 1.0 - blend ) * ( 1.0 - base.rgb ); 48 | 49 | vec3 newColor = mix( result1, result2, L ); 50 | 51 | float A2 = opacity * base.a; 52 | vec3 mixRGB = A2 * newColor.rgb; 53 | mixRGB += ( ( 1.0 - A2 ) * base.rgb ); 54 | 55 | gl_FragColor = vec4( mixRGB, base.a ); 56 | 57 | } 58 | 59 | 60 | "; 61 | } 62 | 63 | public BleachBypassShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/DotScreenShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class DotScreenShader : ShaderMaterial 8 | { 9 | public DotScreenShader() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("tSize", new GLUniform { { "value", new Vector2(256, 256) } }); 13 | Uniforms.Add("center", new GLUniform { { "value", new Vector2(0.5f, 0.5f) } }); 14 | Uniforms.Add("angle", new GLUniform { { "value", 1.57f } }); 15 | Uniforms.Add("scale", new GLUniform { { "value", 1.0f } }); 16 | 17 | VertexShader = @" 18 | varying vec2 vUv; 19 | 20 | void main() { 21 | 22 | vUv = uv; 23 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 24 | 25 | } 26 | 27 | 28 | 29 | " 30 | ; 31 | 32 | FragmentShader = @" 33 | uniform vec2 center; 34 | uniform float angle; 35 | uniform float scale; 36 | uniform vec2 tSize; 37 | 38 | uniform sampler2D tDiffuse; 39 | 40 | varying vec2 vUv; 41 | 42 | float pattern() { 43 | 44 | float s = sin( angle ), c = cos( angle ); 45 | 46 | vec2 tex = vUv * tSize - center; 47 | vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * scale; 48 | 49 | return ( sin( point.x ) * sin( point.y ) ) * 4.0; 50 | 51 | } 52 | 53 | void main() { 54 | 55 | vec4 color = texture2D( tDiffuse, vUv ); 56 | 57 | float average = ( color.r + color.g + color.b ) / 3.0; 58 | 59 | gl_FragColor = vec4( vec3( average * 10.0 - 5.0 + pattern() ), color.a ); 60 | 61 | } 62 | 63 | " 64 | ; 65 | } 66 | 67 | public DotScreenShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/VignetteShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class VignetteShader : ShaderMaterial 7 | { 8 | public VignetteShader() : base() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("offset", new GLUniform { { "value", 1.0f } }); 12 | Uniforms.Add("darkness", new GLUniform { { "value", 1.0f } }); 13 | 14 | 15 | VertexShader = @" 16 | varying vec2 vUv; 17 | 18 | 19 | void main() { 20 | 21 | vUv = uv; 22 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 23 | 24 | } 25 | 26 | 27 | " 28 | ; 29 | 30 | FragmentShader = @" 31 | uniform float offset; 32 | uniform float darkness; 33 | 34 | uniform sampler2D tDiffuse; 35 | 36 | varying vec2 vUv; 37 | 38 | void main() { 39 | 40 | // Eskil's vignette 41 | 42 | vec4 texel = texture2D( tDiffuse, vUv ); 43 | vec2 uv = ( vUv - vec2( 0.5 ) ) * vec2( offset ); 44 | gl_FragColor = vec4( mix( texel.rgb, vec3( 1.0 - darkness ), dot( uv, uv ) ), texel.a ); 45 | 46 | /* 47 | // alternative version from glfx.js 48 | // this one makes more dusty look (as opposed to burned) 49 | 50 | vec4 color = texture2D( tDiffuse, vUv ); 51 | float dist = distance( vUv, vec2( 0.5 ) ); 52 | color.rgb *= smoothstep( 0.8, offset * 0.799, dist *( darkness + offset ) ); 53 | gl_FragColor = color; 54 | */ 55 | 56 | } 57 | 58 | 59 | "; 60 | } 61 | 62 | public VignetteShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLIndexedBufferRenderer.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | using System; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLIndexedBufferRenderer : GLBufferRenderer 8 | { 9 | private VertexAttribPointerType type; 10 | 11 | private int bytesPerElement; 12 | 13 | 14 | 15 | public GLIndexedBufferRenderer(GLRenderer renderer, GLExtensions extensions, GLInfo info, GLCapabilities capabilities) : base(renderer, extensions, info, capabilities) 16 | { 17 | } 18 | 19 | //public void SetMode(PrimitiveType value) 20 | //{ 21 | // this.mode = value; 22 | //} 23 | 24 | public void SetIndex(BufferType value) 25 | { 26 | var pointerType = (VertexAttribPointerType)Enum.ToObject(typeof(VertexAttribPointerType), value.Type); 27 | this.type = pointerType; 28 | 29 | this.bytesPerElement = value.BytesPerElement; 30 | } 31 | 32 | public override void Render(int start, int count) 33 | { 34 | int indices = start * this.bytesPerElement; 35 | IntPtr ptr = IntPtr.Add(IntPtr.Zero, indices); 36 | 37 | GL.DrawElements((All)mode, count, (All)type, ptr); 38 | 39 | info.Update(count, (int)mode); 40 | } 41 | 42 | public override void RenderInstances(Geometry geometry, int start, int count, int primcount) 43 | { 44 | if (primcount == 0) return; 45 | 46 | int indices = start * this.bytesPerElement; 47 | IntPtr ptr = IntPtr.Add(IntPtr.Zero, indices); 48 | 49 | GL.DrawElementsInstanced((All)mode, count, (All)type, ptr, primcount); 50 | 51 | info.Update(count, (int)mode, primcount); 52 | 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/VerticalBlurShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class VerticalBlurShader : ShaderMaterial 7 | { 8 | public VerticalBlurShader() : base() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("v", new GLUniform { { "value", 1.0f / 512.0f } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform sampler2D tDiffuse; 30 | uniform float v; 31 | 32 | varying vec2 vUv; 33 | 34 | void main() { 35 | 36 | vec4 sum = vec4( 0.0 ); 37 | 38 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * v ) ) * 0.051; 39 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * v ) ) * 0.0918; 40 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * v ) ) * 0.12245; 41 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * v ) ) * 0.1531; 42 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633; 43 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * v ) ) * 0.1531; 44 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * v ) ) * 0.12245; 45 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * v ) ) * 0.0918; 46 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * v ) ) * 0.051; 47 | 48 | gl_FragColor = sum; 49 | 50 | } 51 | "; 52 | } 53 | 54 | public VerticalBlurShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/HorizontalBlurShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class HorizontalBlurShader : ShaderMaterial 7 | { 8 | public HorizontalBlurShader() : base() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("h", new GLUniform { { "value", 1.0f / 512.0f } }); 12 | 13 | VertexShader = @" 14 | varying vec2 vUv; 15 | 16 | 17 | void main() { 18 | 19 | vUv = uv; 20 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 21 | 22 | } 23 | 24 | 25 | " 26 | ; 27 | 28 | FragmentShader = @" 29 | uniform sampler2D tDiffuse; 30 | uniform float h; 31 | 32 | varying vec2 vUv; 33 | 34 | void main() { 35 | 36 | vec4 sum = vec4( 0.0 ); 37 | 38 | sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * h, vUv.y ) ) * 0.051; 39 | sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * h, vUv.y ) ) * 0.0918; 40 | sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * h, vUv.y ) ) * 0.12245; 41 | sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * h, vUv.y ) ) * 0.1531; 42 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633; 43 | sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * h, vUv.y ) ) * 0.1531; 44 | sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * h, vUv.y ) ) * 0.12245; 45 | sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * h, vUv.y ) ) * 0.0918; 46 | sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * h, vUv.y ) ) * 0.051; 47 | 48 | gl_FragColor = sum; 49 | 50 | } 51 | "; 52 | } 53 | 54 | public HorizontalBlurShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/Light.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class Light : Object3D 7 | { 8 | public Color Color; 9 | 10 | public Color GroundColor; 11 | 12 | public float Intensity; 13 | 14 | public float Distance; 15 | 16 | public float Angle; 17 | 18 | public float Exponent; 19 | 20 | public float Decay; 21 | 22 | public float Power { get; set; } 23 | 24 | public float Penumbra; 25 | 26 | public Object3D Target; 27 | 28 | public LightShadow Shadow; 29 | 30 | public SphericalHarmonics3 sh; 31 | 32 | //RectAreaLight 33 | 34 | public int Width; 35 | 36 | public int Height; 37 | 38 | public Light() : base() 39 | { 40 | this.IsLight = true; 41 | } 42 | public Light(SerializationInfo info, StreamingContext context) : base(info, context) { } 43 | 44 | public Light(Color color, float? intensity = null) : base() 45 | { 46 | this.type = "Light"; 47 | 48 | this.Color = color; 49 | 50 | this.Intensity = intensity != null ? intensity.Value : 1; 51 | 52 | this.ReceiveShadow = false; 53 | 54 | this.IsLight = true; 55 | 56 | } 57 | public Light(int color, float? intensity = null) : this(Color.Hex(color), intensity) { } 58 | 59 | protected Light(Light other) : base(other) 60 | { 61 | this.type = "Light"; 62 | 63 | this.Color = other.Color; 64 | 65 | this.Intensity = other.Intensity; 66 | 67 | this.IsLight = true; 68 | } 69 | public Light Copy(Light source) 70 | { 71 | return new Light(source); 72 | 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Curves/SplineCurve.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class SplineCurve : Curve 7 | { 8 | public List Points; 9 | 10 | public SplineCurve(List points = null) : base() 11 | { 12 | this.Points = points != null ? points : new List(); 13 | } 14 | 15 | protected SplineCurve(SplineCurve source) 16 | { 17 | this.Points = new List(); 18 | 19 | for (int i = 0; i < source.Points.Count; i++) 20 | { 21 | var point = source.Points[i]; 22 | this.Points.Add((Vector3)point.Clone()); 23 | } 24 | } 25 | 26 | public new object Clone() 27 | { 28 | return new SplineCurve(this); 29 | } 30 | public override Vector3 GetPoint(float t, Vector3 optionalTarget = null) 31 | { 32 | var point = optionalTarget != null ? optionalTarget : new Vector3(); 33 | 34 | var points = this.Points; 35 | var p = (points.Count - 1) * t; 36 | 37 | var intPoint = (int)System.Math.Floor(p); 38 | var weight = p - intPoint; 39 | 40 | var p0 = points[intPoint == 0 ? intPoint : intPoint - 1]; 41 | var p1 = points[intPoint]; 42 | var p2 = points[intPoint > points.Count - 2 ? points.Count - 1 : intPoint + 1]; 43 | var p3 = points[intPoint > points.Count - 3 ? points.Count - 1 : intPoint + 2]; 44 | 45 | point.Set( 46 | Interpolations.CatmullRom(weight, p0.X, p1.X, p2.X, p3.X), 47 | Interpolations.CatmullRom(weight, p0.Y, p1.Y, p2.Y, p3.Y), 48 | 0 49 | ); 50 | 51 | return point; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLRenderStates.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLRenderStates 8 | { 9 | public Hashtable renderStates = new Hashtable(); 10 | private GLExtensions extensions; 11 | private GLCapabilities capabilities; 12 | public GLRenderStates(GLExtensions extensions, GLCapabilities capabilities) 13 | { 14 | this.extensions = extensions; 15 | this.capabilities = capabilities; 16 | } 17 | 18 | public void OnSceneDispose(object sender, EventArgs e) 19 | { 20 | var scene = sender as Scene; 21 | 22 | scene.Disposed -= OnSceneDispose; 23 | renderStates.Remove(scene); 24 | } 25 | 26 | public GLRenderState Get(Scene scene, int renderCallDepth=0) 27 | { 28 | GLRenderState renderState; 29 | 30 | if (!renderStates.Contains(scene)) 31 | { 32 | renderState = new GLRenderState(extensions,capabilities); 33 | List list = new List() { renderState }; 34 | renderStates.Add(scene, list); 35 | 36 | scene.Disposed += OnSceneDispose; 37 | } 38 | else 39 | { 40 | if (renderCallDepth >= (renderStates[scene] as List).Count) 41 | { 42 | renderState = new GLRenderState(extensions,capabilities); 43 | (renderStates[scene] as List).Add(renderState); 44 | } 45 | else 46 | { 47 | renderState = (renderStates[scene] as List)[renderCallDepth]; 48 | } 49 | } 50 | 51 | return renderState; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Helpers/GridHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GridHelper : LineSegments 8 | { 9 | public GridHelper(int size = 10, int divisions = 10, int c1 = 0x444444, int c2 = 0x888888) : base() 10 | { 11 | Color color1 = new Color(c1); 12 | Color color2 = new Color(c2); 13 | 14 | var center = divisions / 2; 15 | var step = size / divisions; 16 | var halfSize = size / 2; 17 | 18 | List vertices = new List(); 19 | List colors = new List(); 20 | 21 | 22 | for (int i = 0, k = -halfSize; i <= divisions; i++, k += step) 23 | { 24 | 25 | vertices.Add(-halfSize, 0, k, halfSize, 0, k); 26 | vertices.Add(k, 0, -halfSize, k, 0, halfSize); 27 | 28 | var color = (i == center) ? color1 : color2; 29 | 30 | colors.Add(color.R, color.G, color.B); 31 | colors.Add(color.R, color.G, color.B); 32 | colors.Add(color.R, color.G, color.B); 33 | colors.Add(color.R, color.G, color.B); 34 | 35 | } 36 | 37 | var geometry = new BufferGeometry(); 38 | geometry.SetAttribute("position", new BufferAttribute(vertices.ToArray(), 3)); 39 | geometry.SetAttribute("color", new BufferAttribute(colors.ToArray(), 3)); 40 | 41 | var material = new LineBasicMaterial() { VertexColors = true, ToneMapped = false }; 42 | 43 | List materialList = new List() { material }; 44 | InitGeometry(geometry, materialList); 45 | 46 | this.type = "GridHelper"; 47 | } 48 | public GridHelper(SerializationInfo info, StreamingContext context) : base(info, context) { } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/HueSaturationShader.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class HueSaturationShader : ShaderMaterial 7 | { 8 | public HueSaturationShader() : base() 9 | { 10 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 11 | Uniforms.Add("hue", new GLUniform { { "value", 0.0f } }); 12 | Uniforms.Add("saturation", new GLUniform { { "value", 0.0f } }); 13 | 14 | VertexShader = @" 15 | varying vec2 vUv; 16 | 17 | 18 | void main() { 19 | 20 | vUv = uv; 21 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 22 | 23 | } 24 | 25 | 26 | " 27 | ; 28 | 29 | FragmentShader = @" 30 | uniform sampler2D tDiffuse; 31 | uniform float hue; 32 | uniform float saturation; 33 | 34 | varying vec2 vUv; 35 | 36 | void main() { 37 | 38 | gl_FragColor = texture2D( tDiffuse, vUv ); 39 | 40 | // hue 41 | float angle = hue * 3.14159265; 42 | float s = sin(angle), c = cos(angle); 43 | vec3 weights = (vec3(2.0 * c, -sqrt(3.0) * s - c, sqrt(3.0) * s - c) + 1.0) / 3.0; 44 | float len = length(gl_FragColor.rgb); 45 | gl_FragColor.rgb = vec3( 46 | dot(gl_FragColor.rgb, weights.xyz), 47 | dot(gl_FragColor.rgb, weights.zxy), 48 | dot(gl_FragColor.rgb, weights.yzx) 49 | ); 50 | 51 | // saturation 52 | float average = (gl_FragColor.r + gl_FragColor.g + gl_FragColor.b) / 3.0; 53 | if (saturation > 0.0) { 54 | gl_FragColor.rgb += (average - gl_FragColor.rgb) * (1.0 - 1.0 / (1.001 - saturation)); 55 | } else { 56 | gl_FragColor.rgb += (average - gl_FragColor.rgb) * (-saturation); 57 | } 58 | 59 | } 60 | 61 | 62 | "; 63 | } 64 | 65 | public HueSaturationShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/VerticalTiltShiftShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class VerticalTiltShiftShader : ShaderMaterial 8 | { 9 | public VerticalTiltShiftShader() : base() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("v", new GLUniform { { "value", 1.0f / 512.0f } }); 13 | Uniforms.Add("r", new GLUniform { { "value", 0.35f } }); 14 | 15 | VertexShader = @" 16 | varying vec2 vUv; 17 | 18 | 19 | void main() { 20 | 21 | vUv = uv; 22 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 23 | 24 | } 25 | 26 | 27 | " 28 | ; 29 | 30 | FragmentShader = @" 31 | uniform sampler2D tDiffuse; 32 | uniform float v; 33 | uniform float r; 34 | 35 | varying vec2 vUv; 36 | 37 | void main() { 38 | 39 | vec4 sum = vec4( 0.0 ); 40 | 41 | float vv = v * abs( r - vUv.y ); 42 | 43 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 4.0 * vv ) ) * 0.051; 44 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 3.0 * vv ) ) * 0.0918; 45 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 2.0 * vv ) ) * 0.12245; 46 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y - 1.0 * vv ) ) * 0.1531; 47 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633; 48 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 1.0 * vv ) ) * 0.1531; 49 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 2.0 * vv ) ) * 0.12245; 50 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 3.0 * vv ) ) * 0.0918; 51 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y + 4.0 * vv ) ) * 0.051; 52 | 53 | gl_FragColor = sum; 54 | 55 | } 56 | "; 57 | } 58 | 59 | public VerticalTiltShiftShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/HorizontalTiltShiftShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | 8 | public class HorizontalTiltShiftShader : ShaderMaterial 9 | { 10 | public HorizontalTiltShiftShader() : base() 11 | { 12 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 13 | Uniforms.Add("h", new GLUniform { { "value", 1.0f / 512.0f } }); 14 | Uniforms.Add("r", new GLUniform { { "value", 0.35f } }); 15 | 16 | VertexShader = @" 17 | varying vec2 vUv; 18 | 19 | 20 | void main() { 21 | 22 | vUv = uv; 23 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 24 | 25 | } 26 | 27 | 28 | " 29 | ; 30 | 31 | FragmentShader = @" 32 | uniform sampler2D tDiffuse; 33 | uniform float h; 34 | uniform float r; 35 | 36 | varying vec2 vUv; 37 | 38 | void main() { 39 | 40 | vec4 sum = vec4( 0.0 ); 41 | 42 | float hh = h * abs( r - vUv.y ); 43 | 44 | sum += texture2D( tDiffuse, vec2( vUv.x - 4.0 * hh, vUv.y ) ) * 0.051; 45 | sum += texture2D( tDiffuse, vec2( vUv.x - 3.0 * hh, vUv.y ) ) * 0.0918; 46 | sum += texture2D( tDiffuse, vec2( vUv.x - 2.0 * hh, vUv.y ) ) * 0.12245; 47 | sum += texture2D( tDiffuse, vec2( vUv.x - 1.0 * hh, vUv.y ) ) * 0.1531; 48 | sum += texture2D( tDiffuse, vec2( vUv.x, vUv.y ) ) * 0.1633; 49 | sum += texture2D( tDiffuse, vec2( vUv.x + 1.0 * hh, vUv.y ) ) * 0.1531; 50 | sum += texture2D( tDiffuse, vec2( vUv.x + 2.0 * hh, vUv.y ) ) * 0.12245; 51 | sum += texture2D( tDiffuse, vec2( vUv.x + 3.0 * hh, vUv.y ) ) * 0.0918; 52 | sum += texture2D( tDiffuse, vec2( vUv.x + 4.0 * hh, vUv.y ) ) * 0.051; 53 | 54 | gl_FragColor = sum; 55 | 56 | } 57 | "; 58 | } 59 | 60 | public HorizontalTiltShiftShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshLambertMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class MeshLambertMaterial : Material 7 | { 8 | public MeshLambertMaterial() : base() 9 | { 10 | this.type = "MeshLambertMaterial"; 11 | 12 | this.Color = THREE.Color.ColorName(ColorKeywords.white); 13 | 14 | this.Opacity = 1; 15 | 16 | this.Emissive = THREE.Color.Hex(0x000000); 17 | 18 | this.Combine = Constants.MultiplyOperation; 19 | 20 | this.RefractionRatio = 0.98f; 21 | 22 | this.Transparent = false; 23 | 24 | this.WireframeLineWidth = 1; 25 | 26 | this.WireframeLineCap = "round"; 27 | this.WireframeLineJoin = "round"; 28 | } 29 | public MeshLambertMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 30 | 31 | protected MeshLambertMaterial(MeshLambertMaterial source) : base() 32 | { 33 | Copy(source); 34 | } 35 | public override object Clone() 36 | { 37 | var material = new MeshLambertMaterial(); 38 | material.Copy(this); 39 | return material; 40 | } 41 | public object Copy(MeshLambertMaterial source) 42 | { 43 | base.Copy(source); 44 | this.type = source.type; 45 | 46 | this.Color = source.Color; 47 | 48 | this.Opacity = source.Opacity; 49 | 50 | this.Emissive = source.Emissive; 51 | 52 | this.Combine = source.Combine; 53 | 54 | this.RefractionRatio = source.RefractionRatio; 55 | 56 | this.Transparent = source.Transparent; 57 | 58 | this.WireframeLineWidth = source.WireframeLineWidth; 59 | 60 | this.WireframeLineCap = source.WireframeLineCap; 61 | this.WireframeLineJoin = source.WireframeLineJoin; 62 | 63 | return this; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Postprocessing/TexturePass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using THREE.Renderers.Shaders; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class TexturePass : Pass 8 | { 9 | private Texture map; 10 | private float opacity; 11 | private GLUniforms uniforms; 12 | private ShaderMaterial material; 13 | 14 | public TexturePass(Texture map, float? opacity = null) : base() 15 | { 16 | var shader = new CopyShader(); 17 | 18 | this.map = map; 19 | this.opacity = opacity != null ? opacity.Value : 1.0f; 20 | this.uniforms = UniformsUtils.CloneUniforms(shader.Uniforms); 21 | 22 | this.material = new ShaderMaterial 23 | { 24 | Uniforms = this.uniforms, 25 | VertexShader = shader.VertexShader, 26 | FragmentShader = shader.FragmentShader, 27 | DepthTest = false, 28 | DepthWrite = false 29 | }; 30 | 31 | this.NeedsSwap = false; 32 | 33 | this.fullScreenQuad = new FullScreenQuad(); 34 | } 35 | public override void Render(GLRenderer renderer, GLRenderTarget writeBuffer, GLRenderTarget readBuffer, float? deltaTime = null, bool? maskActive = null) 36 | { 37 | var oldAutoClear = renderer.AutoClear; 38 | renderer.AutoClear = false; 39 | 40 | this.fullScreenQuad.material = this.material; 41 | 42 | (this.uniforms["opacity"] as GLUniform)["value"] = this.opacity; 43 | (this.uniforms["tDiffuse"] as GLUniform)["value"] = this.map; 44 | this.material.Transparent = (this.opacity < 1.0); 45 | 46 | renderer.SetRenderTarget(this.RenderToScreen ? null : readBuffer); 47 | if (this.Clear) renderer.Clear(); 48 | this.fullScreenQuad.Render(renderer); 49 | 50 | renderer.AutoClear = oldAutoClear; 51 | } 52 | 53 | public override void SetSize(float width, float height) 54 | { 55 | 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Materials/MeshPhongMaterial.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class MeshPhongMaterial : Material 8 | { 9 | public MeshPhongMaterial(Hashtable parameter = null) 10 | { 11 | this.type = "MeshPhongMaterial"; 12 | this.Color = new Color().SetHex(0xffffff); ; 13 | this.Specular = new Color().SetHex(0x111111); ; 14 | this.Shininess = 30; 15 | 16 | this.LightMap = null; 17 | this.LightMapIntensity = 1.0f; 18 | 19 | this.AoMap = null; 20 | this.AoMapIntensity = 1.0f; 21 | 22 | this.Emissive = new Color().SetHex(0x000000); 23 | this.EmissiveIntensity = 1.0f; 24 | this.EmissiveMap = null; 25 | 26 | this.BumpMap = null; 27 | this.BumpScale = 1; 28 | 29 | this.NormalMap = null; 30 | this.NormalMapType = Constants.TangentSpaceNormalMap; 31 | this.NormalScale = new Vector2(1, 1); 32 | 33 | this.DisplacementMap = null; 34 | this.DisplacementScale = 1; 35 | this.DisplacementBias = 0; 36 | 37 | this.SpecularMap = null; 38 | 39 | this.AlphaMap = null; 40 | 41 | this.EnvMap = null; 42 | 43 | this.Combine = Constants.MultiplyOperation; 44 | 45 | this.Reflectivity = 1; 46 | 47 | this.RefractionRatio = 0.98f; 48 | 49 | this.Wireframe = false; 50 | this.WireframeLineWidth = 1; 51 | this.WireframeLineCap = "round"; 52 | this.WireframeLineJoin = "round"; 53 | 54 | this.Skinning = false; 55 | this.MorphTargets = false; 56 | this.MorphNormals = false; 57 | 58 | 59 | if (parameter != null) 60 | this.SetValues(parameter); 61 | } 62 | 63 | public MeshPhongMaterial(SerializationInfo info, StreamingContext context) : base(info, context) { } 64 | 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Postprocessing/ShaderPass.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using THREE.Renderers.Shaders; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class ShaderPass : Pass 9 | { 10 | private string textureId; 11 | public GLUniforms uniforms; 12 | private ShaderMaterial material; 13 | 14 | public ShaderPass(Material shader, string textureId = null) 15 | { 16 | this.textureId = textureId != null ? textureId : "tDiffuse"; 17 | if (shader != null && shader is ShaderMaterial) 18 | { 19 | uniforms = (shader as ShaderMaterial).Uniforms; 20 | if (textureId != null && !uniforms.ContainsKey(textureId)) 21 | uniforms[textureId] = new GLUniform { { "value", null } }; 22 | material = shader as ShaderMaterial; 23 | } 24 | 25 | fullScreenQuad = new Pass.FullScreenQuad(this.material); 26 | } 27 | public override void Render(GLRenderer renderer, GLRenderTarget writeBuffer, GLRenderTarget readBuffer, float? deltaTime = null, bool? maskActive = null) 28 | { 29 | if (uniforms.ContainsKey(textureId)) 30 | { 31 | (uniforms[textureId] as GLUniform)["value"] = readBuffer.Texture; 32 | } 33 | 34 | fullScreenQuad.material = material; 35 | if (this.RenderToScreen) 36 | { 37 | renderer.SetRenderTarget(null); 38 | fullScreenQuad.Render(renderer); 39 | } 40 | else 41 | { 42 | renderer.SetRenderTarget(writeBuffer); 43 | // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600 44 | if (this.Clear) renderer.Clear(renderer.AutoClearColor, renderer.AutoClearDepth, renderer.AutoClearStencil); 45 | this.fullScreenQuad.Render(renderer); 46 | } 47 | } 48 | 49 | public override void SetSize(float width, float height) 50 | { 51 | 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Postprocessing/DotScreenPass.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using THREE.Renderers.Shaders; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class DotScreenPass : Pass 9 | { 10 | public GLUniforms uniforms; 11 | private ShaderMaterial material; 12 | 13 | public DotScreenPass(Vector2 center = null, float? angle = null, float? scale = null) : base() 14 | { 15 | var shader = new DotScreenShader(); 16 | 17 | this.uniforms = UniformsUtils.CloneUniforms(shader.Uniforms); 18 | 19 | if (center != null) (this.uniforms["center"] as GLUniform)["value"] = center; 20 | if (angle != null) (this.uniforms["angle"] as GLUniform)["value"] = angle; 21 | if (scale != null) (this.uniforms["scale"] as GLUniform)["value"] = scale; 22 | 23 | this.material = new ShaderMaterial 24 | { 25 | 26 | Uniforms = this.uniforms, 27 | VertexShader = shader.VertexShader, 28 | FragmentShader = shader.FragmentShader 29 | 30 | }; 31 | 32 | this.fullScreenQuad = new FullScreenQuad(this.material); 33 | 34 | } 35 | public override void Render(GLRenderer renderer, GLRenderTarget writeBuffer, GLRenderTarget readBuffer, float? deltaTime = null, bool? maskActive = null) 36 | { 37 | (this.uniforms["tDiffuse"] as GLUniform)["value"] = readBuffer.Texture; 38 | ((this.uniforms["tSize"] as GLUniform)["value"] as Vector2).Set(readBuffer.Width, readBuffer.Height); 39 | 40 | if (this.RenderToScreen) 41 | { 42 | 43 | renderer.SetRenderTarget(null); 44 | this.fullScreenQuad.Render(renderer); 45 | 46 | } 47 | else 48 | { 49 | 50 | renderer.SetRenderTarget(writeBuffer); 51 | if (this.Clear) renderer.Clear(); 52 | this.fullScreenQuad.Render(renderer); 53 | 54 | } 55 | } 56 | 57 | public override void SetSize(float width, float height) 58 | { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/Face3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class Face3 : ICloneable 8 | { 9 | public int a; 10 | 11 | public int b; 12 | 13 | public int c; 14 | 15 | public Vector3 Normal = new Vector3(); 16 | 17 | public List VertexNormals = new List(); 18 | 19 | public Color Color; 20 | 21 | public List VertexColors = new List(); 22 | 23 | public List VertexTangents = new List(); 24 | 25 | public int MaterialIndex = 0; 26 | 27 | public Face3(int a, int b, int c) 28 | { 29 | this.a = a; 30 | this.b = b; 31 | this.c = c; 32 | this.Normal = new Vector3(1, 1, 1); 33 | this.Color = Color.ColorName(ColorKeywords.white); 34 | this.MaterialIndex = 0; 35 | } 36 | public Face3(int a, int b, int c, Vector3 normal) 37 | { 38 | this.a = a; 39 | this.b = b; 40 | this.c = c; 41 | this.Normal = normal; 42 | } 43 | 44 | public Face3(int a, int b, int c, Vector3 normal, Color color, int materialIndex = 0) 45 | { 46 | this.a = a; 47 | this.b = b; 48 | this.c = c; 49 | this.Normal = normal; 50 | this.Color = color; 51 | this.MaterialIndex = materialIndex; 52 | } 53 | 54 | public Face3(int a, int b, int c, List vertexNormals, List vertexColors, int materialIndex = 0) 55 | { 56 | this.a = a; 57 | this.b = b; 58 | this.c = c; 59 | this.VertexNormals = vertexNormals; 60 | this.VertexColors = vertexColors; 61 | this.MaterialIndex = materialIndex; 62 | } 63 | protected Face3(Face3 other) 64 | { 65 | throw new NotImplementedException(); 66 | } 67 | 68 | public object Clone() 69 | { 70 | return new Face3(this); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/TextGeometry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class TextGeometry : Geometry 8 | { 9 | public Hashtable parameters; 10 | 11 | public TextGeometry(string text, Hashtable parameters) : base() 12 | { 13 | this.type = "TextGeometry"; 14 | 15 | this.parameters = new Hashtable() 16 | { 17 | {"text",text }, 18 | {"parameters",parameters } 19 | }; 20 | 21 | this.FromBufferGeometry(new TextBufferGeometry(text, parameters)); 22 | this.MergeVertices(); 23 | } 24 | 25 | } 26 | 27 | [Serializable] 28 | public class TextBufferGeometry : ExtrudeBufferGeometry 29 | { 30 | public TextBufferGeometry() 31 | { 32 | 33 | } 34 | public TextBufferGeometry(string text, Hashtable parameters) 35 | { 36 | this.type = "TextBufferGeometry"; 37 | 38 | this.parameters = new Hashtable() 39 | { 40 | {"text",text }, 41 | {"parameters",parameters } 42 | }; 43 | 44 | if (!parameters.ContainsKey("font") || parameters["font"] == null) 45 | { 46 | Console.WriteLine("Error: TextGeometry font parameter is not an instance of THREE.Font"); 47 | return; 48 | } 49 | 50 | var font = (Font)parameters["font"]; 51 | 52 | var shapes = font.GenerateShapes(text, parameters.ContainsKey("size") ? (int?)parameters["size"] : null); 53 | 54 | if (!parameters.ContainsKey("bevelThickness") || parameters["bevelThickness"] == null) parameters["bevelThickness"] = 10; 55 | if (!parameters.ContainsKey("bevelSize") || parameters["bevelSize"] == null) parameters["bevelSize"] = 8; 56 | if (!parameters.ContainsKey("bevelEnabled") || parameters["bevelEnabled"] == null) parameters["bevelEnabled"] = false; 57 | 58 | parameters["depth"] = parameters.ContainsKey("height") ? (int)parameters["height"] : 50; 59 | 60 | Init(shapes, parameters); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/InterleavedBuffer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.Serialization; 5 | 6 | namespace THREE 7 | { 8 | [Serializable] 9 | public class InterleavedBuffer : BufferAttribute 10 | { 11 | public int Stride 12 | { 13 | get 14 | { 15 | return (int)this["stride"]; 16 | } 17 | set 18 | { 19 | this["stride"] = value; 20 | } 21 | } 22 | 23 | 24 | public new int count 25 | { 26 | get 27 | { 28 | return this.Array != null ? this.Array.Length / Stride : 0; 29 | } 30 | } 31 | 32 | public InterleavedBuffer() : base() 33 | { 34 | 35 | this.Usage = Constants.StaticDrawUsage; 36 | this.Add("stride", 0); 37 | } 38 | public InterleavedBuffer(SerializationInfo info, StreamingContext context) : base(info, context) { } 39 | 40 | 41 | public InterleavedBuffer(T[] array, int stride) : this() 42 | { 43 | this.Array = array; 44 | this.Stride = stride; 45 | this.UpdateRange = new UpdateRange { Offset = 0, Count = -1 }; 46 | this.Type = typeof(T); 47 | } 48 | 49 | 50 | 51 | public InterleavedBuffer CopyAt(int index1, InterleavedBuffer attribute, int index2) 52 | { 53 | index1 *= this.Stride; 54 | index2 *= attribute.Stride; 55 | 56 | for (int i = 0, l = this.Stride; i < l; i++) 57 | { 58 | this.Array[index1 + i] = attribute.Array[index2 + i]; 59 | } 60 | 61 | return this; 62 | } 63 | 64 | public InterleavedBuffer Set(List value, int offset) 65 | { 66 | List list = new List(); 67 | list = this.Array.ToList(); 68 | for (int i = offset; i < value.Count; i++) 69 | { 70 | list.Insert(i, value[i - offset]); 71 | } 72 | this.Array = list.ToArray(); 73 | return this; 74 | } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.14.35906.104 d17.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THREE.Avalonia", "THREE.Avalonia\THREE.Avalonia.csproj", "{EBCA2272-7074-D0D9-95ED-39BC40236A5E}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THREE.Loaders.GltfLoader", "THREE.GltfLoader\THREE.Loaders.GltfLoader.csproj", "{99D77ABE-525D-1283-CD50-144265EB120A}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THREE.Avalonia.TestApp", "THREE.Avalonia.TestApp\THREE.Avalonia.TestApp.csproj", "{69987A99-9413-DB1D-31B2-AF87D8792CA0}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {EBCA2272-7074-D0D9-95ED-39BC40236A5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {EBCA2272-7074-D0D9-95ED-39BC40236A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {EBCA2272-7074-D0D9-95ED-39BC40236A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {EBCA2272-7074-D0D9-95ED-39BC40236A5E}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {99D77ABE-525D-1283-CD50-144265EB120A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {99D77ABE-525D-1283-CD50-144265EB120A}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {99D77ABE-525D-1283-CD50-144265EB120A}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {99D77ABE-525D-1283-CD50-144265EB120A}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {69987A99-9413-DB1D-31B2-AF87D8792CA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {69987A99-9413-DB1D-31B2-AF87D8792CA0}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {69987A99-9413-DB1D-31B2-AF87D8792CA0}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {69987A99-9413-DB1D-31B2-AF87D8792CA0}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {B0FC8EEA-DE69-4F30-97C6-7ABD989A2058} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Math/Spherical.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class Spherical : ICloneable 7 | { 8 | public float Radius; 9 | public float Phi; 10 | public float Theta; 11 | 12 | public Spherical(float radius = 1, float phi = 0, float theta = 0) 13 | { 14 | Radius = radius; 15 | Phi = phi; 16 | Theta = theta; 17 | } 18 | public Spherical(Spherical source) 19 | { 20 | Radius = source.Radius; 21 | Phi = source.Phi; 22 | Theta = source.Theta; 23 | } 24 | public object Clone() 25 | { 26 | return new Spherical(this); 27 | } 28 | 29 | public Spherical Set(float radius, float phi, float theta) 30 | { 31 | Radius = radius; 32 | Phi = phi; 33 | Theta = theta; 34 | 35 | return this; 36 | } 37 | public Spherical Copy(Spherical source) 38 | { 39 | Radius = source.Radius; 40 | Phi = source.Phi; 41 | Theta = source.Theta; 42 | 43 | return this; 44 | } 45 | // restrict phi to be betwee EPS and PI-EPS 46 | public Spherical makeSafe() 47 | { 48 | 49 | float EPS = 0.000001f; 50 | this.Phi = (float)System.Math.Max(EPS, System.Math.Min(System.Math.PI - EPS, this.Phi)); 51 | 52 | return this; 53 | 54 | } 55 | public Spherical SetFromVector3(Vector3 v) 56 | { 57 | return this.setFromCartesianCoords(v.X, v.Y, v.Z); 58 | } 59 | public Spherical setFromCartesianCoords(float x, float y, float z) 60 | { 61 | 62 | this.Radius = (float)System.Math.Sqrt(x * x + y * y + z * z); 63 | 64 | if (this.Radius == 0) 65 | { 66 | 67 | this.Theta = 0; 68 | this.Phi = 0; 69 | 70 | } 71 | else 72 | { 73 | 74 | this.Theta = (float)System.Math.Atan2(x, z); 75 | this.Phi = (float)System.Math.Acos(ExtensionMethods.Clamp(y / this.Radius, -1, 1)); 76 | 77 | } 78 | return this; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Helpers/PlaneHelper.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class PlaneHelper : Line 8 | { 9 | public Plane Plane { get; set; } 10 | public float Size { get; set; } 11 | public PlaneHelper(Plane plane, float? size, int? hex) : base() 12 | { 13 | var color = (hex != null) ? hex.Value : 0xffff00; 14 | 15 | float[] positions = new float[] { 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 }; 16 | 17 | var geometry = new BufferGeometry(); 18 | geometry.SetAttribute("position", new BufferAttribute(positions, 3)); 19 | geometry.ComputeBoundingSphere(); 20 | 21 | this.InitGeometry(geometry, new LineBasicMaterial() { Color = Color.Hex(color), ToneMapped = false }); 22 | 23 | this.type = "PlaneHelper"; 24 | 25 | this.Plane = plane; 26 | 27 | this.Size = (size == null) ? 1 : size.Value; 28 | 29 | float[] positions2 = new float[] { 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1 }; 30 | 31 | var geometry2 = new BufferGeometry(); 32 | geometry2.SetAttribute("position", new BufferAttribute(positions2, 3)); 33 | geometry2.ComputeBoundingSphere(); 34 | 35 | this.Add(new Mesh(geometry2, new MeshBasicMaterial() { Color = Color.Hex(color), Opacity = 0.2f, Transparent = true, DepthWrite = false, ToneMapped = false })); 36 | } 37 | public PlaneHelper(SerializationInfo info, StreamingContext context) : base(info, context) { } 38 | 39 | 40 | public override void UpdateMatrixWorld(bool force = false) 41 | { 42 | var scale = -this.Plane.Constant; 43 | 44 | if (System.Math.Abs(scale) < 1e-8) scale = 1e-8f; // sign does not matter 45 | 46 | this.Scale.Set(0.5f * this.Size, 0.5f * this.Size, scale); 47 | 48 | this.Children[0].Material.Side = (scale < 0) ? Constants.BackSide : Constants.FrontSide; // renderer flips side when determinant < 0; flipping not wanted here 49 | 50 | this.LookAt(this.Plane.Normal); 51 | 52 | base.UpdateMatrixWorld(force); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/IControlsContainer.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Input; 2 | using Avalonia.OpenGL.Controls; 3 | using OpenTK.Windowing.Common; 4 | namespace THREE 5 | { 6 | public interface IControlsContainer 7 | { 8 | Rectangle ClientRectangle { get; } 9 | event Action MouseDown; 10 | event Action MouseUp; 11 | event Action MouseMove; 12 | event Action MouseWheel; 13 | event Action MouseEnter; 14 | event Action MouseLeave; 15 | event Action SizeChanged; 16 | event Action KeyDown; 17 | event Action KeyUp; 18 | event Action KeyPress; 19 | } 20 | 21 | public class KeyPressEventArgs 22 | { 23 | public KeyPressEventArgs(string ch) 24 | { 25 | //throw new NotImplementedException(); 26 | } 27 | } 28 | 29 | public class KeyboardKeyControlContainerEventArgs 30 | { 31 | public KeyboardKeyControlContainerEventArgs(Keys key, int scanCode, KeyModifiers modifer, bool b) 32 | { 33 | //throw new NotImplementedException(); 34 | } 35 | 36 | public object Key { get; set; } 37 | } 38 | 39 | public class PointerControlContainerEventArgs 40 | { 41 | public PointerControlContainerEventArgs(OpenGlControlBase control, PointerEventArgs e, double delta = 0) 42 | { 43 | var pos = e.GetPosition(control); 44 | X = (int)pos.X; 45 | Y = (int)pos.Y; 46 | 47 | var pt = e.GetCurrentPoint(control).Properties; 48 | if (pt.IsLeftButtonPressed) 49 | Button = MouseButton.Left; 50 | if (pt.IsRightButtonPressed) 51 | Button = MouseButton.Right; 52 | if (pt.IsMiddleButtonPressed) 53 | Button = MouseButton.Middle; 54 | 55 | Delta = (float)delta; 56 | } 57 | 58 | public int X { get; set; } 59 | public int Y { get; set; } 60 | public MouseButton Button { get; set; } 61 | public float Delta { get; set; } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Geometries/DodecahedronGeometry.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class DodecahedronGeometry : Geometry 8 | { 9 | public Hashtable parameters; 10 | 11 | public DodecahedronGeometry(float? radius = null, float? detail = null) : base() 12 | { 13 | parameters = new Hashtable() 14 | { 15 | {"radius",radius }, 16 | {"detail",detail } 17 | }; 18 | 19 | this.FromBufferGeometry(new DodecahedronBufferGeometry(radius, detail)); 20 | this.MergeVertices(); 21 | } 22 | 23 | } 24 | 25 | [Serializable] 26 | public class DodecahedronBufferGeometry : PolyhedronBufferGeometry 27 | { 28 | static float t = (1 + (float)System.Math.Sqrt(5)) / 2; 29 | 30 | static float r = 1 / t; 31 | 32 | static List vertices = new List 33 | { 34 | // (±1, ±1, ±1) 35 | -1, -1, -1, -1, -1, 1, 36 | -1, 1, -1, -1, 1, 1, 37 | 1, -1, -1, 1, -1, 1, 38 | 1, 1, -1, 1, 1, 1, 39 | 40 | // (0, ±1/φ, ±φ) 41 | 0, -r, -t, 0, -r, t, 42 | 0, r, -t, 0, r, t, 43 | 44 | // (±1/φ, ±φ, 0) 45 | -r, -t, 0, -r, t, 0, 46 | r, -t, 0, r, t, 0, 47 | 48 | // (±φ, 0, ±1/φ) 49 | -t, 0, -r, t, 0, -r, 50 | -t, 0, r, t, 0, r 51 | }; 52 | 53 | static List indices = new List 54 | { 55 | 3, 11, 7, 3, 7, 15, 3, 15, 13, 56 | 7, 19, 17, 7, 17, 6, 7, 6, 15, 57 | 17, 4, 8, 17, 8, 10, 17, 10, 6, 58 | 8, 0, 16, 8, 16, 2, 8, 2, 10, 59 | 0, 12, 1, 0, 1, 18, 0, 18, 16, 60 | 6, 10, 2, 6, 2, 13, 6, 13, 15, 61 | 2, 16, 18, 2, 18, 3, 2, 3, 13, 62 | 18, 1, 9, 18, 9, 11, 18, 11, 3, 63 | 4, 14, 12, 4, 12, 0, 4, 0, 8, 64 | 11, 9, 5, 11, 5, 19, 11, 19, 7, 65 | 19, 5, 14, 19, 14, 4, 19, 4, 17, 66 | 1, 12, 14, 1, 14, 5, 1, 5, 9 67 | }; 68 | 69 | public DodecahedronBufferGeometry(float? radius = null, float? detail = null) : base(vertices, indices, radius, detail) 70 | { 71 | 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Postprocessing/FilmPass.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using THREE.Renderers.Shaders; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class FilmPass : Pass 9 | { 10 | public GLUniforms uniforms; 11 | 12 | public ShaderMaterial material; 13 | 14 | public FilmPass(float? noiseIntensity, float? scanlinesIntensity, float? scanlinesCount, bool? grayscale) 15 | { 16 | var shader = new FilmShader(); 17 | 18 | this.uniforms = UniformsUtils.CloneUniforms(shader.Uniforms); 19 | 20 | material = new ShaderMaterial(); 21 | material.Uniforms = uniforms; 22 | material.VertexShader = shader.VertexShader; 23 | material.FragmentShader = shader.FragmentShader; 24 | 25 | 26 | if (grayscale != null) (this.uniforms["grayscale"] as GLUniform)["value"] = grayscale.Value; 27 | if (noiseIntensity != null) (this.uniforms["nIntensity"] as GLUniform)["value"] = noiseIntensity.Value; 28 | if (scanlinesIntensity != null) (this.uniforms["sIntensity"] as GLUniform)["value"] = scanlinesIntensity.Value; 29 | if (scanlinesCount != null) (this.uniforms["sCount"] as GLUniform)["value"] = scanlinesCount.Value; 30 | 31 | this.fullScreenQuad = new Pass.FullScreenQuad(this.material); 32 | } 33 | 34 | public override void Render(GLRenderer renderer, GLRenderTarget writeBuffer, GLRenderTarget readBuffer, float? deltaTime = null, bool? maskActive = null) 35 | { 36 | (this.uniforms["tDiffuse"] as GLUniform)["value"] = readBuffer.Texture; 37 | float currentDeltaTime = (float)(this.uniforms["time"] as GLUniform)["value"] + deltaTime.Value; 38 | (this.uniforms["time"] as GLUniform)["value"] = currentDeltaTime; 39 | 40 | if (this.RenderToScreen) 41 | { 42 | 43 | renderer.SetRenderTarget(null); 44 | this.fullScreenQuad.Render(renderer); 45 | 46 | } 47 | else 48 | { 49 | 50 | renderer.SetRenderTarget(writeBuffer); 51 | if (this.Clear) renderer.Clear(); 52 | this.fullScreenQuad.Render(renderer); 53 | 54 | } 55 | } 56 | 57 | public override void SetSize(float width, float height) 58 | { 59 | 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Math/Vector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public abstract class Vector : ICloneable, IEquatable 7 | { 8 | public abstract Vector SetComponent(int index, float value); 9 | 10 | public abstract float GetComponent(int index); 11 | 12 | public abstract Vector Set(float x, float y); 13 | 14 | public abstract Vector Set(float x, float y, float z); 15 | 16 | public abstract Vector Set(float x, float y, float z, float w); 17 | 18 | public abstract void SetScalar(float scalar); 19 | 20 | public abstract Vector Copy(Vector v); 21 | 22 | public abstract Vector Add(Vector v); 23 | 24 | public abstract Vector AddVectors(Vector a, Vector b); 25 | 26 | public abstract Vector AddScalar(float s); 27 | 28 | public abstract Vector AddScaledVector(Vector v, float s); 29 | 30 | public abstract Vector Sub(Vector v); 31 | 32 | public abstract Vector SubVectors(Vector a, Vector b); 33 | 34 | public abstract Vector MultiplyScalar(float s); 35 | 36 | public abstract Vector DivideScalar(float s); 37 | 38 | public abstract Vector Negate(); 39 | 40 | public abstract float Dot(Vector v); 41 | 42 | public abstract float LengthSq(); 43 | 44 | public abstract float Length(); 45 | 46 | public abstract Vector Normalize(); 47 | 48 | public abstract float DistanceTo(Vector v); 49 | 50 | public abstract float DistanceToSquared(Vector v); 51 | 52 | public abstract Vector ApplyMatrix3(Matrix3 m); 53 | 54 | public abstract Vector Min(Vector v); 55 | 56 | public abstract Vector Max(Vector v); 57 | 58 | public abstract Vector Clamp(Vector min, Vector max); 59 | 60 | public abstract Vector ClampScalar(float minVal, float maxVal); 61 | 62 | public abstract Vector ClampLength(float min, float max); 63 | 64 | public abstract Vector Floor(); 65 | 66 | public abstract Vector Ceil(); 67 | 68 | public abstract Vector Round(); 69 | 70 | public abstract Vector RoundToZero(); 71 | 72 | public abstract Vector SetLength(float length); 73 | 74 | public abstract Vector Lerp(Vector v, float alpha); 75 | 76 | public abstract object Clone(); 77 | 78 | public abstract bool Equals(Vector other); 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extras/Core/Interpolations.cs: -------------------------------------------------------------------------------- 1 | namespace THREE 2 | { 3 | [Serializable] 4 | public class Interpolations 5 | { 6 | /** 7 | * author zz85 / http://www.lab4games.net/zz85/blog 8 | * 9 | * Bezier Curves formulas obtained from 10 | * http://en.wikipedia.org/wiki/Bézier_curve 11 | */ 12 | 13 | public static float CatmullRom(float t, float p0, float p1, float p2, float p3) 14 | { 15 | 16 | var v0 = (p2 - p0) * 0.5f; 17 | var v1 = (p3 - p1) * 0.5f; 18 | var t2 = t * t; 19 | var t3 = t * t2; 20 | 21 | return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; 22 | 23 | } 24 | 25 | // 26 | 27 | public static float QuadraticBezierP0(float t, float p) 28 | { 29 | 30 | var k = 1 - t; 31 | return k * k * p; 32 | 33 | } 34 | 35 | public static float QuadraticBezierP1(float t, float p) 36 | { 37 | 38 | return 2 * (1 - t) * t * p; 39 | 40 | } 41 | 42 | public static float QuadraticBezierP2(float t, float p) 43 | { 44 | 45 | return t * t * p; 46 | 47 | } 48 | 49 | public static float QuadraticBezier(float t, float p0, float p1, float p2) 50 | { 51 | 52 | return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + 53 | QuadraticBezierP2(t, p2); 54 | 55 | } 56 | 57 | // 58 | 59 | public static float CubicBezierP0(float t, float p) 60 | { 61 | 62 | var k = 1 - t; 63 | return k * k * k * p; 64 | 65 | } 66 | 67 | public static float CubicBezierP1(float t, float p) 68 | { 69 | 70 | var k = 1 - t; 71 | return 3 * k * k * t * p; 72 | 73 | } 74 | 75 | public static float CubicBezierP2(float t, float p) 76 | { 77 | 78 | return 3 * (1 - t) * t * t * p; 79 | 80 | } 81 | 82 | public static float CubicBezierP3(float t, float p) 83 | { 84 | 85 | return t * t * t * p; 86 | 87 | } 88 | 89 | public static float CubicBezier(float t, float p0, float p1, float p2, float p3) 90 | { 91 | 92 | return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + 93 | CubicBezierP3(t, p3); 94 | 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Loaders/BufferGeometryLoader.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System.Collections; 3 | using System.IO; 4 | using System.Linq; 5 | 6 | namespace THREE 7 | { 8 | [Serializable] 9 | public class BufferGeometryLoader 10 | { 11 | Hashtable interleavedBufferMap = new Hashtable(); 12 | Hashtable arrayBufferMap = new Hashtable(); 13 | 14 | public BufferGeometryLoader() 15 | { 16 | 17 | } 18 | 19 | public BufferGeometry Load(string fileName) 20 | { 21 | string text = File.ReadAllText(fileName); 22 | JObject jobject = JObject.Parse(text); 23 | return Parse(jobject); 24 | } 25 | 26 | public BufferGeometry Parse(JObject json) 27 | { 28 | BufferGeometry geometry = null; 29 | 30 | if (json.ContainsKey("isInstancedBufferGeometry")) 31 | { 32 | geometry = new InstancedBufferGeometry(); 33 | } 34 | else 35 | { 36 | geometry = new BufferGeometry(); 37 | } 38 | 39 | object indexObj = json["data"]["index"]; 40 | 41 | if (indexObj != null) 42 | { 43 | 44 | int itemSize = (int)(indexObj as JObject)["itemSize"]; 45 | JToken arrayToken = (indexObj as JObject)["array"]; 46 | int[] index = arrayToken.ToObject(); 47 | geometry.SetIndex(index.ToList()); 48 | } 49 | 50 | JObject data = (JObject)json["data"]; 51 | 52 | if (data != null) 53 | { 54 | JObject attributes = (JObject)data["attributes"]; 55 | if (attributes != null) 56 | { 57 | foreach (var o in attributes) 58 | { 59 | JObject attribute = (JObject)attributes[o.Key]; 60 | if (attribute != null) 61 | { 62 | int itemSize = (int)attribute["itemSize"]; 63 | JToken arrayToken = attribute["array"]; 64 | float[] floatArray = arrayToken.ToObject(); 65 | geometry.SetAttribute(o.Key, new BufferAttribute(floatArray, itemSize)); 66 | } 67 | } 68 | } 69 | } 70 | return geometry; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Core/GLBufferAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class GLBufferAttribute : Dictionary 8 | { 9 | public int Version = 0; 10 | public int Buffer 11 | { 12 | get 13 | { 14 | return (int)this["buffer"]; 15 | } 16 | set 17 | { 18 | this["buffer"] = value; 19 | } 20 | } 21 | 22 | public int Type 23 | { 24 | get 25 | { 26 | return (int)this["type"]; 27 | } 28 | set 29 | { 30 | this["type"] = value; 31 | } 32 | } 33 | 34 | public int ItemSize 35 | { 36 | get 37 | { 38 | return (int)this["itemSize"]; 39 | } 40 | set 41 | { 42 | this["itemSize"] = value; 43 | } 44 | } 45 | public bool NeedsUpdate 46 | { 47 | get 48 | { 49 | return (bool)this["needsUpdate"]; 50 | } 51 | set 52 | { 53 | this.Version++; 54 | this["needsUpdate"] = value; 55 | } 56 | } 57 | 58 | public int ElementSize 59 | { 60 | get 61 | { 62 | return (int)this["elementSize"]; 63 | } 64 | set 65 | { 66 | this["elementSize"] = value; 67 | } 68 | } 69 | 70 | public int count 71 | { 72 | get 73 | { 74 | return (int)this["count"]; 75 | } 76 | set 77 | { 78 | this["count"] = value; 79 | } 80 | } 81 | 82 | bool isGLBufferAttribute = true; 83 | 84 | 85 | public GLBufferAttribute(int buffer, int type, int itemSize, int elementSize, int count) 86 | { 87 | this.Buffer = buffer; 88 | this.Type = type; 89 | this.ItemSize = itemSize; 90 | this.ElementSize = elementSize; 91 | this.count = count; 92 | 93 | } 94 | public GLBufferAttribute() :base() { } 95 | public GLBufferAttribute(SerializationInfo info, StreamingContext context) : base(info, context) { } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/FilmShader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class FilmShader : ShaderMaterial 8 | { 9 | public FilmShader() 10 | { 11 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 12 | Uniforms.Add("time", new GLUniform { { "value", 0.0f } }); 13 | Uniforms.Add("nIntensity", new GLUniform { { "value", 0.5f } }); 14 | Uniforms.Add("sIntensity", new GLUniform { { "value", 0.05f } }); 15 | Uniforms.Add("sCount", new GLUniform { { "value", 4096 } }); 16 | Uniforms.Add("grayscale", new GLUniform { { "value", 1 } }); 17 | 18 | VertexShader = @" 19 | varying vec2 vUv; 20 | 21 | void main() { 22 | vUv = uv; 23 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 24 | 25 | } 26 | 27 | 28 | 29 | 30 | " 31 | ; 32 | 33 | FragmentShader = @" 34 | #include 35 | 36 | // control parameter 37 | uniform float time; 38 | 39 | uniform bool grayscale; 40 | 41 | // noise effect intensity value (0 = no effect, 1 = full effect) 42 | uniform float nIntensity; 43 | 44 | // scanlines effect intensity value (0 = no effect, 1 = full effect) 45 | uniform float sIntensity; 46 | 47 | // scanlines effect count value (0 = no effect, 4096 = full effect) 48 | uniform float sCount; 49 | 50 | uniform sampler2D tDiffuse; 51 | 52 | varying vec2 vUv; 53 | 54 | void main() { 55 | 56 | // sample the source 57 | vec4 cTextureScreen = texture2D( tDiffuse, vUv ); 58 | 59 | // make some noise 60 | float dx = rand( vUv + time ); 61 | 62 | // add noise 63 | vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 ); 64 | 65 | // get us a sine and cosine 66 | vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) ); 67 | 68 | // add scanlines 69 | cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity; 70 | 71 | // interpolate between source and result by intensity 72 | cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb ); 73 | 74 | // convert to grayscale if desired 75 | if( grayscale ) { 76 | 77 | cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 ); 78 | 79 | } 80 | 81 | gl_FragColor = vec4( cResult, cTextureScreen.a ); 82 | 83 | } 84 | " 85 | ; 86 | 87 | 88 | } 89 | 90 | public FilmShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Postprocessing/HalftonePass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using THREE.Renderers.Shaders; 4 | 5 | namespace THREE 6 | { 7 | [Serializable] 8 | public class HalftonePass : Pass 9 | { 10 | public GLUniforms uniforms; 11 | public ShaderMaterial material; 12 | public HalftonePass(float? width = null, float? height = null, Hashtable parameter = null) : base() 13 | { 14 | var halftoneShader = new HalftoneShader(); 15 | uniforms = UniformsUtils.CloneUniforms(halftoneShader.Uniforms); 16 | this.material = new ShaderMaterial 17 | { 18 | Uniforms = this.uniforms, 19 | FragmentShader = halftoneShader.FragmentShader, 20 | VertexShader = halftoneShader.VertexShader 21 | }; 22 | 23 | // set params 24 | 25 | (this.uniforms["width"] as GLUniform)["value"] = width; 26 | (this.uniforms["height"] as GLUniform)["value"] = height; 27 | 28 | if (parameter != null) 29 | { 30 | 31 | 32 | foreach (DictionaryEntry key in parameter) 33 | { 34 | 35 | if (key.Value != null && this.uniforms.ContainsKey((string)key.Key)) 36 | { 37 | (this.uniforms[(string)key.Key] as GLUniform)["value"] = key.Value; 38 | } 39 | } 40 | } 41 | this.fullScreenQuad = new Pass.FullScreenQuad(this.material); 42 | } 43 | public override void Render(GLRenderer renderer, GLRenderTarget writeBuffer, GLRenderTarget readBuffer, float? deltaTime = null, bool? maskActive = null) 44 | { 45 | (this.material.Uniforms["tDiffuse"] as GLUniform)["value"] = readBuffer.Texture; 46 | 47 | if (this.RenderToScreen) 48 | { 49 | 50 | renderer.SetRenderTarget(null); 51 | this.fullScreenQuad.Render(renderer); 52 | 53 | } 54 | else 55 | { 56 | 57 | renderer.SetRenderTarget(writeBuffer); 58 | if (this.Clear) renderer.Clear(); 59 | this.fullScreenQuad.Render(renderer); 60 | 61 | } 62 | } 63 | 64 | public override void SetSize(float width, float height) 65 | { 66 | (this.uniforms["width"] as GLUniform)["value"] = width; 67 | (this.uniforms["height"] as GLUniform)["value"] = height; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLInfo.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | 6 | namespace THREE 7 | { 8 | [Serializable] 9 | public class GLInfo 10 | { 11 | [Serializable] 12 | public struct Memory 13 | { 14 | public int Geometries; 15 | 16 | public int Textures; 17 | } 18 | 19 | [Serializable] 20 | public struct Render 21 | { 22 | public int Frame; 23 | 24 | public int Calls; 25 | 26 | public int Triangles; 27 | 28 | public int Points; 29 | 30 | public int Lines; 31 | } 32 | public Memory memory = new Memory { Geometries = 0, Textures = 0 }; 33 | 34 | public Render render = new Render { Frame = 0, Calls = 0, Triangles = 0, Points = 0, Lines = 0 }; 35 | 36 | public List programs; 37 | 38 | public bool AutoReset = true; 39 | 40 | public GLInfo() 41 | { 42 | } 43 | 44 | public void Update(int count, int mode, int? instanceCount = null) 45 | { 46 | if (instanceCount == null) instanceCount = 1; 47 | 48 | this.render.Calls++; 49 | 50 | PrimitiveType type = (PrimitiveType)Enum.ToObject(typeof(PrimitiveType), mode); 51 | 52 | switch (type) 53 | { 54 | case PrimitiveType.Triangles: 55 | render.Triangles += (int)instanceCount * (count / 3); 56 | break; 57 | case PrimitiveType.Lines: 58 | render.Lines += (int)instanceCount * (count / 2); 59 | break; 60 | case PrimitiveType.LineStrip: 61 | render.Lines += (int)instanceCount * (count - 1); 62 | break; 63 | case PrimitiveType.LineLoop: 64 | render.Lines += (int)instanceCount * count; 65 | break; 66 | case PrimitiveType.Points: 67 | render.Points += (int)instanceCount * count; 68 | break; 69 | default: 70 | Trace.TraceError("THREE.gl.GLInfo:Unknown draw mode:", mode); 71 | break; 72 | } 73 | } 74 | public void Reset() 75 | { 76 | render.Frame++; 77 | render.Calls = 0; 78 | render.Triangles = 0; 79 | render.Points = 0; 80 | render.Lines = 0; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extensions/GLUniformsLoader.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace THREE.OpenGL.Extensions 10 | { 11 | public class GLUniformsLoader 12 | { 13 | public static void Upload(List Seq, GLUniforms values, GLTextures textures) 14 | { 15 | for (int i = 0, n = Seq.Count; i != n; ++i) 16 | { 17 | var u = Seq[i]; 18 | object v = (values[u.Id] as GLUniform)["value"]; 19 | if (v == null) continue; 20 | 21 | var property = v.GetType().GetProperty("NeedsUpdate"); 22 | 23 | if (u.UniformKind.Equals("SingleUniform")) 24 | { 25 | 26 | (u as SingleUniform).SetValue(v, textures); 27 | 28 | ErrorCode error = GL.GetError(); 29 | 30 | if (error == ErrorCode.InvalidOperation) 31 | { 32 | //Debugger.Break(); 33 | Console.WriteLine(error.ToString()); 34 | } 35 | } 36 | else if (u.UniformKind.Equals("PureArrayUniform")) 37 | { 38 | (u as PureArrayUniform).SetValue(v, textures); 39 | ErrorCode error = GL.GetError(); 40 | if (error == ErrorCode.InvalidOperation) 41 | { 42 | //Debugger.Break(); 43 | Console.WriteLine(error.ToString()); 44 | } 45 | } 46 | else 47 | { 48 | 49 | (u as StructuredUniform).SetValue(v, textures); 50 | ErrorCode error = GL.GetError(); 51 | if (error == ErrorCode.InvalidOperation) 52 | { 53 | //Debugger.Break(); 54 | Console.WriteLine(error.ToString()); 55 | } 56 | } 57 | } 58 | } 59 | public static List SeqWithValue(List seq, GLUniforms values) 60 | { 61 | List r = new List(); 62 | 63 | for (int i = 0, n = seq.Count; i != n; ++i) 64 | { 65 | var u = seq[i]; 66 | if (values.ContainsKey(u.Id)) 67 | r.Add(u); 68 | } 69 | return r; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Shaders/ConvolutionShader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Serialization; 3 | 4 | namespace THREE 5 | { 6 | [Serializable] 7 | public class ConvolutionShader : ShaderMaterial 8 | { 9 | public ConvolutionShader() 10 | { 11 | Defines.Add("KERNEL_SIZE_FLOAT", "25.0"); 12 | Defines.Add("KERNEL_SIZE_INT", "25"); 13 | 14 | Uniforms.Add("tDiffuse", new GLUniform { { "value", null } }); 15 | Uniforms.Add("uImageIncrement", new GLUniform { { "value", new Vector2(0.001953125f, 0.0f) } }); 16 | Uniforms.Add("cKernel", new GLUniform { { "value", new List() } }); 17 | 18 | VertexShader = @" 19 | uniform vec2 uImageIncrement; 20 | 21 | 22 | varying vec2 vUv; 23 | 24 | void main() { 25 | 26 | vUv = uv - ( ( KERNEL_SIZE_FLOAT - 1.0 ) / 2.0 ) * uImageIncrement; 27 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 28 | 29 | } 30 | " 31 | ; 32 | FragmentShader = @" 33 | uniform float cKernel[KERNEL_SIZE_INT]; 34 | 35 | uniform sampler2D tDiffuse; 36 | uniform vec2 uImageIncrement; 37 | 38 | varying vec2 vUv; 39 | 40 | void main() { 41 | 42 | vec2 imageCoord = vUv; 43 | vec4 sum = vec4( 0.0, 0.0, 0.0, 0.0 ); 44 | 45 | for( int i = 0; i < KERNEL_SIZE_INT; i ++ ) { 46 | sum += texture2D( tDiffuse, imageCoord ) * cKernel[ i ]; 47 | imageCoord += uImageIncrement; 48 | 49 | } 50 | 51 | gl_FragColor = sum; 52 | 53 | } 54 | " 55 | ; 56 | 57 | } 58 | 59 | public ConvolutionShader(SerializationInfo info, StreamingContext context) : base(info, context) { } 60 | 61 | public List BuildKernel(float sigma) 62 | { 63 | List values = new List(); 64 | 65 | int kMaxKernelSize = 25; 66 | int kernelSize = 2 * (int)System.Math.Ceiling(sigma * 3.0f) + 1; 67 | if (kernelSize > kMaxKernelSize) kernelSize = kMaxKernelSize; 68 | 69 | float sum = 0.0f; 70 | float halfWidth = (kernelSize - 1) * 0.5f; 71 | 72 | for (int i = 0; i < kernelSize; i++) 73 | { 74 | values.Add(Gauss(i - halfWidth, sigma)); 75 | sum += values[i]; 76 | } 77 | 78 | for (int i = 0; i < kernelSize; i++) 79 | values[i] = values[i] / sum; 80 | 81 | return values; 82 | } 83 | 84 | private float Gauss(float x, float sigma) 85 | { 86 | return (float)System.Math.Exp(-(x * x) / (2.0f * sigma * sigma)); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/SpotLight.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class SpotLight : Light 7 | { 8 | public new float Power 9 | { 10 | get 11 | { 12 | return (float)(this.Intensity * System.Math.PI); 13 | } 14 | set 15 | { 16 | this.Intensity = (float)(value / System.Math.PI); 17 | } 18 | } 19 | 20 | public SpotLight() : base() 21 | { 22 | this.Position.Copy(Object3D.DefaultUp); 23 | this.UpdateMatrix(); 24 | 25 | this.Target = new Object3D(); 26 | 27 | this.Distance = 0; 28 | 29 | this.Angle = (float)(System.Math.PI / 3); 30 | 31 | this.Penumbra = 0; 32 | 33 | this.Decay = 1; 34 | 35 | this.Shadow = new SpotLightShadow(); 36 | 37 | this.type = "SpotLight"; 38 | } 39 | public SpotLight(Color color, float? intensity = null, float? distance = null, float? angle = null, float? penumbra = null, float? decay = null) 40 | : base(color, intensity) 41 | { 42 | this.Position.Copy(Object3D.DefaultUp); 43 | this.UpdateMatrix(); 44 | 45 | this.Target = new Object3D(); 46 | 47 | this.Distance = distance != null ? (float)distance : 0; 48 | 49 | this.Angle = angle != null ? (float)angle : (float)(System.Math.PI / 3); 50 | 51 | this.Penumbra = penumbra != null ? (float)penumbra : 0; 52 | 53 | this.Decay = decay != null ? (float)decay : 1; 54 | 55 | this.Shadow = new SpotLightShadow(); 56 | 57 | this.type = "SpotLight"; 58 | } 59 | public SpotLight(int color, float? intensity = null, float? distance = null, float? angle = null, float? penumbra = null, float? decay = null) : 60 | this(Color.Hex(color), intensity, distance, angle, penumbra, decay) 61 | { } 62 | 63 | public SpotLight(SerializationInfo info, StreamingContext context) : base(info, context) { } 64 | 65 | protected SpotLight(SpotLight other) : base(other) 66 | { 67 | this.Distance = other.Distance; 68 | 69 | this.Angle = other.Angle; 70 | 71 | this.Penumbra = other.Penumbra; 72 | 73 | this.Decay = other.Decay; 74 | 75 | this.Target = other.Target; 76 | 77 | this.Shadow = (SpotLightShadow)other.Shadow.Clone(); 78 | 79 | this.type = "SpotLight"; 80 | } 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Extensions/ImageExtension.cs: -------------------------------------------------------------------------------- 1 | using SkiaSharp; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace THREE 7 | { 8 | [Serializable] 9 | public struct RGBA 10 | { 11 | public byte B; 12 | public byte G; 13 | public byte R; 14 | public byte A; 15 | } 16 | [Serializable] 17 | public static class ImageExtension 18 | { 19 | public static byte[] ToByteArray(this float[] floatArray) 20 | { 21 | byte[] byteArray = new byte[floatArray.Length]; 22 | for (int i = 0; i < floatArray.Length; i++) 23 | byteArray[i] = (byte)(floatArray[i] * 255.0f); 24 | 25 | return byteArray; 26 | } 27 | public static SKBitmap ToSKBitMap(this byte[] byteArray,int width,int height) 28 | { 29 | SKBitmap bitmap = new SKBitmap(); 30 | 31 | // pin the managed array so that the GC doesn't move it 32 | var gcHandle = GCHandle.Alloc(byteArray, GCHandleType.Pinned); 33 | 34 | // install the pixels with the color type of the pixel data 35 | var info = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul); 36 | bitmap.InstallPixels(info, gcHandle.AddrOfPinnedObject(), info.RowBytes, null, delegate { gcHandle.Free(); }, null); 37 | 38 | return bitmap; 39 | } 40 | // => SKBitmap.Bytes -> byte[] 41 | //public static byte[] GetTextureImage(this SKBitmap image) 42 | //{ 43 | //List pixels = new List(); 44 | //BitmapData imageData = null; 45 | 46 | //imageData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat); 47 | //unsafe 48 | //{ 49 | // RGBA* pixelImage = (RGBA*)imageData.Scan0.ToPointer(); 50 | // for (int y = 0; y < image.Height; y++) 51 | // { 52 | // for (int x = 0; x < image.Width; x++) 53 | // { 54 | // int pixelIndex = y * image.Width + x; 55 | // RGBA pixelRGBA = pixelImage[pixelIndex]; 56 | // pixels.Add(pixelRGBA.R); 57 | // pixels.Add(pixelRGBA.G); 58 | // pixels.Add(pixelRGBA.B); 59 | // pixels.Add(pixelRGBA.A); 60 | // } 61 | // } 62 | //} 63 | //image.UnlockBits(imageData); 64 | 65 | //return pixels.ToArray(); 66 | //} 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Lights/PointLightShadow.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace THREE 4 | { 5 | [Serializable] 6 | public class PointLightShadow : LightShadow 7 | { 8 | 9 | 10 | private List _cubeDirections = new List 11 | { 12 | new Vector3(1,0,0), 13 | new Vector3(-1,0,0), 14 | new Vector3(0,0,1), 15 | new Vector3(0,0,-1), 16 | new Vector3(0,1,0), 17 | new Vector3(0,-1,0) 18 | }; 19 | 20 | private List _cubeUps = new List 21 | { 22 | new Vector3(0,1,0), 23 | new Vector3(0,1,0), 24 | new Vector3(0,1,0), 25 | new Vector3(0,1,0), 26 | new Vector3(0,0,1), 27 | new Vector3(0,0,-1) 28 | }; 29 | 30 | public PointLightShadow() 31 | : base(new PerspectiveCamera(90, 1, 0.5f, 500)) 32 | { 33 | _frameExtents = new Vector2(4, 2); 34 | this._viewportCount = 6; 35 | 36 | _viewports = new List 37 | { 38 | new Vector4(2,1,1,1), 39 | new Vector4(0,1,1,1), 40 | new Vector4(3,1,1,1), 41 | new Vector4(1,1,1,1), 42 | new Vector4(3,0,1,1), 43 | new Vector4(1,0,1,1) 44 | }; 45 | } 46 | 47 | public void UpdateMatrices(Light light, int? _viewportIndex = null) 48 | { 49 | int viewportIndex = 0; 50 | if (_viewportIndex == null) viewportIndex = 0; 51 | else viewportIndex = (int)_viewportIndex; 52 | 53 | var camera = this.Camera; 54 | var shadowMatrix = this.Matrix; 55 | var lightPositionWorld = this._lightPositionWorld; 56 | var lookTarget = this._lookTarget; 57 | var projScreenMatrix = this._projScreenMatrix; 58 | 59 | lightPositionWorld.SetFromMatrixPosition(light.MatrixWorld); 60 | camera.Position.Copy(lightPositionWorld); 61 | 62 | lookTarget.Copy(camera.Position); 63 | lookTarget.Add(this._cubeDirections[viewportIndex]); 64 | camera.Up.Copy(this._cubeUps[viewportIndex]); 65 | camera.LookAt(lookTarget); 66 | camera.UpdateMatrixWorld(); 67 | 68 | shadowMatrix.MakeTranslation(-lightPositionWorld.X, -lightPositionWorld.Y, -lightPositionWorld.Z); 69 | 70 | projScreenMatrix.MultiplyMatrices(camera.ProjectionMatrix, camera.MatrixWorldInverse); 71 | this._frustum.SetFromProjectionMatrix(projScreenMatrix); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Sources/THREE.Avalonia/Renderers/gl/GLProperties.cs: -------------------------------------------------------------------------------- 1 | using OpenTK.Graphics.ES30; 2 | using System.Collections; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Diagnostics; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace THREE 8 | { 9 | [Serializable] 10 | public class GLProperties 11 | { 12 | private Dictionary Properties = new Dictionary(); 13 | 14 | public GLProperties() 15 | { 16 | } 17 | 18 | public Hashtable Get(object obj) 19 | { 20 | Hashtable map = new Hashtable(); ; 21 | if (!Properties.ContainsKey(obj)) 22 | //if (!Properties.TryGetValue(obj, out map)) 23 | { 24 | Properties.Add(obj, map); 25 | } 26 | else 27 | { 28 | map = Properties[obj]; 29 | } 30 | return map; 31 | } 32 | 33 | public void Remove(object obj) 34 | { 35 | Properties.Remove(obj); 36 | } 37 | 38 | public void Update(object obj, object key, object value) 39 | { 40 | Hashtable map; 41 | if (!Properties.TryGetValue(obj, out map)) 42 | { 43 | map[key] = value; 44 | } 45 | } 46 | 47 | public void Dispose() 48 | { 49 | foreach (var entry in Properties) 50 | { 51 | if(entry.Key is Texture) 52 | { 53 | Hashtable hashtable = (Hashtable)entry.Value; 54 | foreach (DictionaryEntry entry1 in hashtable) 55 | { 56 | if(entry1.Key.Equals("glFramebuffer") || entry1.Key.Equals("glDepthbuffer")) 57 | { 58 | object value = hashtable[entry1.Key]; 59 | if (value is int) 60 | { 61 | GL.DeleteFramebuffer((int)value); 62 | } 63 | if(value is int[]) 64 | { 65 | int[] buffers = (int[])value; 66 | GL.DeleteFramebuffers(buffers.Length,buffers); 67 | } 68 | } 69 | if(entry1.Key.Equals("glTexture")) 70 | { 71 | GL.DeleteTexture((int)hashtable[entry1.Key]); 72 | } 73 | 74 | } 75 | } 76 | } 77 | Properties = new Dictionary(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | --------------------------------------------------------------------------------