Skip to content

.net Class Library for creating Three.js compatible objects

License

Notifications You must be signed in to change notification settings

mcneel/ThreeLib

Repository files navigation

ThreeLib

.net Class Library written in c# for creating Three.js compatible objects.

Build status

The scope of this project is focused on serialization (and later perhaps deserialization). Therefore the objects to be targeted should be those that can be read through one of the Three.js Loaders.

This library could be used to develop exporter plugins from 3d modelling software that support mono / .net.

This project started as project Iris, a Three.js exporter for Rhino3d. ThreeLib is essentially the serialization library from that project recreated as an open source project and rewritten to be more like working with Three.js. ThreeLib is what allows Iris to write Rhino Objects to json.

Docs

Dependencies

Usage

You can either clone this repo and build the ThreeLib.csproj or use the published NuGet package.

Check out the Sample project to see how some of the API is coming along.

For example:

var scene = new Scene
{
    Background = new  Color(255,0,255).ToInt(),
    Name = "My Scene"
};

var verts = new List<float[]>
{
    new float[] { 0, 0, 0 },
    new float[] { 0, 0, 10.1234f },
    new float[] { 10, 0, 10 },
    new float[] { 10, 0, 0 }
};

var norms = new List<float[]>
{
    new float[] { 0, 1, 0 },
    new float[] { 0, 1, 0 },
    new float[] { 0, 1, 0 },
    new float[] { 0, 1, 0 }
};

var vertices = Geometry.ProcessVertexArray(verts); //flattens a List<float[]>

var normals = Geometry.ProcessNormalArray(norms);

var face = new int[] { 0, 1, 2, 3 };

var faces = Geometry.ProcessFaceArray(new List<int[]> { { face } }, false, false);

var geometry = new Geometry(vertices, faces, normals);

var mesh = new Mesh
{
    Geometry = geometry,
    Material = material,
    Name = "My Mesh"
};

scene.Add(mesh);

scene.ToJSON(false);

Rsults in:

{
	"metadata" : {
		"version" : 4.5,
		"type" : "Object",
		"generator" : "ThreeLib-Object3D.toJSON"
	},
	"geometries" : [{
			"data" : {
				"vertices" : [0, 0, 0, 0, 0, 10.1234, 10, 0, 10, 10, 0, 0],
				"colors" : [],
				"faces" : [33, 0, 1, 2, 3, 0, 1, 2, 3],
				"uvs" : [],
				"normals" : [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0]
			},
			"matrix" : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
			"uuid" : "7989f47c-5e74-4d1b-830d-880ba402d78d",
			"type" : "Geometry"
		}
	],
	"materials" : [{
			"color" : 16777215,
			"roughness" : 1.0,
			"metalness" : 0.25,
			"opacity" : 1.0,
			"uuid" : "683ae9a3-608a-4982-b301-448bd8a41105",
			"type" : "MeshStandardMaterial"
		}
	],
	"object" : {
		"background" : 16711935,
		"children" : [{
				"geometry" : "7989f47c-5e74-4d1b-830d-880ba402d78d",
				"material" : "683ae9a3-608a-4982-b301-448bd8a41105",
				"matrix" : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
				"uuid" : "d48d6259-0eb6-466e-b484-65be547b1934",
				"name" : "My Mesh",
				"type" : "Mesh"
			}
		],
		"matrix" : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
		"uuid" : "da0f589a-50d3-4a65-91ed-061b28d961b5",
		"name" : "My Scene",
		"type" : "Scene"
	}
}

Current Status

Three.js Objects

Category Object Status
Animation - -
Animation / Tracks - -
Audio - -
Cameras Camera WIP
CubeCamera -
OrthographicCamera WIP
PerspectiveCamera WIP
StereoCamera -
Constants - -
Core BufferAttribute WIP
BufferGeometry WIP
Clock -
DirectGeometry -
EventDispatcher -
Face3 -
Geometry WIP
InstancedBufferAttribute -
InstancedBufferGeometry -
InstancedInterleavedBuffer -
InterleavedBuffer -
InterleavedBufferAttribute -
Layers -
Object3D WIP
Raycaster -
Uniform -
Core/BufferAttributes - -
Geometries - -
Lights AmbientLight WIP
DirectionalLight WIP
HemisphereLight WIP
Light WIP
PointLight WIP
RectAreaLight WIP
SpotLight WIP
Lights/Shadows DirectionalLightShadow WIP
LightShadow WIP
SpotLightShadow WIP
Materials LineBasicMaterial WIP
LineDashedMaterial -
Material WIP
MeshBasicMaterial WIP
MeshDepthMaterial WIP
MeshLambertMaterial WIP
MeshNormalMaterial WIP
MeshPhongMaterial WIP
MeshPhysicalMaterial WIP
MeshStandardMaterial WIP
MeshToonMaterial -
PointsMaterial WIP
RawShaderMaterial -
ShaderMaterial -
ShadowMaterial -
SpriteMaterial -
Math Box2 -
Box3 -
Color WIP
Cylindrical -
Euler WIP
Frustum -
Interpolant -
Line3 -
Math -
Matrix3 -
Matrix4 WIP
Plane -
Quaternion WIP
Ray -
Sphere -
Spherical -
Triangle -
Vector2 -
Vector3 WIP
Vector4 -
Objects Bone -
Group WIP
LensFlare -
Line WIP
LineLoop -
LineSegments -
LOD -
Mesh WIP
Points WIP
Skeleton -
SkinnedMesh -
Sprite -
Scenes Fog -
FogExp2 -
Scene WIP
Textures CompressedTexture -
CubeTexture -
DataTexture -
DepthTexture -
Texture WIP
VideoTexture -
Other Image WIP

About

.net Class Library for creating Three.js compatible objects

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages