Last active
August 25, 2021 02:46
-
-
Save aspose-3d/631532eeb21c3374f2ed to your computer and use it in GitHub Desktop.
This Gist contains .NET code snippets for examples of Aspose.3D for .NET.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize a Scene object | |
Scene scene = new Scene(); | |
// Create a Box model | |
scene.RootNode.CreateChildNode("box", new Box()); | |
// Create a Cylinder model | |
scene.RootNode.CreateChildNode("cylinder", new Cylinder()); | |
// Save drawing in the FBX format | |
MyDir = MyDir + RunExamples.GetOutputFilePath("test.fbx"); | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize scene object | |
Scene scene = new Scene(); | |
scene.Open(MyDir + "camera.3ds", FileFormat.Discreet3DS); | |
MyDir = MyDir + "FlipCoordinateSystem.obj"; | |
scene.Save(MyDir, FileFormat.WavefrontOBJ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// load a 3D file | |
Scene scene = new Scene(MyDir + "test.fbx"); | |
/* | |
* 3D format demonstration is simple | |
* | |
* struct File { | |
* MeshBlock blocks[]; | |
* }; | |
* | |
* struct Vertex { | |
* float x; | |
* float y; | |
* float z; | |
* }; | |
* | |
* struct Triangle { | |
* int a; | |
* int b; | |
* int c; | |
* }; | |
* | |
* struct MeshBlock { | |
* int numControlPoints; | |
* int numTriangles; | |
* Vertex vertices[numControlPoints]; | |
* Triangle faces[numTriangles]; | |
* }; | |
*/ | |
// open file for writing in binary mode | |
using (var writer = new BinaryWriter(new FileStream(MyDir + "Save3DMeshesInCustomBinaryFormat_out", FileMode.Create, FileAccess.Write))) | |
{ | |
// visit each descent nodes | |
scene.RootNode.Accept(delegate(Node node) | |
{ | |
foreach (Entity entity in node.Entities) | |
{ | |
// only convert meshes, lights/camera and other stuff will be ignored | |
if (!(entity is IMeshConvertible)) | |
continue; | |
Mesh m = ((IMeshConvertible)entity).ToMesh(); | |
var controlPoints = m.ControlPoints; | |
// triangulate the mesh, so triFaces will only store triangle indices | |
int[][] triFaces = PolygonModifier.Triangulate(controlPoints, m.Polygons); | |
// gets the global transform matrix | |
Matrix4 transform = node.GlobalTransform.TransformMatrix; | |
// write number of control points and triangle indices | |
writer.Write(controlPoints.Count); | |
writer.Write(triFaces.Length); | |
// write control points | |
for (int i = 0; i < controlPoints.Count; i++) | |
{ | |
// calculate the control points in world space and save them to file | |
var cp = transform * controlPoints[i]; | |
writer.Write((float)cp.x); | |
writer.Write((float)cp.y); | |
writer.Write((float)cp.z); | |
} | |
// write triangle indices | |
for (int i = 0; i < triFaces.Length; i++) | |
{ | |
writer.Write(triFaces[i][0]); | |
writer.Write(triFaces[i][1]); | |
writer.Write(triFaces[i][2]); | |
} | |
} | |
return true; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// load a 3D file | |
Scene scene = new Scene(MyDir + "test.fbx"); | |
/* | |
* 3D format demonstration is simple | |
* | |
* struct File { | |
* MeshBlock blocks[]; | |
* }; | |
* | |
* struct Vertex { | |
* float x; | |
* float y; | |
* float z; | |
* }; | |
* | |
* struct Triangle { | |
* int a; | |
* int b; | |
* int c; | |
* }; | |
* | |
* struct MeshBlock { | |
* int numControlPoints; | |
* int numTriangles; | |
* Vertex vertices[numControlPoints]; | |
* Triangle faces[numTriangles]; | |
* }; | |
*/ | |
// open file for writing in binary mode | |
using (var writer = new BinaryWriter(new FileStream(MyDir + "Save3DMeshesInCustomBinaryFormat_out", FileMode.Create, FileAccess.Write))) | |
{ | |
// visit each descent nodes | |
scene.RootNode.Accept(delegate(Node node) | |
{ | |
foreach (Entity entity in node.Entities) | |
{ | |
// only convert meshes, lights/camera and other stuff will be ignored | |
if (!(entity is IMeshConvertible)) | |
continue; | |
Mesh m = ((IMeshConvertible)entity).ToMesh(); | |
var controlPoints = m.ControlPoints; | |
// triangulate the mesh, so triFaces will only store triangle indices | |
int[][] triFaces = PolygonModifier.Triangulate(controlPoints, m.Polygons); | |
// gets the global transform matrix | |
Matrix4 transform = node.GlobalTransform.TransformMatrix; | |
// write number of control points and triangle indices | |
writer.Write(controlPoints.Count); | |
writer.Write(triFaces.Length); | |
// write control points | |
for (int i = 0; i < controlPoints.Count; i++) | |
{ | |
// calculate the control points in world space and save them to file | |
var cp = transform * controlPoints[i]; | |
writer.Write((float)cp.x); | |
writer.Write((float)cp.y); | |
writer.Write((float)cp.z); | |
} | |
// write triangle indices | |
for (int i = 0; i < triFaces.Length; i++) | |
{ | |
writer.Write(triFaces[i][0]); | |
writer.Write(triFaces[i][1]); | |
writer.Write(triFaces[i][2]); | |
} | |
} | |
return true; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load an existing 3D scene | |
Scene scene = new Scene(MyDir + "scene.obj"); | |
// Create an instance of the camera | |
Camera camera = new Camera(); | |
scene.RootNode.CreateChildNode("camera", camera).Transform.Translation = new Vector3(2, 44, 66); | |
// Set the target | |
camera.LookAt = new Vector3(50, 12, 0); | |
// Create a light | |
scene.RootNode.CreateChildNode("light", new Light() { Color = new Vector3(Color.White), LightType = LightType.Point }).Transform.Translation = new Vector3(26, 57, 43); | |
// The CreateRenderer will create a hardware OpenGL-backend renderer, more renderer will be added in the future | |
// And some internal initializations will be done. | |
// When the renderer left using the scope, the unmanaged hardware resources will also be disposed | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
renderer.EnableShadows = false; | |
// Create a new render target that renders the scene to texture(s) | |
// Use default render parameters | |
// And one output targets | |
// Size is 1024 x 1024 | |
// This render target can have multiple render output textures, but here we only need one output. | |
// The other textures and depth textures are mainly used by deferred shading in the future. | |
// But you can also access the depth texture through IRenderTexture.DepthTeture | |
using (IRenderTexture rt = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(), 1, 1024, 1024)) | |
{ | |
// This render target has one viewport to render, the viewport occupies the 100% width and 100% height | |
Viewport vp = rt.CreateViewport(camera, new RelativeRectangle() { ScaleWidth = 1, ScaleHeight = 1 }); | |
// Render the target and save the target texture to external file | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "Original_viewport_out.png", ImageFormat.Png); | |
// Create a post-processing effect | |
PostProcessing pixelation = renderer.GetPostProcessing("pixelation"); | |
renderer.PostProcessings.Add(pixelation); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "VisualEffect_pixelation_out.png", ImageFormat.Png); | |
// Clear previous post-processing effects and try another one | |
PostProcessing grayscale = renderer.GetPostProcessing("grayscale"); | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(grayscale); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "VisualEffect_grayscale_out.png", ImageFormat.Png); | |
// We can also combine post-processing effects | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(grayscale); | |
renderer.PostProcessings.Add(pixelation); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "VisualEffect_grayscale+pixelation_out.png", ImageFormat.Png); | |
// Clear previous post-processing effects and try another one | |
PostProcessing edgedetection = renderer.GetPostProcessing("edge-detection"); | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(edgedetection); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "VisualEffect_edgedetection_out.png", ImageFormat.Png); | |
// Clear previous post-processing effects and try another one | |
PostProcessing blur = renderer.GetPostProcessing("blur"); | |
renderer.PostProcessings.Clear(); | |
renderer.PostProcessings.Add(blur); | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "VisualEffect_blur_out.png", ImageFormat.Png); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load an existing 3D scene | |
Scene scene = new Scene(MyDir + "scene.obj"); | |
// Create an instance of the camera | |
Camera camera = new Camera(); | |
scene.RootNode.CreateChildNode("camera", camera).Transform.Translation = new Vector3(2, 44, 66); | |
// Set the target | |
camera.LookAt = new Vector3(50, 12, 0); | |
// Create a light | |
scene.RootNode.CreateChildNode("light", new Light() { Color = new Vector3(Color.White), LightType = LightType.Point }).Transform.Translation = new Vector3(26, 57, 43); | |
// The CreateRenderer will create a hardware OpenGL-backend renderer | |
// And some internal initializations will be done. | |
// When the renderer left using the scope, the unmanaged hardware resources will also be disposed | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
renderer.EnableShadows = false; | |
// Create a new render target that renders the scene to texture(s) | |
// Use default render parameters | |
// And one output targets | |
// Size is 1024 x 1024 | |
// This render target can have multiple render output textures, but here we only need one output. | |
// The other textures and depth textures are mainly used by deferred shading in the future. | |
// But you can also access the depth texture through IRenderTexture.DepthTeture | |
// Use CreateRenderWindow method to render in window, like: | |
// Window = renderer.RenderFactory.CreateRenderWindow(new RenderParameters(), Handle); | |
using (IRenderTexture rt = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(), 1, 1024, 1024)) | |
{ | |
// This render target has one viewport to render, the viewport occupies the 100% width and 100% height | |
Viewport vp = rt.CreateViewport(camera, new RelativeRectangle() { ScaleWidth = 1, ScaleHeight = 1 }); | |
// Render the target and save the target texture to external file | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "file-1viewports_out.png", ImageFormat.Png); | |
// Now let's change the previous viewport only uses the half left side(50% width and 100% height) | |
vp.Area = new RelativeRectangle() { ScaleWidth = 0.5f, ScaleHeight = 1 }; | |
// And create a new viewport that occupies the 50% width and 100% height and starts from 50% | |
// Both of them are using the same camera, so the rendered content should be the same | |
rt.CreateViewport(camera, new RelativeRectangle() { ScaleX = 0.5f, ScaleWidth = 0.5f, ScaleHeight = 1 }); | |
// But this time let's increase the field of view of the camera to 90 degree so it can see more part of the scene | |
camera.FieldOfView = 90; | |
renderer.Render(rt); | |
((ITexture2D)rt.Targets[0]).Save(MyDir + "file-2viewports_out.png", ImageFormat.Png); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Each cube node has their own translation | |
Node cube1 = scene.RootNode.CreateChildNode("cube1", mesh); | |
// Find translation property on node's transform object | |
Property translation = cube1.Transform.FindProperty("Translation"); | |
// Create a curve mapping based on translation property | |
CurveMapping mapping = new CurveMapping(scene, translation); | |
// Create the animation curve on X component of the scale | |
mapping.BindCurve("X", new Curve() | |
{ | |
// Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation | |
{0, 10.0f, Interpolation.Bezier}, | |
// Move node's translation to (20, 0, -10) at 3 sec | |
{3, 20.0f, Interpolation.Bezier}, | |
// Move node's translation to (30, 0, 0) at 5 sec | |
{5, 30.0f, Interpolation.Linear}, | |
}); | |
// Create the animation curve on Z component of the scale | |
mapping.BindCurve("Z", new Curve() | |
{ | |
// Move node's translation to (10, 0, 10) at 0 sec using bezier interpolation | |
{0, 10.0f, Interpolation.Bezier}, | |
// Move node's translation to (20, 0, -10) at 3 sec | |
{3, -10.0f, Interpolation.Bezier}, | |
// Move node's translation to (30, 0, 0) at 5 sec | |
{5, 0.0f, Interpolation.Linear}, | |
}); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("PropertyToDocument.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Get a child node object | |
Node cameraNode = scene.RootNode.CreateChildNode("camera", new Camera()); | |
// Set camera node translation | |
cameraNode.Transform.Translation = new Vector3(100, 20, 0); | |
cameraNode.GetEntity<Camera>().Target = scene.RootNode.CreateChildNode("target"); | |
MyDir = MyDir + "camera-test.3ds"; | |
scene.Save(MyDir, FileFormat.Discreet3DS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize a 3D scene | |
Scene scene = new Scene(); | |
// Set application/tool name | |
scene.RootNode.AssetInfo.ApplicationName = "Egypt"; | |
// Set application/tool vendor name | |
scene.RootNode.AssetInfo.ApplicationVendor = "Manualdesk"; | |
// We use ancient egyption measurement unit Pole | |
scene.RootNode.AssetInfo.UnitName = "pole"; | |
// One Pole equals to 60cm | |
scene.RootNode.AssetInfo.UnitScaleFactor = 0.6; | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("InformationToScene.fbx"); | |
// Save scene to 3D supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// initialize a scene | |
Scene scene = new Scene(); | |
// initialize PBR material object | |
PbrMaterial mat = new PbrMaterial(); | |
// an almost metal material | |
mat.MetallicFactor = 0.9; | |
// material surface is very rough | |
mat.RoughnessFactor = 0.9; | |
// create a box to which the material will be applied | |
var boxNode = scene.RootNode.CreateChildNode("box", new Box()); | |
boxNode.Material = mat; | |
// save 3d scene into STL format | |
scene.Save(MyDir + "PBR_Material_Box_Out.stl", FileFormat.STLASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Vector4[] controlPoints = DefineControlPoints(); | |
// Initialize mesh object | |
Mesh mesh = new Mesh(); | |
// Add control points to the mesh | |
mesh.ControlPoints.AddRange(controlPoints); | |
// Create polygons to mesh | |
// Front face (Z+) | |
mesh.CreatePolygon(new int[] { 0, 1, 2, 3 }); | |
// Right side (X+) | |
mesh.CreatePolygon(new int[] { 1, 5, 6, 2 }); | |
// Back face (Z-) | |
mesh.CreatePolygon(new int[] { 5, 4, 7, 6 }); | |
// Left side (X-) | |
mesh.CreatePolygon(new int[] { 4, 0, 3, 7 }); | |
// Bottom face (Y-) | |
mesh.CreatePolygon(new int[] { 0, 4, 5, 1 }); | |
// Top face (Y+) | |
mesh.CreatePolygon(new int[] { 3, 2, 6, 7 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Vector4[] controlPoints = DefineControlPoints(); | |
// Initialize mesh object | |
Mesh mesh = new Mesh(); | |
// Add control points to the mesh | |
mesh.ControlPoints.AddRange(controlPoints); | |
// Indices of the vertices per each polygon | |
int[] indices = new int[] | |
{ | |
0,1,2,3, // Front face (Z+) | |
1,5,6,2, // Right side (X+) | |
5,4,7,6, // Back face (Z-) | |
4,0,3,7, // Left side (X-) | |
0,4,5,1, // Bottom face (Y-) | |
3,2,6,7 // Top face (Y+) | |
}; | |
int vertexId = 0; | |
PolygonBuilder builder = new PolygonBuilder(mesh); | |
for (int face = 0; face < 6; face++) | |
{ | |
// Start defining a new polygon | |
builder.Begin(); | |
for (int v = 0; v < 4; v++) | |
// The indice of vertice per each polygon | |
builder.AddVertex(indices[vertexId++]); | |
// Finished one polygon | |
builder.End(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize control points | |
Vector4[] controlPoints = new Vector4[] | |
{ | |
new Vector4( -5.0, 0.0, 5.0, 1.0), | |
new Vector4( 5.0, 0.0, 5.0, 1.0), | |
new Vector4( 5.0, 10.0, 5.0, 1.0), | |
new Vector4( -5.0, 10.0, 5.0, 1.0), | |
new Vector4( -5.0, 0.0, -5.0, 1.0), | |
new Vector4( 5.0, 0.0, -5.0, 1.0), | |
new Vector4( 5.0, 10.0, -5.0, 1.0), | |
new Vector4( -5.0, 10.0, -5.0, 1.0) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
Scene scene = new Scene(); | |
Quaternion q1 = Quaternion.FromEulerAngle(Math.PI * 0.5, 0, 0); | |
Quaternion q2 = Quaternion.FromAngleAxis(-Math.PI * 0.5, Vector3.XAxis); | |
// Concatenate q1 and q2. q1 and q2 rotate alone x-axis with same angle but different direction, | |
// So the concatenated result will be identity quaternion. | |
Quaternion q3 = q1.Concat(q2); | |
// Create 3 cylinders to represent each quaternion | |
Node cylinder = scene.RootNode.CreateChildNode("cylinder-q1", new Cylinder(0.1, 1, 2)); | |
cylinder.Transform.Rotation = q1; | |
cylinder.Transform.Translation = new Vector3(-5, 2, 0); | |
cylinder = scene.RootNode.CreateChildNode("cylinder-q2", new Cylinder(0.1, 1, 2)); | |
cylinder.Transform.Rotation = q2; | |
cylinder.Transform.Translation = new Vector3(0, 2, 0); | |
cylinder = scene.RootNode.CreateChildNode("cylinder-q3", new Cylinder(0.1, 1, 2)); | |
cylinder.Transform.Rotation = q3; | |
cylinder.Transform.Translation = new Vector3(5, 2, 0); | |
MyDir = MyDir + "test_out.fbx"; | |
// Save to file | |
scene.Save(MyDir, FileFormat.FBX7400ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.Entity = mesh; | |
// Add Node to a scene | |
scene.RootNode.ChildNodes.Add(cubeNode); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("CubeScene.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize cube node object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Point node to the mesh | |
cubeNode.Entity = mesh; | |
// Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode); | |
// Initiallize PhongMaterial object | |
PhongMaterial mat = new PhongMaterial(); | |
// Initiallize Texture object | |
Texture diffuse = new Texture(); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Set local file path | |
diffuse.FileName = MyDir + "surface.dds"; | |
// Set Texture of the material | |
mat.SetTexture("DiffuseColor", diffuse); | |
// Embed raw content data to FBX (only for FBX and optional) | |
// Set file name | |
diffuse.FileName = "embedded-texture.png"; | |
// Set binary content | |
diffuse.Content = File.ReadAllBytes(MyDir + "aspose-logo.jpg"); | |
// Set color | |
mat.SpecularColor = new Vector3(Color.Red); | |
// Set brightness | |
mat.Shininess = 100; | |
// Set material property of the cube object | |
cubeNode.Material = mat; | |
MyDir = MyDir + RunExamples.GetOutputFilePath("MaterialToCube.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Get a child node object | |
Node top = scene.RootNode.CreateChildNode(); | |
// Each cube node has their own translation | |
Node cube1 = top.CreateChildNode("cube1"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Point node to the mesh | |
cube1.Entity = mesh; | |
// Set first cube translation | |
cube1.Transform.Translation = new Vector3(-10, 0, 0); | |
Node cube2 = top.CreateChildNode("cube2"); | |
// Point node to the mesh | |
cube2.Entity = mesh; | |
// Set second cube translation | |
cube2.Transform.Translation = new Vector3(10, 0, 0); | |
// The rotated top node will affect all child nodes | |
top.Transform.Rotation = Quaternion.FromEulerAngle(Math.PI, 4, 0); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("NodeHierarchy.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Raw normal data | |
Vector4[] normals = new Vector4[] | |
{ | |
new Vector4(-0.577350258,-0.577350258, 0.577350258, 1.0), | |
new Vector4( 0.577350258,-0.577350258, 0.577350258, 1.0), | |
new Vector4( 0.577350258, 0.577350258, 0.577350258, 1.0), | |
new Vector4(-0.577350258, 0.577350258, 0.577350258, 1.0), | |
new Vector4(-0.577350258,-0.577350258,-0.577350258, 1.0), | |
new Vector4( 0.577350258,-0.577350258,-0.577350258, 1.0), | |
new Vector4( 0.577350258, 0.577350258,-0.577350258, 1.0), | |
new Vector4(-0.577350258, 0.577350258,-0.577350258, 1.0) | |
}; | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
VertexElementNormal elementNormal = mesh.CreateElement(VertexElementType.Normal, MappingMode.ControlPoint, ReferenceMode.Direct) as VertexElementNormal; | |
// Copy the data to the vertex element | |
elementNormal.Data.AddRange(normals); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// UVs | |
Vector4[] uvs = new Vector4[] | |
{ | |
new Vector4( 0.0, 1.0,0.0, 1.0), | |
new Vector4( 1.0, 0.0,0.0, 1.0), | |
new Vector4( 0.0, 0.0,0.0, 1.0), | |
new Vector4( 1.0, 1.0,0.0, 1.0) | |
}; | |
// Indices of the uvs per each polygon | |
int[] uvsId = new int[] | |
{ | |
0,1,3,2,2,3,5,4,4,5,7,6,6,7,9,8,1,10,11,3,12,0,2,13 | |
}; | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Create UVset | |
VertexElementUV elementUV = mesh.CreateElementUV(TextureMapping.Diffuse, MappingMode.PolygonVertex, ReferenceMode.IndexToDirect); | |
// Copy the data to the UV vertex element | |
elementUV.Data.AddRange(uvs); | |
elementUV.Indices.AddRange(uvsId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.Entity = mesh; | |
// Euler angles | |
cubeNode.Transform.EulerAngles = new Vector3(0.3, 0.1, -0.5); | |
// Set translation | |
cubeNode.Transform.Translation = new Vector3(0, 0, 20); | |
// Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.Entity = mesh; | |
// Set rotation | |
cubeNode.Transform.Rotation = Quaternion.FromRotation(new Vector3(0, 1, 0), new Vector3(0.3, 0.5, 0.1)); | |
// Set translation | |
cubeNode.Transform.Translation = new Vector3(0, 0, 20); | |
// Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("cube"); | |
// Call Common class create mesh using polygon builder method to set mesh instance | |
Mesh mesh = Common.CreateMeshUsingPolygonBuilder(); | |
// Point node to the Mesh geometry | |
cubeNode.Entity = mesh; | |
// Set custom translation matrix | |
cubeNode.Transform.TransformMatrix = new Matrix4( | |
1, -0.3, 0, 0, | |
0.4, 1, 0.3, 0, | |
0, 0, 1, 0, | |
0, 20, 0, 1 | |
); | |
// Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize scene object | |
Scene scene = new Scene(); | |
scene.Open(MyDir + "document.fbx"); | |
scene.RootNode.Accept(delegate(Node node) | |
{ | |
Mesh mesh = node.GetEntity<Mesh>(); | |
if (mesh != null) | |
{ | |
// Triangulate the mesh | |
Mesh newMesh = PolygonModifier.Triangulate(mesh); | |
// Replace the old mesh | |
node.Entity = mesh; | |
} | |
return true; | |
}); | |
MyDir = MyDir + RunExamples.GetOutputFilePath("document.fbx"); | |
scene.Save(MyDir, FileFormat.FBX7400ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Instantiate the License class | |
Aspose.ThreeD.License license = new Aspose.ThreeD.License(); | |
// Pass only the name of the license file embedded in the assembly | |
license.SetLicense("Aspose._3D.lic"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Aspose.ThreeD.License license = new Aspose.ThreeD.License(); | |
license.SetLicense("Aspose._3D.lic"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Aspose.ThreeD.License license = new Aspose.ThreeD.License(); | |
FileStream myStream = new FileStream("Aspose._3D.lic", FileMode.Open); | |
license.SetLicense(myStream); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize a Metered license class object | |
Aspose.ThreeD.Metered metered = new Aspose.ThreeD.Metered(); | |
// Set public and private keys | |
metered.SetMeteredKey("your-public-key", "your-private-key"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize a Metered license class object | |
Aspose.ThreeD.Metered metered = new Aspose.ThreeD.Metered(); | |
// Det public and private keys | |
metered.SetMeteredKey("your-public-key", "your-private-key"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
CancellationTokenSource cts = new CancellationTokenSource(); | |
Scene scene = new Scene(); | |
cts.CancelAfter(1000); | |
try | |
{ | |
scene.Open(MyDir + "document.fbx" , cts.Token); | |
Console.WriteLine("Import is done within 1000ms"); | |
} | |
catch (ImportException e) | |
{ | |
if (e.InnerException is OperationCanceledException) | |
{ | |
Console.WriteLine("It takes too long time to import, import has been canceled."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + "document.fbx"; | |
// Create an object of the Scene class | |
Scene scene = new Scene(); | |
// Save 3D scene document | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Detect the format of a 3D file | |
FileFormat inputFormat = FileFormat.Detect(MyDir + "document.fbx"); | |
// Display the file format | |
Console.WriteLine("File Format: " + inputFormat.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
byte[] password = null; | |
List<Scene> scenes = FileFormat.PDF.ExtractScene(MyDir + "House_Design.pdf", password); | |
int i = 1; | |
// Iterate through the scenes and save in 3D files | |
foreach (Scene scene in scenes) | |
{ | |
string fileName = "3d-" + (i++) + ".fbx"; | |
scene.Save(fileName, FileFormat.FBX7400ASCII); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
byte[] password = null; | |
// Extract 3D contents | |
List<byte[]> contents = FileFormat.PDF.Extract(MyDir + "House_Design.pdf", password); | |
int i = 1; | |
// Iterate through the contents and in separate 3D files | |
foreach (byte[] content in contents) | |
{ | |
string fileName = "3d-" + (i++); | |
File.WriteAllBytes(fileName, content); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
Discreet3DSLoadOptions loadOpts = new Discreet3DSLoadOptions(); | |
// Sets wheather to use the transformation defined in the first frame of animation track. | |
loadOpts.ApplyAnimationTransform = true; | |
// Flip the coordinate system | |
loadOpts.FlipCoordinateSystem = true; | |
// Prefer to use gamma-corrected color if a 3ds file provides both original color and gamma-corrected color. | |
loadOpts.GammaCorrectedColor = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
loadOpts.LookupPaths = new List<string>(new string[] { MyDir }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize Scene class object | |
Scene scene = new Scene(); | |
// Set load options | |
GLTFLoadOptions loadOpt = new GLTFLoadOptions(); | |
// The default value is true, usually we don't need to change it. Aspose.3D will automatically flip the V/T texture coordinate during load and save. | |
loadOpt.FlipTexCoordV = true; | |
scene.Open( MyDir + "Duck.gltf", loadOpt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
ObjLoadOptions loadObjOpts = new ObjLoadOptions(); | |
// Import materials from external material library file | |
loadObjOpts.EnableMaterials = true; | |
// Flip the coordinate system. | |
loadObjOpts.FlipCoordinateSystem = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
loadObjOpts.LookupPaths = new List<string>(new string[] { MyDir}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// initialize Scene class object | |
Scene scene = new Scene(); | |
// initialize an object | |
PlyLoadOptions loadPLYOpts = new PlyLoadOptions(); | |
// Flip the coordinate system. | |
loadPLYOpts.FlipCoordinateSystem = true; | |
// load 3D Ply model | |
scene.Open(MyDir + "vase-v2.ply", loadPLYOpts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
STLLoadOptions loadSTLOpts = new STLLoadOptions(); | |
// Flip the coordinate system. | |
loadSTLOpts.FlipCoordinateSystem = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
loadSTLOpts.LookupPaths = new List<string>(new string[] { MyDir }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
U3DLoadOptions loadU3DOpts = new U3DLoadOptions(); | |
// Flip the coordinate system. | |
loadU3DOpts.FlipCoordinateSystem = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
loadU3DOpts.LookupPaths = new List<string>(new string[] { MyDir }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// initialize Scene class object | |
Scene scene = new Scene(); | |
// initialize an object | |
XLoadOptions loadXOpts = new XLoadOptions(FileContentType.ASCII); | |
// flip the coordinate system. | |
loadXOpts.FlipCoordinateSystem = true; | |
// load 3D X file | |
scene.Open(MyDir + "warrior.x", loadXOpts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// initialize a new 3D scene | |
var s = new Scene(); | |
var box = new Box(); | |
s.RootNode.CreateChildNode("box1", box).Material = new PhongMaterial() { DiffuseColor = new Vector3(1, 0, 1) }; | |
GLTFSaveOptions opt = new GLTFSaveOptions(FileFormat.GLTF2); | |
//Custom material converter to convert PhongMaterial to PbrMaterial | |
opt.MaterialConverter = delegate (Material material) | |
{ | |
PhongMaterial m = (PhongMaterial)material; | |
return new PbrMaterial() { Albedo = new Vector3(m.DiffuseColor.x, m.DiffuseColor.y, m.DiffuseColor.z) }; | |
}; | |
// save in GLTF 2.0 format | |
s.Save(MyDir + "Non_PBRtoPBRMaterial_Out.gltf", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Create a new scene | |
Scene scene = new Scene(); | |
// Use loading options and apply password | |
PdfLoadOptions opt = new PdfLoadOptions() { Password = Encoding.UTF8.GetBytes("password") }; | |
// Open scene | |
scene.Open(MyDir + "House_Design.pdf", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize a Scene class object | |
Scene scene = new Scene(); | |
// Load an existing 3D document | |
scene.Open(MyDir + "document.fbx"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Create a new scene | |
Scene scene = new Scene(); | |
// Create a cylinder child node | |
scene.RootNode.CreateChildNode("cylinder", new Cylinder()).Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.DarkCyan) }; | |
// Set rendering mode and lighting scheme | |
PdfSaveOptions opt = new PdfSaveOptions(); | |
opt.LightingScheme = PdfLightingScheme.CAD; | |
opt.RenderMode = PdfRenderMode.ShadedIllustration; | |
// Save in the PDF format | |
scene.Save(MyDir + "output_out.pdf", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load a 3D document into Aspose.3D | |
Scene scene = new Scene(MyDir + "document.fbx"); | |
scene.Save("UncompressedDocument.fbx", new FBXSaveOptions(FileFormat.FBX7500ASCII) { EnableCompression = false }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load a 3D document into Aspose.3D | |
Scene scene = new Scene(); | |
// Open an existing 3D scene | |
scene.Open(MyDir + "document.fbx"); | |
// Save Scene to a stream | |
MemoryStream dstStream = new MemoryStream(); | |
scene.Save(dstStream, FileFormat.FBX7500ASCII); | |
// Rewind the stream position back to zero so it is ready for next reader. | |
dstStream.Position = 0; | |
// Save Scene to a local path | |
scene.Save(MyDir + "output_out.fbx", FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
ColladaSaveOptions saveColladaopts = new ColladaSaveOptions(); | |
// Generates indented XML document | |
saveColladaopts.Indented = true; | |
// The style of node transformation | |
saveColladaopts.TransformStyle = ColladaTransformStyle.Matrix; | |
// Configure the lookup paths to allow importer to find external dependencies. | |
saveColladaopts.LookupPaths = new List<string>(new string[] { MyDir }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The code example uses the DummyFileSystem, so the material files are not created. | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize Scene object | |
Scene scene = new Scene(); | |
// Create a child node | |
scene.RootNode.CreateChildNode("sphere", new Sphere()).Material = new PhongMaterial(); | |
// Set saving options | |
ObjSaveOptions opt = new ObjSaveOptions(); | |
opt.FileSystem = new DummyFileSystem(); | |
// Save 3D scene | |
scene.Save(MyDir + "DiscardSavingMaterial_out.obj", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
Discreet3DSSaveOptions saveOpts = new Discreet3DSSaveOptions(); | |
// The start base for generating new name for duplicated names. | |
saveOpts.DuplicatedNameCounterBase = 2; | |
// The format of the duplicated counter. | |
saveOpts.DuplicatedNameCounterFormat = "NameFormat"; | |
// The separator between object's name and the duplicated counter. | |
saveOpts.DuplicatedNameSeparator = "Separator"; | |
// Allows to export cameras | |
saveOpts.ExportCamera = true; | |
// Allows to export light | |
saveOpts.ExportLight = true; | |
// Flip the coordinate system | |
saveOpts.FlipCoordinateSystem = true; | |
// Prefer to use gamma-corrected color if a 3ds file provides both original color and gamma-corrected color. | |
saveOpts.GammaCorrectedColor = true; | |
// Use high-precise color which each color channel will use 32bit float. | |
saveOpts.HighPreciseColor = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
saveOpts.LookupPaths = new List<string>(new string[] {MyDir}); | |
// Set the master scale | |
saveOpts.MasterScale = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize Scene object | |
Scene scene = new Scene(); | |
// Create a child node | |
scene.RootNode.CreateChildNode("sphere", new Sphere()); | |
// Initialize .DRC saving options. | |
DracoSaveOptions opts = new DracoSaveOptions(); | |
// Quantization bits for position | |
opts.PositionBits = 14; | |
// Quantization bits for texture coordinate | |
opts.TextureCoordinateBits = 8; | |
// Quantization bits for vertex color | |
opts.ColorBits = 10; | |
// Quantization bits for normal vectors | |
opts.NormalBits = 7; | |
// Set compression level | |
opts.CompressionLevel = DracoCompressionLevel.Optimal; | |
// Save Google Draco (.drc) file | |
scene.Save(MyDir + "DRCSaveOptions_out.drc", opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
FBXSaveOptions saveOpts = new FBXSaveOptions(FileFormat.FBX7500ASCII); | |
// Generates the legacy material properties. | |
saveOpts.ExportLegacyMaterialProperties = true; | |
// Fold repeated curve data using FBX's animation reference count | |
saveOpts.FoldRepeatedCurveData = true; | |
// Always generates material mapping information for geometries if the attached node contains materials. | |
saveOpts.GenerateVertexElementMaterial = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
saveOpts.LookupPaths = new List<string>(new string[] { MyDir }); | |
// Generates a video object for texture. | |
saveOpts.VideoForTexture = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize Scene object | |
Scene scene = new Scene(); | |
// Create a child node | |
scene.RootNode.CreateChildNode("sphere", new Sphere()); | |
// Set glTF saving options. The code example embeds all assets into the target file usually a glTF file comes with some dependencies, a bin file for model's vertex/indices, two .glsl files for vertex/fragment shaders | |
// Use opt.EmbedAssets to tells the Aspose.3D API to export scene and embed the dependencies inside the target file. | |
GLTFSaveOptions opt = new GLTFSaveOptions(FileContentType.ASCII); | |
opt.EmbedAssets = true; | |
// Use KHR_materials_common extension to define the material, thus no GLSL files are generated. | |
opt.UseCommonMaterials = true; | |
// Customize the name of the buffer file which defines model | |
opt.BufferFile = "mybuf.bin"; | |
// Save glTF file | |
scene.Save(MyDir + "glTFSaveOptions_out.gltf", opt); | |
// Save a binary glTF file using KHR_binary_glTF extension | |
scene.Save(MyDir + "glTFSaveOptions_out.glb", FileFormat.GLTF_Binary); | |
// Developers may use saving options to create a binary glTF file using KHR_binary_glTF extension | |
GLTFSaveOptions opts = new GLTFSaveOptions(FileContentType.Binary); | |
scene.Save(MyDir + "Test_out.glb", opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
ObjSaveOptions saveObjOpts = new ObjSaveOptions(); | |
// Import materials from external material library file | |
saveObjOpts.EnableMaterials = true; | |
// Flip the coordinate system. | |
saveObjOpts.FlipCoordinateSystem = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
saveObjOpts.LookupPaths = new List<string>(new string[] { MyDir }); | |
// Serialize W component in model's vertex position | |
saveObjOpts.SerializeW = true; | |
// Generate comments for each section | |
saveObjOpts.Verbose = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The code example uses the LocalFileSystem class to save dependencies to the local directory. | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize Scene object | |
Scene scene = new Scene(); | |
// Create a child node | |
scene.RootNode.CreateChildNode("sphere", new Sphere()).Material = new PhongMaterial(); | |
// Set saving options | |
ObjSaveOptions opt = new ObjSaveOptions(); | |
opt.FileSystem = new LocalFileSystem(MyDir); | |
// Save 3D scene | |
scene.Save(MyDir + "SavingDependenciesInLocalDirectory_out.obj", opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The code example uses the MemoryFileSystem to intercepts the dependencies writing. | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize Scene object | |
Scene scene = new Scene(); | |
// Create a child node | |
scene.RootNode.CreateChildNode("sphere", new Sphere()).Material = new PhongMaterial(); | |
// Set saving options | |
ObjSaveOptions opt = new ObjSaveOptions(); | |
MemoryFileSystem mfs = new MemoryFileSystem(); | |
opt.FileSystem = mfs; | |
// Save 3D scene | |
scene.Save(MyDir + "SavingDependenciesInMemoryFileSystem_out.obj", opt); | |
// Get the test.mtl file content | |
byte[] mtl = mfs.GetFileContent(MyDir + "test.mtl"); | |
File.WriteAllBytes( MyDir + "Material.mtl", mtl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
STLSaveOptions saveSTLOpts = new STLSaveOptions(); | |
// Flip the coordinate system. | |
saveSTLOpts.FlipCoordinateSystem = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
saveSTLOpts.LookupPaths = new List<string>(new string[] {MyDir }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Initialize an object | |
U3DSaveOptions saveU3DOptions = new U3DSaveOptions(); | |
// Export normal data. | |
saveU3DOptions.ExportNormals = true; | |
// Export the texture coordinates. | |
saveU3DOptions.ExportTextureCoordinates = true; | |
// Export the vertex diffuse color. | |
saveU3DOptions.ExportVertexDiffuse = true; | |
// Export vertex specular color | |
saveU3DOptions.ExportVertexSpecular = true; | |
// Flip the coordinate system. | |
saveU3DOptions.FlipCoordinateSystem = true; | |
// Configure the look up paths to allow importer to find external dependencies. | |
saveU3DOptions.LookupPaths = new List<string>(new string[] { MyDir }); | |
// Compress the mesh data | |
saveU3DOptions.MeshCompression = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load an existing 3D file | |
Scene scene = new Scene(MyDir + "document.fbx"); | |
// Triangulate a scene | |
PolygonModifier.Triangulate(scene); | |
// Save 3D scene | |
scene.Save(MyDir + "triangulated_out.fbx", FileFormat.FBX7400ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
Scene scene = new Scene(); | |
Camera camera = new Camera(); | |
camera.NearPlane = 0.1; | |
scene.RootNode.CreateChildNode("camera", camera); | |
Light light; | |
scene.RootNode.CreateChildNode("light", light = new Light() | |
{ | |
NearPlane = 0.1, | |
CastShadows = true, | |
Color = new Vector3(Color.White) | |
}).Transform.Translation = new Vector3(9.4785, 5, 3.18); | |
light.LookAt = Vector3.Origin; | |
light.Falloff = 90; | |
// Create a plane | |
Node plane = scene.RootNode.CreateChildNode("plane", new Plane(20, 20)); | |
plane.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.DarkOrange) }; | |
plane.Transform.Translation = new Vector3(0, 0, 0); | |
// Create a torus for casting shadows | |
Mesh m = (new Torus("", 1, 0.4, 20, 20, Math.PI * 2)).ToMesh(); | |
Node torus = scene.RootNode.CreateChildNode("torus", m); | |
torus.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.Cornsilk) }; | |
torus.Transform.Translation = new Vector3(2, 1, 1); | |
{ | |
// Create a blue box don't cast shadows | |
m = (new Box()).ToMesh(); | |
m.CastShadows = false; | |
Node box = scene.RootNode.CreateChildNode("box", m); | |
box.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.Blue) }; | |
box.Transform.Translation = new Vector3(2, 1, -1); | |
} | |
{ | |
// Create a red box that don't receive shadow but cast shadows | |
m = (new Box()).ToMesh(); | |
m.ReceiveShadows = false; | |
Node box = scene.RootNode.CreateChildNode("box", m); | |
box.Material = new PhongMaterial() { DiffuseColor = new Vector3(Color.Red) }; | |
box.Transform.Translation = new Vector3(-2, 1, 1); | |
} | |
camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10); | |
camera.LookAt = Vector3.Origin; | |
ImageRenderOptions opt = new ImageRenderOptions() { EnableShadows = true }; | |
scene.Render(camera, MyDir + "CastAndReceiveShadow_out.png", new Size(1024, 1024), ImageFormat.Png, opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load scene from file | |
Scene scene = new Scene(MyDir + "camera.3ds"); | |
// Create a camera at (10,10,10) and look at the origin point for rendering, | |
// It must be attached to the scene before render | |
Camera camera = new Camera(); | |
scene.RootNode.CreateChildNode("camera", camera); | |
camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10); | |
camera.LookAt = Vector3.Origin; | |
// Specify the image render option | |
ImageRenderOptions opt = new ImageRenderOptions(); | |
// Set the background color | |
opt.BackgroundColor = Color.AliceBlue; | |
// Tells renderer where the it can find textures | |
opt.AssetDirectories.Add(MyDir + "textures"); | |
// Turn on shadow | |
opt.EnableShadows = true; | |
// Render the scene in given camera's perspective into specified png file with size 1024x1024 | |
scene.Render(camera, MyDir + "Render3DModelImageFromCamera_out.png", new Size(1024, 1024), ImageFormat.Png, opt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(); | |
//load the scene | |
Scene scene = new Scene(dataDir + "VirtualCity.glb"); | |
//create a camera for capturing the cube map | |
Camera cam = new Camera(ProjectionType.Perspective) | |
{ | |
NearPlane = 0.1, | |
FarPlane = 200, | |
RotationMode = RotationMode.FixedDirection | |
}; | |
scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0); | |
//create two lights to illuminate the scene | |
scene.RootNode.CreateChildNode(new Light() { LightType = LightType.Point }).Transform.Translation = new Vector3(-10, 7, -10); | |
scene.RootNode.CreateChildNode(new Light() | |
{ | |
Color = new Vector3(Color.CadetBlue) | |
}).Transform.Translation = new Vector3(49, 0, 49); | |
//create a renderer | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
//Create a cube map render target with depth texture, depth is required when rendering a scene. | |
IRenderTexture rt = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 512, 512); | |
//create a 2D texture render target with no depth texture used for image processing | |
IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024, 1024); | |
//a viewport is required on the render target | |
rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); | |
renderer.Render(rt); | |
//execute the fisheye projection post-processing with the previous rendered cube map as input | |
//the fisheye can have field of view more than 180 degree, so a cube map with all direction is required. | |
PostProcessing fisheye = renderer.GetPostProcessing("fisheye"); | |
// we can change the fov to 360 instead of the default value 180. | |
fisheye.FindProperty("fov").Value = 360.0; | |
//Specify the cube map rendered from the scene as this post processing's input | |
fisheye.Input = rt.Targets[0]; | |
//Execute the post processing effect and save the result to render target final | |
renderer.Execute(fisheye, final); | |
//save the texture into disk | |
((ITexture2D)final.Targets[0]).Save(dataDir + "fisheye.png", ImageFormat.Png); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(); | |
//load the scene | |
Scene scene = new Scene(dataDir + "VirtualCity.glb"); | |
//create a camera for capturing the cube map | |
Camera cam = new Camera(ProjectionType.Perspective) | |
{ | |
NearPlane = 0.1, | |
FarPlane = 200, | |
RotationMode = RotationMode.FixedDirection | |
}; | |
scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0); | |
//create two lights to illuminate the scene | |
scene.RootNode.CreateChildNode(new Light() { LightType = LightType.Point }).Transform.Translation = new Vector3(-10, 7, -10); | |
scene.RootNode.CreateChildNode(new Light() | |
{ | |
Color = new Vector3(Color.CadetBlue) | |
}).Transform.Translation = new Vector3(49, 0, 49); | |
//create a renderer | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
//Create a cube map render target with depth texture, depth is required when rendering a scene. | |
IRenderTexture rt = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 512, 512); | |
//create a 2D texture render target with no depth texture used for image processing | |
IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024 * 3, 1024); | |
//a viewport is required on the render target | |
rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); | |
renderer.Render(rt); | |
//execute the equirectangular projection post-processing with the previous rendered cube map as input | |
PostProcessing equirectangular = renderer.GetPostProcessing("equirectangular"); | |
//Specify the cube map rendered from the scene as this post processing's input | |
equirectangular.Input = rt.Targets[0]; | |
//Execute the post processing effect and save the result to render target final | |
renderer.Execute(equirectangular, final); | |
//save the texture into disk | |
((ITexture2D)final.Targets[0]).Save(dataDir + "panaroma.png", ImageFormat.Png); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(); | |
//load the scene | |
Scene scene = new Scene(dataDir + "VirtualCity.glb"); | |
//create a camera for capturing the cube map | |
Camera cam = new Camera(ProjectionType.Perspective) | |
{ | |
NearPlane = 0.1, | |
FarPlane = 200, | |
RotationMode = RotationMode.FixedDirection | |
}; | |
scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0); | |
//create two lights to illuminate the scene | |
scene.RootNode.CreateChildNode(new Light() { LightType = LightType.Point }).Transform.Translation = new Vector3(-10, 7, -10); | |
scene.RootNode.CreateChildNode(new Light() | |
{ | |
Color = new Vector3(Color.CadetBlue) | |
}).Transform.Translation = new Vector3(49, 0, 49); | |
//create a renderer | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
//create a cube map render target with depth texture, depth is required when rendering a scene. | |
IRenderTexture rt = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 512, 512); | |
//a viewport is required on the render target | |
rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); | |
renderer.Render(rt); | |
//now lets get the cubemap texture | |
ITextureCubemap cubemap = rt.Targets[0] as ITextureCubemap; | |
//we can directly save each face to disk by specifing the file name | |
CubeFaceData<string> fileNames = new CubeFaceData<string>() | |
{ | |
Right = dataDir + "right.png", | |
Left = dataDir + "left.png", | |
Back = dataDir + "back.png", | |
Front = dataDir + "front.png", | |
Bottom = dataDir + "bottom.png", | |
Top = dataDir + "top.png" | |
}; | |
//and call Save method | |
cubemap.Save(fileNames, ImageFormat.Png); | |
//or we just need to use the render result in memory, we can save it to CubeFaceData<Bitmap> | |
//CubeFaceData<Bitmap> bitmaps = new CubeFaceData<Bitmap>(); | |
//cubemap.Save(bitmaps); | |
//bitmaps.Back.Save("back.bmp", ImageFormat.Bmp); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
public static void Run() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(); | |
//load the scene | |
Scene scene = new Scene(dataDir + "skybox.obj"); | |
//create a camera for capturing the cube map | |
Camera cam = new Camera(ProjectionType.Perspective); | |
cam.NearPlane = 0.1; | |
cam.FarPlane = 200; | |
scene.RootNode.CreateChildNode(cam).Transform.Translation = new Vector3(5, 6, 0); | |
cam.RotationMode = RotationMode.FixedDirection; | |
//create two lights to illuminate the scene | |
scene.RootNode.CreateChildNode(new Light() { LightType = LightType.Point }).Transform.Translation = new Vector3(-10, 7, -10); | |
scene.RootNode.CreateChildNode(new Light() | |
{ | |
LightType = LightType.Point, | |
ConstantAttenuation = 0.1, | |
Color = new Vector3(Color.CadetBlue) | |
}).Transform.Translation = new Vector3(49, 0, 49); | |
//create a render target | |
using (var renderer = Renderer.CreateRenderer()) | |
{ | |
//Create a cube map render target with depth texture, depth is required when rendering a scene. | |
IRenderTexture rt = renderer.RenderFactory.CreateCubeRenderTexture(new RenderParameters(false), 512, 512); | |
//create a 2D texture render target with no depth texture used for image processing | |
IRenderTexture final = renderer.RenderFactory.CreateRenderTexture(new RenderParameters(false, 32, 0, 0), 1024 * 3, 1024); | |
//a viewport is required on the render target | |
rt.CreateViewport(cam, RelativeRectangle.FromScale(0, 0, 1, 1)); | |
renderer.ShaderSet = CreateDepthShader(renderer); | |
renderer.Render(rt); | |
//execute the equirectangular projection post-processing with the previous rendered cube map as input | |
PostProcessing equirectangular = renderer.GetPostProcessing("equirectangular"); | |
equirectangular.Input = rt.Targets[0]; | |
renderer.Execute(equirectangular, final); | |
//save the texture into disk | |
((ITexture2D)final.Targets[0]).Save(dataDir + "RenderSceneWithPanoramaInDepth_Out.png", ImageFormat.Png); | |
} | |
} | |
private static ShaderSet CreateDepthShader(Renderer renderer) | |
{ | |
GLSLSource src = new GLSLSource(); | |
src.VertexShader = @"#version 330 core | |
layout (location = 0) in vec3 position; | |
uniform mat4 matWorldViewProj; | |
out float depth; | |
void main() | |
{ | |
gl_Position = matWorldViewProj * vec4(position, 1.0f); | |
float zfar = 200.0; | |
float znear = 0.5; | |
//visualize the depth by linearize it so we don't get a blank screen | |
depth = (2.0 * znear) / (zfar + znear - gl_Position.z /gl_Position.w * (zfar - znear)); | |
}"; | |
src.FragmentShader = @"#version 330 core | |
in float depth; | |
out vec4 color; | |
void main() | |
{ | |
color = vec4(depth, depth, depth, 1); | |
}"; | |
//we only need the position to render the depth map | |
VertexDeclaration fd = new VertexDeclaration(); | |
fd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position); | |
//compile shader from GLSL source code and specify the vertex input format | |
var shader = renderer.RenderFactory.CreateShaderProgram(src, fd); | |
//connect GLSL uniform to renderer's internal variable | |
shader.Variables = new ShaderVariable[] | |
{ | |
new ShaderVariable("matWorldViewProj", VariableSemantic.MatrixWorldViewProj) | |
}; | |
//create a shader set | |
ShaderSet ret = new ShaderSet(); | |
//we only use the fallback, and left other shaders unassigned, so all materials will be rendered by this shader | |
ret.Fallback = shader; | |
return ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load an existing 3D file | |
Scene scene = new Scene( MyDir + "document.fbx"); | |
// Triangulate a scene | |
PolygonModifier.BuildTangentBinormal(scene); | |
// Save 3D scene | |
scene.Save("BuildTangentAndBinormalData_out.fbx", FileFormat.FBX7400ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Get mesh of the Box | |
Mesh box = (new Box()).ToMesh(); | |
// Create a customized vertex layout | |
VertexDeclaration vd = new VertexDeclaration(); | |
VertexField position = vd.AddField(VertexFieldDataType.FVector4, VertexFieldSemantic.Position); | |
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Normal); | |
// Get a triangle mesh | |
TriMesh triMesh = TriMesh.FromMesh(box); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize object by Box class | |
IMeshConvertible convertible = new Box(); | |
// Convert a Box to Mesh | |
Mesh mesh = convertible.ToMesh(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize object by Cylinder class | |
IMeshConvertible convertible = new Cylinder(); | |
// Convert a Cylinder to Mesh | |
Mesh mesh = convertible.ToMesh(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize object by Plane class | |
IMeshConvertible convertible = new Plane(); | |
// Convert a Plane to Mesh | |
Mesh mesh = convertible.ToMesh(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
[StructLayout(LayoutKind.Sequential)] | |
struct MyVertex | |
{ | |
[Semantic(VertexFieldSemantic.Position)] | |
FVector3 position; | |
[Semantic(VertexFieldSemantic.Normal)] | |
FVector3 normal; | |
} | |
public static void Run() | |
{ | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("sphere"); | |
Mesh sphere = (new Sphere()).ToMesh(); | |
// Convert any mesh into typed TriMesh | |
var myMesh = TriMesh<MyVertex>.FromMesh(sphere); | |
// Get the vertex data in customized vertex structure. | |
MyVertex[] vertex = myMesh.VerticesToTypedArray(); | |
// Get the 32bit and 16bit indices | |
int[] indices32bit; | |
ushort[] indices16bit; | |
myMesh.IndicesToArray(out indices32bit); | |
myMesh.IndicesToArray(out indices16bit); | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
// Or we can write the vertex directly into stream like: | |
myMesh.WriteVerticesTo(ms); | |
// The indice data can be directly write to stream, we support 32-bit and 16-bit indice. | |
myMesh.Write16bIndicesTo(ms); | |
myMesh.Write32bIndicesTo(ms); | |
} | |
// Point node to the Mesh geometry | |
cubeNode.Entity = sphere; | |
// Add Node to a scene | |
scene.RootNode.ChildNodes.Add(cubeNode); | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("SphereToTriangleMeshCustomMemoryLayoutScene.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII); | |
Console.WriteLine("Indices = {0}, Actual vertices = {1}, vertices before merging = {2}", myMesh.IndicesCount, myMesh.VerticesCount, myMesh.UnmergedVerticesCount); | |
Console.WriteLine("Total bytes of vertices in memory {0}bytes", myMesh.VerticesSizeInBytes); | |
Console.WriteLine("\n Converted a Sphere mesh to triangle mesh with custom memory layout of the vertex successfully.\nFile saved at " + MyDir); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize object by Sphere class | |
IMeshConvertible convertible = new Sphere(); | |
// Convert a Sphere to Mesh | |
Mesh mesh = convertible.ToMesh(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Initialize object by Torus class | |
IMeshConvertible convertible = new Torus(); | |
// Convert a Torus to Mesh | |
Mesh mesh = convertible.ToMesh(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Create a sphere | |
var sphere = new Sphere(); | |
// Encode the sphere to Google Draco raw data using optimal compression level. | |
var b = FileFormat.Draco.Encode(sphere.ToMesh(), | |
new DracoSaveOptions() { CompressionLevel = DracoCompressionLevel.Optimal }); | |
// Save the raw bytes to file | |
File.WriteAllBytes(MyDir + "SphereMeshtoDRC_Out.drc", b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
// Load a 3ds file, 3ds file doesn't have normal data, but it has smoothing group | |
Scene s = new Scene(MyDir + "camera.3ds"); | |
// Visit all nodes and create normal data for all meshes | |
s.RootNode.Accept(delegate(Node n) | |
{ | |
Mesh mesh = n.GetEntity<Mesh>(); | |
if (mesh != null) | |
{ | |
VertexElementNormal normals = PolygonModifier.GenerateNormal(mesh); | |
mesh.VertexElements.Add(normals); | |
} | |
return true; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir(); | |
MyDir = MyDir + "test.fbx"; | |
// Load a 3D file | |
Scene scene = new Scene(MyDir); | |
// Split all meshes | |
PolygonModifier.SplitMesh(scene, SplitMeshPolicy.CloneData); | |
// Save file | |
MyDir = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("test-splitted.fbx"); | |
scene.Save(MyDir, FileFormat.FBX7500ASCII); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
// Create a mesh of box(A box is composed by 6 planes) | |
Mesh box = (new Box()).ToMesh(); | |
// Create a material element on this mesh | |
VertexElementMaterial mat = (VertexElementMaterial)box.CreateElement(VertexElementType.Material, MappingMode.Polygon, ReferenceMode.Index); | |
// And specify different material index for each plane | |
mat.Indices.AddRange(new int[] { 0, 1, 2, 3, 4, 5 }); | |
// Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh. | |
// We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information. | |
Mesh[] planes = PolygonModifier.SplitMesh(box, SplitMeshPolicy.CloneData); | |
mat.Indices.Clear(); | |
mat.Indices.AddRange(new int[] { 0, 0, 0, 1, 1, 1 }); | |
// Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes. | |
// We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information. | |
planes = PolygonModifier.SplitMesh(box, SplitMeshPolicy.CompactData); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize a Scene object | |
Dim scene As New Scene() | |
' Create a Box model | |
scene.RootNode.CreateChildNode("box", New Box()) | |
' Create a Cylinder model | |
scene.RootNode.CreateChildNode("cylinder", New Cylinder()) | |
' Save drawing in the FBX format | |
MyDir = MyDir & RunExamples.GetOutputFilePath("test.fbx") | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize scene object | |
Dim scene As New Scene() | |
scene.Open(MyDir & Convert.ToString("camera.3ds"), FileFormat.Discreet3DS) | |
MyDir = MyDir & Convert.ToString("FlipCoordinateSystem.obj") | |
scene.Save(MyDir, FileFormat.WavefrontOBJ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Shared Sub Run() | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' load a 3D file | |
Dim scene As New Scene(MyDir + "test.fbx") | |
' visit each descent nodes | |
scene.RootNode.Accept(AddressOf VisitMeshNodes) | |
End Sub | |
Private Shared Function VisitMeshNodes(node As Node) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' open file for writing in binary mode | |
Using writer = New BinaryWriter(New FileStream(MyDir + "Save3DMeshesInCustomBinaryFormat_out", FileMode.Create, FileAccess.Write)) | |
For Each entity As Entity In node.Entities | |
' only convert meshes, lights/camera and other stuff will be ignored | |
If Not (TypeOf entity Is IMeshConvertible) Then | |
Continue For | |
End If | |
Dim m As Mesh = DirectCast(entity, IMeshConvertible).ToMesh() | |
Dim controlPoints = m.ControlPoints | |
' triangulate the mesh, so triFaces will only store triangle indices | |
Dim triFaces As Integer()() = PolygonModifier.Triangulate(controlPoints, m.Polygons) | |
' gets the global transform matrix | |
Dim transform As Matrix4 = node.GlobalTransform.TransformMatrix | |
' write number of control points and triangle indices | |
writer.Write(controlPoints.Count) | |
writer.Write(triFaces.Length) | |
' write control points | |
For i As Integer = 0 To controlPoints.Count - 1 | |
' calculate the control points in world space and save them to file | |
Dim cp = transform * controlPoints(i) | |
writer.Write(CSng(cp.x)) | |
writer.Write(CSng(cp.y)) | |
writer.Write(CSng(cp.z)) | |
Next | |
' write triangle indices | |
For i As Integer = 0 To triFaces.Length - 1 | |
writer.Write(triFaces(i)(0)) | |
writer.Write(triFaces(i)(1)) | |
writer.Write(triFaces(i)(2)) | |
Next | |
Next | |
Return True | |
End Using | |
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load an existing 3D scene | |
Dim scene As New Scene(MyDir & Convert.ToString("scene.obj")) | |
' Create an instance of the camera | |
Dim camera As New Camera() | |
scene.RootNode.CreateChildNode("camera", camera).Transform.Translation = New Vector3(2, 44, 66) | |
' Set the target | |
camera.LookAt = New Vector3(50, 12, 0) | |
' Create a light | |
scene.RootNode.CreateChildNode("light", New Light() With { | |
.Color = New Vector3(Color.White), | |
.LightType = LightType.Point _ | |
}).Transform.Translation = New Vector3(26, 57, 43) | |
' The CreateRenderer will create a hardware OpenGL-backend renderer, more renderer will be added in the future | |
' And some internal initializations will be done. | |
' When the renderer left using the scope, the unmanaged hardware resources will also be disposed | |
Using renderer__1 = Renderer.CreateRenderer() | |
renderer__1.EnableShadows = False | |
' Create a new render target that renders the scene to texture(s) | |
' Use default render parameters | |
' And one output targets | |
' Size is 1024 x 1024 | |
' This render target can have multiple render output textures, but here we only need one output. | |
' The other textures and depth textures are mainly used by deferred shading in the future. | |
' But you can also access the depth texture through IRenderTexture.DepthTeture | |
Using rt As IRenderTexture = renderer__1.RenderFactory.CreateRenderTexture(New RenderParameters(), 1, 1024, 1024) | |
' This render target has one viewport to render, the viewport occupies the 100% width and 100% height | |
Dim vp As Viewport = rt.CreateViewport(camera, New RelativeRectangle() With { | |
.ScaleWidth = 1, _ | |
.ScaleHeight = 1 _ | |
}) | |
' Render the target and save the target texture to external file | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("Original_viewport_out.png"), ImageFormat.Png) | |
' Create a post-processing effect | |
Dim pixelation As PostProcessing = renderer__1.GetPostProcessing("pixelation") | |
renderer__1.PostProcessings.Add(pixelation) | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("VisualEffect_pixelation_out.png"), ImageFormat.Png) | |
' Clear previous post-processing effects and try another one | |
Dim grayscale As PostProcessing = renderer__1.GetPostProcessing("grayscale") | |
renderer__1.PostProcessings.Clear() | |
renderer__1.PostProcessings.Add(grayscale) | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("VisualEffect_grayscale_out.png"), ImageFormat.Png) | |
' We can also combine post-processing effects | |
renderer__1.PostProcessings.Clear() | |
renderer__1.PostProcessings.Add(grayscale) | |
renderer__1.PostProcessings.Add(pixelation) | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("VisualEffect_grayscale+pixelation_out.png"), ImageFormat.Png) | |
' Clear previous post-processing effects and try another one | |
Dim edgedetection As PostProcessing = renderer__1.GetPostProcessing("edge-detection") | |
renderer__1.PostProcessings.Clear() | |
renderer__1.PostProcessings.Add(edgedetection) | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("VisualEffect_edgedetection_out.png"), ImageFormat.Png) | |
' Clear previous post-processing effects and try another one | |
Dim blur As PostProcessing = renderer__1.GetPostProcessing("blur") | |
renderer__1.PostProcessings.Clear() | |
renderer__1.PostProcessings.Add(blur) | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("VisualEffect_blur_out.png"), ImageFormat.Png) | |
End Using | |
End Using |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load an existing 3D scene | |
Dim scene As New Scene(MyDir & Convert.ToString("scene.obj")) | |
' Create an instance of the camera | |
Dim camera As New Camera() | |
scene.RootNode.CreateChildNode("camera", camera).Transform.Translation = New Vector3(2, 44, 66) | |
' Set the target | |
camera.LookAt = New Vector3(50, 12, 0) | |
' Create a light | |
scene.RootNode.CreateChildNode("light", New Light() With { | |
.Color = New Vector3(Color.White), | |
.LightType = LightType.Point _ | |
}).Transform.Translation = New Vector3(26, 57, 43) | |
' The CreateRenderer will create a hardware OpenGL-backend renderer | |
' And some internal initializations will be done. | |
' When the renderer left using the scope, the unmanaged hardware resources will also be disposed | |
Using renderer__1 = Renderer.CreateRenderer() | |
renderer__1.EnableShadows = False | |
' Create a new render target that renders the scene to texture(s) | |
' Use default render parameters | |
' And one output targets | |
' Size is 1024 x 1024 | |
' This render target can have multiple render output textures, but here we only need one output. | |
' The other textures and depth textures are mainly used by deferred shading in the future. | |
' But you can also access the depth texture through IRenderTexture.DepthTeture | |
' Use CreateRenderWindow method to render in window, like: | |
' Window = renderer.RenderFactory.CreateRenderWindow(new RenderParameters(), Handle); | |
Using rt As IRenderTexture = renderer__1.RenderFactory.CreateRenderTexture(New RenderParameters(), 1, 1024, 1024) | |
' This render target has one viewport to render, the viewport occupies the 100% width and 100% height | |
Dim vp As Viewport = rt.CreateViewport(camera, New RelativeRectangle() With { | |
.ScaleWidth = 1, | |
.ScaleHeight = 1 | |
}) | |
' Render the target and save the target texture to external file | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("file-1viewports_out.png"), ImageFormat.Png) | |
' Now let' S change the previous viewport only uses the half left side(50% width and 100% height) | |
vp.Area = New RelativeRectangle() With { | |
.ScaleWidth = 0.5F, | |
.ScaleHeight = 1 | |
} | |
' And create a new viewport that occupies the 50% width and 100% height and starts from 50% | |
' Both of them are using the same camera, so the rendered content should be the same | |
rt.CreateViewport(camera, New RelativeRectangle() With { | |
.ScaleX = 0.5F, | |
.ScaleWidth = 0.5F, | |
.ScaleHeight = 1 | |
}) | |
' But this time let' S increase the field of view of the camera to 90 degree so it can see more part of the scene | |
camera.FieldOfView = 90 | |
renderer__1.Render(rt) | |
rt.Targets(0).Save(MyDir & Convert.ToString("file-2viewports_out.png"), ImageFormat.Png) | |
End Using | |
End Using |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Each cube node has their own translation | |
Dim cube1 As Node = scene.RootNode.CreateChildNode("cube1", mesh) | |
' Find translation property on node' S transform object | |
Dim translation As [Property] = cube1.Transform.FindProperty("Translation") | |
' Create a curve mapping based on translation property | |
Dim mapping As New CurveMapping(scene, translation) | |
' Create curve on channel X and Z | |
Dim curveX As Curve = mapping.CreateCurve("X") | |
Dim curveZ As Curve = mapping.CreateCurve("Z") | |
' Move node' S translation to (10, 0, 10) at 0 sec using bezier interpolation | |
curveX.CreateKeyFrame(0, 10.0F, Interpolation.Bezier) | |
curveZ.CreateKeyFrame(0, 10.0F, Interpolation.Bezier) | |
' Move node' S translation to (20, 0, -10) at 3 sec | |
curveX.CreateKeyFrame(3, 20.0F, Interpolation.Bezier) | |
curveZ.CreateKeyFrame(3, -10.0F, Interpolation.Bezier) | |
' Move node' S translation to (30, 0, 0) at 5 sec | |
curveX.CreateKeyFrame(5, 30.0F, Interpolation.Linear) | |
curveZ.CreateKeyFrame(5, 0.0F, Interpolation.Bezier) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("PropertyToDocument.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Get a child node object | |
Dim cameraNode As Node = scene.RootNode.CreateChildNode("camera", New Camera()) | |
' Set camera node translation | |
cameraNode.Transform.Translation = New Vector3(100, 20, 0) | |
cameraNode.GetEntity(Of Camera)().Target = scene.RootNode.CreateChildNode("target") | |
MyDir = MyDir & Convert.ToString("camera-test.3ds") | |
scene.Save(MyDir, FileFormat.Discreet3DS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize a 3D scene | |
Dim scene As New Scene() | |
' Set application/tool name | |
scene.AssetInfo.ApplicationName = "Egypt" | |
' Set application/tool vendor name | |
scene.AssetInfo.ApplicationVendor = "Manualdesk" | |
' We use ancient egyption measurement unit Pole | |
scene.AssetInfo.UnitName = "pole" | |
' One Pole equals to 60cm | |
scene.AssetInfo.UnitScaleFactor = 0.6 | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("InformationToScene.fbx") | |
' Save scene to 3D supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Dim controlPoints As Vector4() = DefineControlPoints() | |
' Initialize mesh object | |
Dim mesh As New Mesh() | |
' Add control points to the mesh | |
mesh.ControlPoints.AddRange(controlPoints) | |
' Create polygons to mesh | |
' Front face (Z+) | |
mesh.CreatePolygon(New Integer() {0, 1, 2, 3}) | |
' Right side (X+) | |
mesh.CreatePolygon(New Integer() {1, 5, 6, 2}) | |
' Back face (Z-) | |
mesh.CreatePolygon(New Integer() {5, 4, 7, 6}) | |
' left side (X-) | |
mesh.CreatePolygon(New Integer() {4, 0, 3, 7}) | |
' Bottom face (Y-) | |
mesh.CreatePolygon(New Integer() {0, 4, 5, 1}) | |
' Top face (Y+) | |
mesh.CreatePolygon(New Integer() {3, 2, 6, 7}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Dim controlPoints As Vector4() = DefineControlPoints() | |
' Initialize mesh object | |
Dim mesh As New Mesh() | |
' Add control points to the mesh | |
mesh.ControlPoints.AddRange(controlPoints) | |
' Indices of the vertices per each polygon | |
' 0, 1, 2, 3 -> front face (Z+) | |
' 1, 5, 6, 2 -> right side (X+) | |
' 5, 4, 7, 6 -> back face (Z-) | |
' 4, 0, 3, 7 -> left side (X-) | |
' 0, 4, 5, 1 -> bottom face (Y-) | |
' 3, 2, 6, 7 -> top face (Y+) | |
Dim indices = New Integer() {0, 1, 2, 3, 1, 5, 6, 2, 5, 4, 7, 6, 4, 0, 3, 7, 0, 4, 5, 1, 3, 2, 6, 7} | |
Dim vertexId As Integer = 0 | |
Dim builder As New PolygonBuilder(mesh) | |
For face As Integer = 0 To 5 | |
' Start defining a new polygon | |
builder.Begin() | |
For v As Integer = 0 To 3 | |
' The indice of vertice per each polygon | |
builder.AddVertex(indices(vertexId)) | |
vertexId = vertexId + 1 | |
Next | |
' Finished one polygon | |
builder.End() | |
Next | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize control points | |
Dim controlPoints As Vector4() = New Vector4() { | |
New Vector4(-5.0, 0.0, 5.0, 1.0), | |
New Vector4(5.0, 0.0, 5.0, 1.0), | |
New Vector4(5.0, 10.0, 5.0, 1.0), | |
New Vector4(-5.0, 10.0, 5.0, 1.0), | |
New Vector4(-5.0, 0.0, -5.0, 1.0), | |
New Vector4(5.0, 0.0, -5.0, 1.0), | |
New Vector4(5.0, 10.0, -5.0, 1.0), | |
New Vector4(-5.0, 10.0, -5.0, 1.0)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
Dim scene As New Scene() | |
Dim q1 As Quaternion = Quaternion.FromEulerAngle(Math.PI * 0.5, 0, 0) | |
Dim q2 As Quaternion = Quaternion.FromAngleAxis(-Math.PI * 0.5, Vector3.XAxis) | |
' Concatenate q1 and q2. q1 and q2 rotate alone x-axis with same angle but different direction, | |
' So the concatenated result will be identity quaternion. | |
Dim q3 As Quaternion = q1.Concat(q2) | |
' Create 3 cylinders to represent each quaternion | |
Dim cylinder As Node = scene.RootNode.CreateChildNode("cylinder-q1", New Cylinder(0.1, 1, 2)) | |
cylinder.Transform.Rotation = q1 | |
cylinder.Transform.Translation = New Vector3(-5, 2, 0) | |
cylinder = scene.RootNode.CreateChildNode("cylinder-q2", New Cylinder(0.1, 1, 2)) | |
cylinder.Transform.Rotation = q2 | |
cylinder.Transform.Translation = New Vector3(0, 2, 0) | |
cylinder = scene.RootNode.CreateChildNode("cylinder-q3", New Cylinder(0.1, 1, 2)) | |
cylinder.Transform.Rotation = q3 | |
cylinder.Transform.Translation = New Vector3(5, 2, 0) | |
MyDir = MyDir & Convert.ToString("test_out.fbx") | |
' Save to file | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Initialize Node class object | |
Dim cubeNode As New Node("cube") | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Point node to the Mesh geometry | |
cubeNode.Entity = mesh | |
' Add Node to a scene | |
scene.RootNode.ChildNodes.Add(cubeNode) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("CubeScene.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Initialize cube node object | |
Dim cubeNode As New Node("cube") | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Point node to the mesh | |
cubeNode.Entity = mesh | |
' Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode) | |
' Initiallize PhongMaterial object | |
Dim mat As New PhongMaterial() | |
' Initiallize Texture object | |
Dim diffuse As New Texture() | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Set local file path | |
diffuse.FileName = MyDir & Convert.ToString("surface.dds") | |
' Set Texture of the material | |
mat.SetTexture("DiffuseColor", diffuse) | |
' Embed raw content data to FBX (only for FBX And optional) | |
' Set file name | |
diffuse.FileName = "embedded-texture.png" | |
' Set binary content | |
diffuse.Content = File.ReadAllBytes(MyDir & "aspose-logo.jpg") | |
' Set color | |
mat.SpecularColor = New Vector3(Color.Red) | |
' Set brightness | |
mat.Shininess = 100 | |
' Set material property of the cube object | |
cubeNode.Material = mat | |
MyDir = MyDir & RunExamples.GetOutputFilePath("MaterialToCube.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Get a child node object | |
Dim top As Node = scene.RootNode.CreateChildNode() | |
' Each cube node has their own translation | |
Dim cube1 As Node = top.CreateChildNode("cube1") | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Point node to the mesh | |
cube1.Entity = mesh | |
' Set first cube translation | |
cube1.Transform.Translation = New Vector3(-10, 0, 0) | |
Dim cube2 As Node = top.CreateChildNode("cube2") | |
' Point node to the mesh | |
cube2.Entity = mesh | |
' Set second cube translation | |
cube2.Transform.Translation = New Vector3(10, 0, 0) | |
' The rotated top node will affect all child nodes | |
top.Transform.Rotation = Quaternion.FromEulerAngle(Math.PI, 4, 0) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("NodeHierarchy.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Raw normal data | |
Dim normals As Vector4() = New Vector4() { | |
New Vector4(-0.577350258, -0.577350258, 0.577350258, 1.0), | |
New Vector4(0.577350258, -0.577350258, 0.577350258, 1.0), | |
New Vector4(0.577350258, 0.577350258, 0.577350258, 1.0), | |
New Vector4(-0.577350258, 0.577350258, 0.577350258, 1.0), | |
New Vector4(-0.577350258, -0.577350258, -0.577350258, 1.0), | |
New Vector4(0.577350258, -0.577350258, -0.577350258, 1.0), | |
New Vector4(0.577350258, 0.577350258, -0.577350258, 1.0), | |
New Vector4(-0.577350258, 0.577350258, -0.577350258, 1.0)} | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
Dim elementNormal As VertexElementNormal = TryCast(mesh.CreateElement(VertexElementType.Normal, MappingMode.ControlPoint, ReferenceMode.Direct), VertexElementNormal) | |
' Copy the data to the vertex element | |
elementNormal.Data.AddRange(normals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' UVs | |
Dim uvs As Vector4() = New Vector4() { | |
New Vector4(0.0, 1.0, 0.0, 1.0), | |
New Vector4(1.0, 0.0, 0.0, 1.0), | |
New Vector4(0.0, 0.0, 0.0, 1.0), | |
New Vector4(1.0, 1.0, 0.0, 1.0) | |
} | |
' Indices of the uvs per each polygon | |
Dim uvsId As Integer() = New Integer() { | |
0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 9, 8, 1, 10, 11, 3, 12, 0, 2, 13 | |
} | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Create UVset | |
Dim elementUV As VertexElementUV = mesh.CreateElementUV(TextureMapping.Diffuse, MappingMode.PolygonVertex, ReferenceMode.IndexToDirect) | |
' Copy the data to the UV vertex element | |
' ElementUV.Data.AddRange(uvs) | |
elementUV.Indices.AddRange(uvsId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Initialize Node class object | |
Dim cubeNode As New Node("cube") | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Point node to the Mesh geometry | |
cubeNode.Entity = mesh | |
' Set euler angles | |
cubeNode.Transform.EulerAngles = New Vector3(0.3, 0.1, -0.5) | |
' Set translation | |
cubeNode.Transform.Translation = New Vector3(0, 0, 20) | |
' Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("TransformationToNode.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Initialize Node class object | |
Dim cubeNode As New Node("cube") | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Point node to the Mesh geometry | |
cubeNode.Entity = mesh | |
' Set rotation | |
cubeNode.Transform.Rotation = Quaternion.FromRotation(New Vector3(0, 1, 0), New Vector3(0.3, 0.5, 0.1)) | |
' Set translation | |
cubeNode.Transform.Translation = New Vector3(0, 0, 20) | |
' Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("TransformationToNode.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Initialize Node class object | |
Dim cubeNode As New Node("cube") | |
' Call Common class create mesh using polygon builder method to set mesh instance | |
Dim mesh As Mesh = Common.CreateMeshUsingPolygonBuilder() | |
' Point node to the Mesh geometry | |
cubeNode.Entity = mesh | |
' Set custom translation matrix | |
cubeNode.Transform.TransformMatrix = New Matrix4(1, -0.3, 0, 0, 0.4, 1, | |
0.3, 0, 0, 0, 1, 0, | |
0, 20, 0, 1) | |
' Add cube to the scene | |
scene.RootNode.ChildNodes.Add(cubeNode) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & RunExamples.GetOutputFilePath("TransformationToNode.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Dim mesh As Mesh = node.GetEntity(Of Mesh)() | |
If mesh IsNot Nothing Then | |
' Triangulate the mesh | |
Dim newMesh As Mesh = PolygonModifier.Triangulate(mesh) | |
' Replace the old mesh | |
node.Entity = mesh | |
End If |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize scene object | |
Dim scene As New Scene() | |
scene.Open(MyDir & Convert.ToString("document.fbx")) | |
scene.RootNode.Accept(AddressOf HandleMesh) | |
MyDir = MyDir & RunExamples.GetOutputFilePath("document.fbx") | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Instantiate the License class | |
Dim license As New Aspose.ThreeD.License() | |
' Pass only the name of the license file embedded in the assembly | |
license.SetLicense("Aspose.3D.lic") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Dim license As New Aspose.ThreeD.License() | |
license.SetLicense("Aspose.3D.lic") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Dim license As New Aspose.ThreeD.License() | |
Dim myStream As New FileStream("Aspose.3D.lic", FileMode.Open) | |
license.SetLicense(myStream) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize a Metered license class object | |
Dim metered As New Aspose.ThreeD.Metered() | |
' Set public and private keys | |
metered.SetMeteredKey("your-public-key", "your-private-key") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize a Metered license class object | |
Dim metered As New Aspose.ThreeD.Metered() | |
' Det public and private keys | |
metered.SetMeteredKey("your-public-key", "your-private-key") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & Convert.ToString("document.fbx") | |
' Create an object of the Scene class | |
Dim scene As New Scene() | |
' Save 3D scene document | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Detect the format of a 3D file | |
Dim inputFormat As FileFormat = FileFormat.Detect(MyDir & Convert.ToString("document.fbx")) | |
' Display the file format | |
Console.WriteLine("File Format: " + inputFormat.ToString()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
Dim password As Byte() = Nothing | |
Dim scenes As List(Of Scene) = FileFormat.PDF.ExtractScene(MyDir & Convert.ToString("House_Design.pdf"), password) | |
Dim i As Integer = 1 | |
' Iterate through the scenes and save in 3D files | |
For Each scene As Scene In scenes | |
Dim fileName As String = "3d-" + (System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)) + ".fbx" | |
scene.Save(fileName, FileFormat.FBX7400ASCII) | |
Next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
Dim password As Byte() = Nothing | |
' Extract 3D contents | |
Dim contents As List(Of Byte()) = FileFormat.PDF.Extract(MyDir & Convert.ToString("House_Design.pdf"), password) | |
Dim i As Integer = 1 | |
' Iterate through the contents and in separate 3D files | |
For Each content As Byte() In contents | |
Dim fileName As String = "3d-" + (System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)) | |
File.WriteAllBytes(fileName, content) | |
Next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
Dim loadOpts As New Discreet3DSLoadOptions() | |
' Sets wheather to use the transformation defined in the first frame of animation track. | |
loadOpts.ApplyAnimationTransform = True | |
' Flip the coordinate system | |
loadOpts.FlipCoordinateSystem = True | |
' Prefer to use gamma-corrected color if a 3ds file provides both original color and gamma-corrected color. | |
loadOpts.GammaCorrectedColor = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
loadOpts.LookupPaths = New List(Of String)(New String() {MyDir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize Scene class object | |
Dim scene As New Scene() | |
' Set load options | |
Dim loadOpt As New GLTFLoadOptions() | |
' The default value is true, usually we don' T need to change it. Aspose.3D will automatically flip the V/T texture coordinate during load and save. | |
loadOpt.FlipTexCoordV = True | |
scene.Open(MyDir & Convert.ToString("Duck.gltf"), loadOpt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim loadObjOpts As New ObjLoadOptions() | |
' Import materials from external material library file | |
loadObjOpts.EnableMaterials = True | |
' Flip the coordinate system. | |
loadObjOpts.FlipCoordinateSystem = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
loadObjOpts.LookupPaths = New List(Of String)(New String() {MyDir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' the path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' initialize Scene class object | |
Dim scene As New Scene() | |
' initialize an object | |
Dim loadPLYOpts As New PlyLoadOptions() | |
' Flip the coordinate system. | |
loadPLYOpts.FlipCoordinateSystem = True | |
' load 3D Ply model | |
scene.Open(MyDir & Convert.ToString("vase-v2.ply"), loadPLYOpts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim loadSTLOpts As New STLLoadOptions() | |
' Flip the coordinate system. | |
loadSTLOpts.FlipCoordinateSystem = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
loadSTLOpts.LookupPaths = New List(Of String)(New String() {MyDir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim loadU3DOpts As New U3DLoadOptions() | |
' Flip the coordinate system. | |
loadU3DOpts.FlipCoordinateSystem = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
loadU3DOpts.LookupPaths = New List(Of String)(New String() {MyDir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Create a new scene | |
Dim scene As New Scene() | |
' Use loading options and apply password | |
Dim opt As New PdfLoadOptions() With { | |
.Password = Encoding.UTF8.GetBytes("password") _ | |
} | |
' Open scene | |
scene.Open(MyDir & Convert.ToString("House_Design.pdf"), opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize a Scene class object | |
Dim scene As New Scene() | |
' load an existing 3D document | |
scene.Open(MyDir & Convert.ToString("document.fbx")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Create a new scene | |
Dim scene As New Scene() | |
' Create a cylinder child node | |
scene.RootNode.CreateChildNode("cylinder", New Cylinder()).Material = New PhongMaterial() With { | |
.DiffuseColor = New Vector3(Color.DarkCyan) _ | |
} | |
' Set rendering mode and lighting scheme | |
Dim opt As New PdfSaveOptions() | |
opt.LightingScheme = PdfLightingScheme.CAD | |
opt.RenderMode = PdfRenderMode.ShadedIllustration | |
' Save in the PDF format | |
scene.Save(MyDir & Convert.ToString("output_out.pdf"), opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load a 3D document into Aspose.3D | |
Dim scene As New Scene() | |
' Open an existing 3D scene | |
scene.Open(MyDir & Convert.ToString("document.fbx")) | |
' Save 3D Scene to a stream | |
Dim dstStream As New MemoryStream() | |
scene.Save(dstStream, FileFormat.FBX7500ASCII) | |
' Rewind the stream position back to zero so it is ready for next reader. | |
dstStream.Position = 0 | |
' Save 3D Scene to a local path | |
scene.Save(MyDir + "output.fbx", FileFormat.FBX7500ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
Dim saveColladaopts As New ColladaSaveOptions() | |
' Generates indented XML document | |
saveColladaopts.Indented = True | |
' The style of node transformation | |
saveColladaopts.TransformStyle = ColladaTransformStyle.Matrix | |
' Configure the lookup paths to allow importer to find external dependencies. | |
saveColladaopts.LookupPaths = New List(Of String)(New String() {MyDir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The code example uses the DummyFileSystem, so the material files are not created. | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize Scene object | |
Dim scene As New Scene() | |
' Create a child node | |
scene.RootNode.CreateChildNode("sphere", New Sphere()).Material = New PhongMaterial() | |
' Set saving options | |
Dim opt As New ObjSaveOptions() | |
opt.FileSystem = New DummyFileSystem() | |
' Save 3D scene | |
scene.Save(MyDir & Convert.ToString("DiscardSavingMaterial_out.obj"), opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim saveOpts As New Discreet3DSSaveOptions() | |
' The start base for generating new name for duplicated names. | |
saveOpts.DuplicatedNameCounterBase = 2 | |
' The format of the duplicated counter. | |
saveOpts.DuplicatedNameCounterFormat = "NameFormat" | |
' The separator between object' S name and the duplicated counter. | |
saveOpts.DuplicatedNameSeparator = "Separator" | |
' Allows to export cameras | |
saveOpts.ExportCamera = True | |
' Allows to export light | |
saveOpts.ExportLight = True | |
' Flip the coordinate system | |
saveOpts.FlipCoordinateSystem = True | |
' Prefer to use gamma-corrected color if a 3ds file provides both original color and gamma-corrected color. | |
saveOpts.GammaCorrectedColor = True | |
' Use high-precise color which each color channel will use 32bit float. | |
saveOpts.HighPreciseColor = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
saveOpts.LookupPaths = New List(Of String)(New String() {MyDir}) | |
' Set the master scale | |
saveOpts.MasterScale = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim saveOpts As New FBXSaveOptions(FileFormat.FBX7500ASCII) | |
' Generates the legacy material properties. | |
saveOpts.ExportLegacyMaterialProperties = True | |
' Fold repeated curve data using FBX' S animation reference count | |
saveOpts.FoldRepeatedCurveData = True | |
' Always generates material mapping information for geometries if the attached node contains materials. | |
saveOpts.GenerateVertexElementMaterial = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
saveOpts.LookupPaths = New List(Of String)(New String() {MyDir}) | |
' Generates a video object for texture. | |
saveOpts.VideoForTexture = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize Scene object | |
Dim scene As New Scene() | |
' Create a child node | |
scene.RootNode.CreateChildNode("sphere", New Sphere()) | |
' Set glTF saving options. The code example embeds all assets into the target file usually a glTF file comes with some dependencies, a bin file for model' S vertex/indices, two .glsl files for vertex/fragment shaders | |
' Use opt.EmbedAssets to tells the Aspose.3D API to export scene and embed the dependencies inside the target file. | |
Dim opt As New GLTFSaveOptions(FileContentType.ASCII) | |
opt.EmbedAssets = True | |
' Use KHR_materials_common extension to define the material, thus no GLSL files are generated. | |
opt.UseCommonMaterials = True | |
' Customize the name of the buffer file which defines model | |
opt.BufferFile = "mybuf.bin" | |
' Save glTF file | |
scene.Save(MyDir & Convert.ToString("glTFSaveOptions_out.gltf"), opt) | |
' Save a binary glTF file using KHR_binary_glTF extension | |
scene.Save(MyDir & Convert.ToString("glTFSaveOptions_out.glb"), FileFormat.GLTF_Binary) | |
' Developers may use saving options to create a binary glTF file using KHR_binary_glTF extension | |
Dim opts As New GLTFSaveOptions(FileContentType.Binary) | |
scene.Save(MyDir & Convert.ToString("Test_out.glb"), opts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim saveObjOpts As New ObjSaveOptions() | |
' Import materials from external material library file | |
saveObjOpts.EnableMaterials = True | |
' Flip the coordinate system. | |
saveObjOpts.FlipCoordinateSystem = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
saveObjOpts.LookupPaths = New List(Of String)(New String() {MyDir}) | |
' Serialize W component in model' S vertex position | |
saveObjOpts.SerializeW = True | |
' Generate comments for each section | |
saveObjOpts.Verbose = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The code example uses the LocalFileSystem class to save dependencies to the local directory. | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize Scene object | |
Dim scene As New Scene() | |
' Create a child node | |
scene.RootNode.CreateChildNode("sphere", New Sphere()).Material = New PhongMaterial() | |
' Set saving options | |
Dim opt As New ObjSaveOptions() | |
opt.FileSystem = New LocalFileSystem(MyDir) | |
' Save 3D scene | |
scene.Save(MyDir & Convert.ToString("SavingDependenciesInLocalDirectory_out.obj"), opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The code example uses the MemoryFileSystem to intercepts the dependencies writing. | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize Scene object | |
Dim scene As New Scene() | |
' Create a child node | |
scene.RootNode.CreateChildNode("sphere", New Sphere()).Material = New PhongMaterial() | |
' Set saving options | |
Dim opt As New ObjSaveOptions() | |
Dim mfs As New MemoryFileSystem() | |
opt.FileSystem = mfs | |
' Save 3D scene | |
scene.Save(MyDir & Convert.ToString("SavingDependenciesInMemoryFileSystem_out.obj"), opt) | |
' Get the test.mtl file content | |
Dim mtl As Byte() = mfs.GetFileContent(MyDir & Convert.ToString("test.mtl")) | |
File.WriteAllBytes(MyDir & Convert.ToString("Material.mtl"), mtl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim saveSTLOpts As New STLSaveOptions() | |
' Flip the coordinate system. | |
saveSTLOpts.FlipCoordinateSystem = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
saveSTLOpts.LookupPaths = New List(Of String)(New String() {MyDir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Initialize an object | |
Dim saveU3DOptions As New U3DSaveOptions() | |
' Export normal data. | |
saveU3DOptions.ExportNormals = True | |
' Export the texture coordinates. | |
saveU3DOptions.ExportTextureCoordinates = True | |
' Export the vertex diffuse color. | |
saveU3DOptions.ExportVertexDiffuse = True | |
' Export vertex specular color | |
saveU3DOptions.ExportVertexSpecular = True | |
' Flip the coordinate system. | |
saveU3DOptions.FlipCoordinateSystem = True | |
' Configure the look up paths to allow importer to find external dependencies. | |
saveU3DOptions.LookupPaths = New List(Of String)(New String() {MyDir}) | |
' Compress the mesh data | |
saveU3DOptions.MeshCompression = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load an existing 3D file | |
Dim scene As New Scene(MyDir & Convert.ToString("document.fbx")) | |
' Triangulate a scene | |
PolygonModifier.Triangulate(scene) | |
' Save 3D scene | |
scene.Save(MyDir & Convert.ToString("triangulated_out.fbx"), FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
Dim scene As New Scene() | |
Dim camera As New Camera() | |
camera.NearPlane = 0.1 | |
scene.RootNode.CreateChildNode("camera", camera) | |
Dim light As New Light() With { | |
.NearPlane = 0.1, | |
.CastShadows = True, | |
.Color = New Vector3(Color.White) | |
} | |
scene.RootNode.CreateChildNode("light", light).Transform.Translation = New Vector3(9.4785, 5, 3.18) | |
light.LookAt = Vector3.Origin | |
light.Falloff = 90 | |
' Create a plane | |
Dim plane As Node = scene.RootNode.CreateChildNode("plane", New Plane(20, 20)) | |
plane.Material = New PhongMaterial() With { | |
.DiffuseColor = New Vector3(Color.DarkOrange) | |
} | |
plane.Transform.Translation = New Vector3(0, 0, 0) | |
' Create a torus for casting shadows | |
Dim m As Mesh = (New Torus("", 1, 0.4, 20, 20, Math.PI * 2)).ToMesh() | |
Dim torus As Node = scene.RootNode.CreateChildNode("torus", m) | |
torus.Material = New PhongMaterial() With { | |
.DiffuseColor = New Vector3(Color.Cornsilk) | |
} | |
torus.Transform.Translation = New Vector3(2, 1, 1) | |
If True Then | |
' Create a blue box don' T cast shadows | |
m = (New Box()).ToMesh() | |
m.CastShadows = False | |
Dim box As Node = scene.RootNode.CreateChildNode("box", m) | |
box.Material = New PhongMaterial() With { | |
.DiffuseColor = New Vector3(Color.Blue) | |
} | |
box.Transform.Translation = New Vector3(2, 1, -1) | |
End If | |
If True Then | |
' Create a red box that don' T receive shadow but cast shadows | |
m = (New Box()).ToMesh() | |
m.ReceiveShadows = False | |
Dim box As Node = scene.RootNode.CreateChildNode("box", m) | |
box.Material = New PhongMaterial() With { | |
.DiffuseColor = New Vector3(Color.Red) | |
} | |
box.Transform.Translation = New Vector3(-2, 1, 1) | |
End If | |
camera.ParentNode.Transform.Translation = New Vector3(10, 10, 10) | |
camera.LookAt = Vector3.Origin | |
Dim opt As New ImageRenderOptions() With { | |
.EnableShadows = True | |
} | |
scene.Render(camera, MyDir & Convert.ToString("CastAndReceiveShadow_out.png"), New Size(1024, 1024), ImageFormat.Png, opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load scene from file | |
Dim scene As New Scene(MyDir & Convert.ToString("camera.3ds")) | |
' Create a camera at (10,10,10) and look at the origin point for rendering, | |
' It must be attached to the scene before render | |
Dim camera As New Camera() | |
scene.RootNode.CreateChildNode("camera", camera) | |
camera.ParentNode.Transform.Translation = New Vector3(10, 10, 10) | |
camera.LookAt = Vector3.Origin | |
' Specify the image render option | |
Dim opt As New ImageRenderOptions() | |
' Set the background color | |
opt.BackgroundColor = Color.AliceBlue | |
' Tells renderer where the it can find textures | |
opt.AssetDirectories.Add(MyDir & Convert.ToString("textures")) | |
' Turn on shadow | |
opt.EnableShadows = True | |
' Render the scene in given camera' S perspective into specified png file with size 1024x1024 | |
scene.Render(camera, MyDir & Convert.ToString("Render3DModelImageFromCamera_out.png"), New Size(1024, 1024), ImageFormat.Png, opt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load an existing 3D file | |
Dim scene As New Scene(MyDir & Convert.ToString("document.fbx")) | |
' Triangulate a scene | |
PolygonModifier.BuildTangentBinormal(scene) | |
' Save 3D scene | |
scene.Save("BuildTangentAndBinormalData_out.fbx", FileFormat.FBX7400ASCII) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Get mesh of the Box | |
Dim box As Mesh = (New Box()).ToMesh() | |
' Create a customized vertex layout | |
Dim vd As New VertexDeclaration() | |
Dim position As VertexField = vd.AddField(VertexFieldDataType.FVector4, VertexFieldSemantic.Position) | |
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Normal) | |
' Get a triangle mesh | |
Dim triMesh__1 As TriMesh = TriMesh.FromMesh(box) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize object by Box class | |
Dim convertible As IMeshConvertible = New Box() | |
' Convert a Box to Mesh | |
Dim mesh As Mesh = convertible.ToMesh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize object by Cylinder class | |
Dim convertible As IMeshConvertible = New Cylinder() | |
' Convert a Cylinder to Mesh | |
Dim mesh As Mesh = convertible.ToMesh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize object by Plane class | |
Dim convertible As IMeshConvertible = New Plane() | |
' Convert a Plane to Mesh | |
Dim mesh As Mesh = convertible.ToMesh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
<StructLayout(LayoutKind.Sequential)> _ | |
Private Structure MyVertex | |
<Semantic(VertexFieldSemantic.Position)> _ | |
Private position As FVector3 | |
<Semantic(VertexFieldSemantic.Normal)> _ | |
Private normal As FVector3 | |
End Structure | |
Public Shared Sub Run() | |
' Initialize scene object | |
Dim scene As New Scene() | |
' Initialize Node class object | |
Dim cubeNode As New Node("sphere") | |
Dim sphere As Mesh = (New Sphere()).ToMesh() | |
' Convert any mesh into typed TriMesh | |
Dim myMesh = TriMesh(Of MyVertex).FromMesh(sphere) | |
' Get the vertex data in customized vertex structure. | |
Dim vertex As MyVertex() = myMesh.VerticesToTypedArray() | |
' Get the 32bit and 16bit indices | |
Dim indices32bit As Integer() | |
Dim indices16bit As UShort() | |
indices32bit = Nothing | |
indices16bit = Nothing | |
myMesh.IndicesToArray(indices32bit) | |
myMesh.IndicesToArray(indices16bit) | |
Using ms As New MemoryStream() | |
' Or we can write the vertex directly into stream like: | |
myMesh.WriteVerticesTo(ms) | |
' The indice data can be directly write to stream, we support 32-bit and 16-bit indice. | |
myMesh.Write16bIndicesTo(ms) | |
myMesh.Write32bIndicesTo(ms) | |
End Using | |
' Point node to the Mesh geometry | |
cubeNode.Entity = sphere | |
' Add Node to a scene | |
scene.RootNode.ChildNodes.Add(cubeNode) | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("SphereToTriangleMeshCustomMemoryLayoutScene.fbx") | |
' Save 3D scene in the supported file formats | |
scene.Save(MyDir, FileFormat.FBX7400ASCII) | |
Console.WriteLine("Indices = {0}, Actual vertices = {1}, vertices before merging = {2}", myMesh.IndicesCount, myMesh.VerticesCount, myMesh.UnmergedVerticesCount) | |
Console.WriteLine("Total bytes of vertices in memory {0}bytes", myMesh.VerticesSizeInBytes) | |
Console.WriteLine(Convert.ToString(vbLf & " Converted a Sphere mesh to triangle mesh with custom memory layout of the vertex successfully." & vbLf & "File saved at ") & MyDir) | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize object by Sphere class | |
Dim convertible As IMeshConvertible = New Sphere() | |
' Convert a Sphere to Mesh | |
Dim mesh As Mesh = convertible.ToMesh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Initialize object by Torus class | |
Dim convertible As IMeshConvertible = New Torus() | |
' Convert a Torus to Mesh | |
Dim mesh As Mesh = convertible.ToMesh() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
' Load a 3ds file, 3ds file doesn' T have normal data, but it has smoothing group | |
Dim s As New Scene(MyDir & Convert.ToString("camera.3ds")) | |
' Visit all nodes and create normal data for all meshes | |
s.RootNode.Accept(Function(n As Node) | |
Dim mesh As Mesh = n.GetEntity(Of Mesh)() | |
If mesh IsNot Nothing Then | |
Dim normals As VertexElementNormal = PolygonModifier.GenerateNormal(mesh) | |
mesh.VertexElements.Add(normals) | |
End If | |
Return True | |
End Function) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' The path to the documents directory. | |
Dim MyDir As String = RunExamples.GetDataDir() | |
MyDir = MyDir & Convert.ToString("test.fbx") | |
' load a 3D file | |
Dim scene As New Scene(MyDir) | |
' Split all meshes | |
PolygonModifier.SplitMesh(scene, SplitMeshPolicy.CloneData) | |
' Save file | |
MyDir = RunExamples.GetDataDir() + RunExamples.GetOutputFilePath("test-splitted.fbx") | |
scene.Save(MyDir, FileFormat.FBX7500ASCII) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
' Create a mesh of box(A box is composed by 6 planes) | |
Dim box As Mesh = (New Box()).ToMesh() | |
' Create a material element on this mesh | |
Dim mat As VertexElementMaterial = DirectCast(box.CreateElement(VertexElementType.Material, MappingMode.Polygon, ReferenceMode.Index), VertexElementMaterial) | |
' And specify different material index for each plane | |
mat.Indices.AddRange(New Integer() {0, 1, 2, 3, 4, 5}) | |
' Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh. | |
' We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information. | |
Dim planes As Mesh() = PolygonModifier.SplitMesh(box, SplitMeshPolicy.CloneData) | |
mat.Indices.Clear() | |
mat.Indices.AddRange(New Integer() {0, 0, 0, 1, 1, 1}) | |
' Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes. | |
' We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information. | |
planes = PolygonModifier.SplitMesh(box, SplitMeshPolicy.CompactData) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
private void InitRenderer() | |
{ | |
// Create a default camera, because it's required during the viewport's creation. | |
camera = new Camera(); | |
Scene.RootNode.CreateChildNode("camera", camera); | |
// Create the renderer and render window from window's native handle | |
renderer = Renderer.CreateRenderer(); | |
// Right now we only support native window handle from Microsoft Windows | |
// We'll support more platform on user's demand. | |
window = renderer.RenderFactory.CreateRenderWindow(new RenderParameters(), Handle); | |
// Create 4 viewports, the viewport's area is meanless here because we'll change it to the right area in the SetViewports later | |
viewports = new[] | |
{ | |
window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), | |
window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), | |
window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), | |
window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)) | |
}; | |
SetViewports(1); | |
//initialize shader for grid | |
GLSLSource src = new GLSLSource(); | |
src.VertexShader = @"#version 330 core | |
layout (location = 0) in vec3 position; | |
uniform mat4 matWorldViewProj; | |
void main() | |
{ | |
gl_Position = matWorldViewProj * vec4(position, 1.0f); | |
}"; | |
src.FragmentShader = @"#version 330 core | |
out vec4 color; | |
void main() | |
{ | |
color = vec4(1, 1, 1, 1); | |
}"; | |
// Define the input format used by GLSL vertex shader the format is struct ControlPoint { FVector3 Position;} | |
VertexDeclaration fd = new VertexDeclaration(); | |
fd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position); | |
// Compile shader from GLSL source code and specify the vertex input format | |
gridShader = renderer.RenderFactory.CreateShaderProgram(src, fd); | |
// Connect GLSL uniform to renderer's internal variable | |
gridShader.Variables = new ShaderVariable[] | |
{ | |
new ShaderVariable("matWorldViewProj", VariableSemantic.MatrixWorldViewProj) | |
}; | |
SceneUpdated(""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Private Sub InitRenderer() | |
' Create a default camera, because it's required during the viewport's creation. | |
camera = New Camera() | |
Scene.RootNode.CreateChildNode("camera", camera) | |
' Create the renderer and render window from window's native handle | |
renderer = Renderer.CreateRenderer() | |
' Right now we only support native window handle from Microsoft Windows | |
' We'll support more platform on user's demand. | |
window = renderer.RenderFactory.CreateRenderWindow(New RenderParameters(), Handle) | |
' Create 4 viewports, the viewport's area is meanless here because we'll change it to the right area in the SetViewports later | |
viewports = New () {window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1)), window.CreateViewport(camera, Color.Gray, RelativeRectangle.FromScale(0, 0, 1, 1))} | |
SetViewports(1) | |
'initialize shader for grid | |
Dim src As New GLSLSource() | |
src.VertexShader = "#version 330 core" & vbCr & vbLf & " layout (location = 0) in vec3 position;" & vbCr & vbLf & " uniform mat4 matWorldViewProj;" & vbCr & vbLf & " void main()" & vbCr & vbLf & " {" & vbCr & vbLf & " gl_Position = matWorldViewProj * vec4(position, 1.0f);" & vbCr & vbLf & " }" | |
src.FragmentShader = "#version 330 core" & vbCr & vbLf & " out vec4 color;" & vbCr & vbLf & " void main()" & vbCr & vbLf & " {" & vbCr & vbLf & " color = vec4(1, 1, 1, 1);" & vbCr & vbLf & " }" | |
' Define the input format used by GLSL vertex shader the format is struct ControlPoint { FVector3 Position;} | |
Dim fd As New VertexDeclaration() | |
fd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position) | |
' Compile shader from GLSL source code and specify the vertex input format | |
gridShader = renderer.RenderFactory.CreateShaderProgram(src, fd) | |
' Connect GLSL uniform to renderer's internal variable | |
gridShader.Variables = New ShaderVariable() {New ShaderVariable("matWorldViewProj", VariableSemantic.MatrixWorldViewProj)} | |
SceneUpdated("") | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
class Grid : ManualEntity | |
{ | |
public Grid(Renderer renderer, ShaderProgram shader) | |
{ | |
// Render state for grid | |
RenderState = renderer.RenderFactory.CreateRenderState(); | |
RenderState.DepthTest = true; | |
RenderState.DepthMask = true; | |
this.Shader = shader; | |
// Define the format of the control point to render the line | |
VertexDeclaration vd = new VertexDeclaration(); | |
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position); | |
// and create a vertex buffer for storing this kind of data | |
this.VertexBuffer = renderer.RenderFactory.CreateVertexBuffer(vd); | |
// Draw the primitive as lines | |
this.DrawOperation = DrawOperation.Lines; | |
this.RenderGroup = RenderQueueGroupId.Geometries; | |
List<FVector3> lines = new List<FVector3>(); | |
for (int i = -10; i <= 10; i++) | |
{ | |
// Draw - line | |
lines.Add(new FVector3(i, 0, -10)); | |
lines.Add(new FVector3(i,0, 10)); | |
// Draw | line | |
lines.Add(new FVector3(-10, 0, i)); | |
lines.Add(new FVector3(10, 0, i)); | |
} | |
// Put it to vertex buffer | |
VertexBuffer.LoadData(lines.ToArray()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Class Grid | |
Inherits ManualEntity | |
Public Sub New(renderer As Renderer, shader As ShaderProgram) | |
' Render state for grid | |
RenderState = renderer.RenderFactory.CreateRenderState() | |
RenderState.DepthTest = True | |
RenderState.DepthMask = True | |
Me.Shader = shader | |
' Define the format of the control point to render the line | |
Dim vd As New VertexDeclaration() | |
vd.AddField(VertexFieldDataType.FVector3, VertexFieldSemantic.Position) | |
' and create a vertex buffer for storing this kind of data | |
Me.VertexBuffer = renderer.RenderFactory.CreateVertexBuffer(vd) | |
' Draw the primitive as lines | |
Me.DrawOperation = DrawOperation.Lines | |
Me.RenderGroup = RenderQueueGroupId.Geometries | |
Dim lines As New List(Of FVector3)() | |
For i As Integer = -10 To 10 | |
' Draw - line | |
lines.Add(New FVector3(i, 0, -10)) | |
lines.Add(New FVector3(i, 0, 10)) | |
' Draw | line | |
lines.Add(New FVector3(-10, 0, i)) | |
lines.Add(New FVector3(10, 0, i)) | |
Next | |
' Put it to vertex buffer | |
VertexBuffer.LoadData(lines.ToArray()) | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
public class Vertex | |
{ | |
[Browsable(false)] | |
public int Index { get; set; } | |
public double X { get; set; } | |
public double Y { get; set; } | |
public Vertex(int index, double x, double y) | |
{ | |
Index = index; | |
X = x; | |
Y = y; | |
} | |
public override string ToString() | |
{ | |
return string.Format("#{0}: {1} {2}", Index, X, Y); | |
} | |
} | |
class PolygonCanvas : Control | |
{ | |
public List<Vertex> points = new List<Vertex>(); | |
public event EventHandler TriangleUpdated; | |
private Point mousePos; | |
private Pen virtualLine = new Pen(Color.DarkSeaGreen); | |
private Vector4[][] triangles; | |
private int[][] triangleIndices; | |
private Pen polygonPen = Pens.Black; | |
private Brush[] brushes = new Brush[] {Brushes.Blue, Brushes.BlueViolet, Brushes.DarkCyan, Brushes.ForestGreen, Brushes.LimeGreen}; | |
private Brush textBrush = Brushes.Black; | |
public PolygonCanvas() | |
{ | |
SetStyle(ControlStyles.ResizeRedraw, true); | |
SetStyle(ControlStyles.UserPaint, true); | |
SetStyle(ControlStyles.Selectable, true); | |
SetStyle(ControlStyles.OptimizedDoubleBuffer, true); | |
SetStyle(ControlStyles.AllPaintingInWmPaint , true); | |
Cursor = Cursors.Cross; | |
virtualLine.DashStyle = DashStyle.Dash; | |
virtualLine.DashPattern = new float[] {10, 10}; | |
} | |
protected override void OnPaint(PaintEventArgs e) | |
{ | |
base.OnPaint(e); | |
Graphics g = e.Graphics; | |
g.Clear(Color.AliceBlue); | |
if (points.Count == 0) | |
return; | |
Size size = this.Size; | |
if (points.Count == 1) | |
{ | |
// Draw virtual line | |
PointF pt = ToPoint(points[0], size); | |
g.DrawLine(virtualLine, mousePos, pt); | |
} | |
else if (points.Count == 2) | |
{ | |
// Draw virtual triangle | |
PointF pt1 = ToPoint(points[0], size); | |
PointF pt2 = ToPoint(points[1], size); | |
g.DrawLine(polygonPen, pt2, pt1); | |
g.DrawLine(virtualLine, mousePos, pt1); | |
g.DrawLine(virtualLine, mousePos, pt2); | |
} | |
else | |
{ | |
// Draw polygon and virtual line | |
// Draw triangles | |
if (triangles != null) | |
{ | |
for (int i = 0; i < triangles.Length; i++) | |
{ | |
PointF[] tri = ToPoints(triangles[i]); | |
// Shrink the triangle so we can see each triangle | |
float inv = 1.0f/3.0f; | |
float cx= (tri[0].X + tri[1].X + tri[2].X) * inv; | |
float cy= (tri[0].Y + tri[1].Y + tri[2].Y) * inv; | |
Shrink(tri, 0, cx, cy); | |
Shrink(tri, 1, cx, cy); | |
Shrink(tri, 2, cx, cy); | |
Brush brush = brushes[i%brushes.Length]; | |
g.FillPolygon(brush, tri); | |
// Draw triangle index | |
string text = string.Format("{0}/{1}/{2}", triangleIndices[i][0], triangleIndices[i][1], triangleIndices[i][2]); | |
g.DrawString(text, Font, textBrush, cx, cy); | |
} | |
} | |
// Draw index of each vertex | |
PointF[] polygon = ToPoints(this.points); | |
g.DrawPolygon(polygonPen, polygon); | |
for (int i = 0; i < polygon.Length; i++) | |
{ | |
string text = string.Format("{0}", i); | |
g.DrawString(text, Font, textBrush, polygon[i]); | |
} | |
g.DrawLine(virtualLine, mousePos, polygon[0]); | |
g.DrawLine(virtualLine, mousePos, polygon[polygon.Length - 1]); | |
} | |
} | |
private void Shrink(PointF[] tri, int i, float cx, float cy) | |
{ | |
float dx = tri[i].X - cx; | |
float dy = tri[i].Y - cy; | |
float inv = 5.0f/(float) Math.Sqrt(dx*dx + dy*dy); | |
dx *= inv; | |
dy *= inv; | |
tri[i] = new PointF(tri[i].X - dx, tri[i].Y - dy); | |
} | |
private PointF[] ToPoints(IList<Vector4> vec) | |
{ | |
Size size = Size; | |
PointF[] ret = new PointF[vec.Count]; | |
for(int i = 0; i < ret.Length; i++) | |
ret[i] = new PointF((float)vec[i].x * size.Width, (float)vec[i].y * Height); | |
return ret; | |
} | |
private PointF[] ToPoints(IList<Vertex> vec) | |
{ | |
Size size = Size; | |
PointF[] ret = new PointF[vec.Count]; | |
for(int i = 0; i < ret.Length; i++) | |
ret[i] = ToPoint(vec[i], size); | |
return ret; | |
} | |
private PointF ToPoint(Vertex vec, Size size) | |
{ | |
return new PointF((float)vec.X * size.Width, (float)vec.Y * Height); | |
} | |
protected override void OnMouseMove(MouseEventArgs e) | |
{ | |
base.OnMouseMove(e); | |
mousePos = e.Location; | |
Invalidate(); | |
} | |
protected override void OnMouseUp(MouseEventArgs e) | |
{ | |
base.OnMouseUp(e); | |
if (e.Button == MouseButtons.Left) | |
{ | |
Vertex pt = new Vertex(points.Count, e.X*1.0/Width, e.Y*1.0/Height); | |
points.Add(pt); | |
UpdateTriangles(); | |
} | |
else | |
{ | |
// Erase last point | |
if (points.Count > 0) | |
{ | |
points.RemoveAt(points.Count - 1); | |
UpdateTriangles(); | |
} | |
} | |
} | |
public void UpdateTriangles() | |
{ | |
DoTriangulate(); | |
Invalidate(); | |
if(TriangleUpdated != null) | |
TriangleUpdated(this, new EventArgs()); | |
} | |
/// <summary> | |
/// Triangulate the polygon into a lot of triangles | |
/// </summary> | |
private void DoTriangulate() | |
{ | |
triangles = null; | |
if (points.Count <= 3) | |
return; | |
// Convert to Vector4[] | |
Vector4[] controlPoints = new Vector4[points.Count]; | |
for (int i = 0; i < points.Count; i++) | |
{ | |
controlPoints[i] = new Vector4(points[i].X, points[i].Y, 0); | |
} | |
// Triangulate the polygon | |
triangleIndices = PolygonModifier.Triangulate(controlPoints); | |
// Save triangle vertex for later drawing. | |
triangles = new Vector4[triangleIndices.Length][]; | |
for (int i = 0; i < triangleIndices.Length; i++) | |
{ | |
int[] triangleFace = triangleIndices[i]; | |
Vector4[] triangle = triangles[i] = new Vector4[3]; | |
triangle[0] = controlPoints[triangleFace[0]]; | |
triangle[1] = controlPoints[triangleFace[1]]; | |
triangle[2] = controlPoints[triangleFace[2]]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Public Class Vertex | |
<Browsable(False)> _ | |
Public Property Index() As Integer | |
Get | |
Return m_Index | |
End Get | |
Set(value As Integer) | |
m_Index = Value | |
End Set | |
End Property | |
Private m_Index As Integer | |
Public Property X() As Double | |
Get | |
Return m_X | |
End Get | |
Set(value As Double) | |
m_X = Value | |
End Set | |
End Property | |
Private m_X As Double | |
Public Property Y() As Double | |
Get | |
Return m_Y | |
End Get | |
Set(value As Double) | |
m_Y = Value | |
End Set | |
End Property | |
Private m_Y As Double | |
Public Sub New(index__1 As Integer, x__2 As Double, y__3 As Double) | |
Index = index__1 | |
X = x__2 | |
Y = y__3 | |
End Sub | |
Public Overrides Function ToString() As String | |
Return String.Format("#{0}: {1} {2}", Index, X, Y) | |
End Function | |
End Class | |
Class PolygonCanvas | |
Inherits Control | |
Public points As New List(Of Vertex)() | |
Public Event TriangleUpdated As EventHandler | |
Private mousePos As Point | |
Private virtualLine As New Pen(Color.DarkSeaGreen) | |
Private triangles As Vector4()() | |
Private triangleIndices As Integer()() | |
Private polygonPen As Pen = Pens.Black | |
Private brushes As Brush() = New Brush() {Brushes.Blue, Brushes.BlueViolet, Brushes.DarkCyan, Brushes.ForestGreen, Brushes.LimeGreen} | |
Private textBrush As Brush = Brushes.Black | |
Public Sub New() | |
SetStyle(ControlStyles.ResizeRedraw, True) | |
SetStyle(ControlStyles.UserPaint, True) | |
SetStyle(ControlStyles.Selectable, True) | |
SetStyle(ControlStyles.OptimizedDoubleBuffer, True) | |
SetStyle(ControlStyles.AllPaintingInWmPaint, True) | |
Cursor = Cursors.Cross | |
virtualLine.DashStyle = DashStyle.Dash | |
virtualLine.DashPattern = New Single() {10, 10} | |
End Sub | |
Protected Overrides Sub OnPaint(e As PaintEventArgs) | |
MyBase.OnPaint(e) | |
Dim g As Graphics = e.Graphics | |
g.Clear(Color.AliceBlue) | |
If points.Count = 0 Then | |
Return | |
End If | |
Dim size As Size = Me.Size | |
If points.Count = 1 Then | |
' Draw virtual line | |
Dim pt As PointF = ToPoint(points(0), size) | |
g.DrawLine(virtualLine, mousePos, pt) | |
ElseIf points.Count = 2 Then | |
' Draw virtual triangle | |
Dim pt1 As PointF = ToPoint(points(0), size) | |
Dim pt2 As PointF = ToPoint(points(1), size) | |
g.DrawLine(polygonPen, pt2, pt1) | |
g.DrawLine(virtualLine, mousePos, pt1) | |
g.DrawLine(virtualLine, mousePos, pt2) | |
Else | |
' Draw polygon and virtual line | |
' Draw triangles | |
If triangles IsNot Nothing Then | |
For i As Integer = 0 To triangles.Length - 1 | |
Dim tri As PointF() = ToPoints(triangles(i)) | |
' Shrink the triangle so we can see each triangle | |
Dim inv As Single = 1.0F / 3.0F | |
Dim cx As Single = (tri(0).X + tri(1).X + tri(2).X) * inv | |
Dim cy As Single = (tri(0).Y + tri(1).Y + tri(2).Y) * inv | |
Shrink(tri, 0, cx, cy) | |
Shrink(tri, 1, cx, cy) | |
Shrink(tri, 2, cx, cy) | |
Dim brush As Brush = brushes(i Mod brushes.Length) | |
g.FillPolygon(brush, tri) | |
' Draw triangle index | |
Dim text As String = String.Format("{0}/{1}/{2}", triangleIndices(i)(0), triangleIndices(i)(1), triangleIndices(i)(2)) | |
g.DrawString(text, Font, textBrush, cx, cy) | |
Next | |
End If | |
' Draw index of each vertex | |
Dim polygon As PointF() = ToPoints(Me.points) | |
g.DrawPolygon(polygonPen, polygon) | |
For i As Integer = 0 To polygon.Length - 1 | |
Dim text As String = String.Format("{0}", i) | |
g.DrawString(text, Font, textBrush, polygon(i)) | |
Next | |
g.DrawLine(virtualLine, mousePos, polygon(0)) | |
g.DrawLine(virtualLine, mousePos, polygon(polygon.Length - 1)) | |
End If | |
End Sub | |
Private Sub Shrink(tri As PointF(), i As Integer, cx As Single, cy As Single) | |
Dim dx As Single = tri(i).X - cx | |
Dim dy As Single = tri(i).Y - cy | |
Dim inv As Single = 5.0F / CSng(Math.Sqrt(dx * dx + dy * dy)) | |
dx *= inv | |
dy *= inv | |
tri(i) = New PointF(tri(i).X - dx, tri(i).Y - dy) | |
End Sub | |
Private Function ToPoints(vec As IList(Of Vector4)) As PointF() | |
Dim size__1 As Size = Size | |
Dim ret As PointF() = New PointF(vec.Count - 1) {} | |
For i As Integer = 0 To ret.Length - 1 | |
ret(i) = New PointF(CSng(vec(i).x) * size__1.Width, CSng(vec(i).y) * Height) | |
Next | |
Return ret | |
End Function | |
Private Function ToPoints(vec As IList(Of Vertex)) As PointF() | |
Dim size__1 As Size = Size | |
Dim ret As PointF() = New PointF(vec.Count - 1) {} | |
For i As Integer = 0 To ret.Length - 1 | |
ret(i) = ToPoint(vec(i), size__1) | |
Next | |
Return ret | |
End Function | |
Private Function ToPoint(vec As Vertex, size As Size) As PointF | |
Return New PointF(CSng(vec.X) * size.Width, CSng(vec.Y) * Height) | |
End Function | |
Protected Overrides Sub OnMouseMove(e As MouseEventArgs) | |
MyBase.OnMouseMove(e) | |
mousePos = e.Location | |
Invalidate() | |
End Sub | |
Protected Overrides Sub OnMouseUp(e As MouseEventArgs) | |
MyBase.OnMouseUp(e) | |
If e.Button = MouseButtons.Left Then | |
Dim pt As New Vertex(points.Count, e.X * 1.0 / Width, e.Y * 1.0 / Height) | |
points.Add(pt) | |
UpdateTriangles() | |
Else | |
' Erase last point | |
If points.Count > 0 Then | |
points.RemoveAt(points.Count - 1) | |
UpdateTriangles() | |
End If | |
End If | |
End Sub | |
Public Sub UpdateTriangles() | |
DoTriangulate() | |
Invalidate() | |
RaiseEvent TriangleUpdated(Me, New EventArgs()) | |
End Sub | |
''' <summary> | |
''' Triangulate the polygon into a lot of triangles | |
''' </summary> | |
Private Sub DoTriangulate() | |
triangles = Nothing | |
If points.Count <= 3 Then | |
Return | |
End If | |
' Convert to Vector4[] | |
Dim controlPoints As Vector4() = New Vector4(points.Count - 1) {} | |
For i As Integer = 0 To points.Count - 1 | |
controlPoints(i) = New Vector4(points(i).X, points(i).Y, 0) | |
Next | |
' Triangulate the polygon | |
triangleIndices = PolygonModifier.Triangulate(controlPoints) | |
' Save triangle vertex for later drawing. | |
triangles = New Vector4(triangleIndices.Length - 1)() {} | |
For i As Integer = 0 To triangleIndices.Length - 1 | |
Dim triangleFace As Integer() = triangleIndices(i) | |
Dim triangle As Vector4() = InlineAssignHelper(triangles(i), New Vector4(2) {}) | |
triangle(0) = controlPoints(triangleFace(0)) | |
triangle(1) = controlPoints(triangleFace(1)) | |
triangle(2) = controlPoints(triangleFace(2)) | |
Next | |
End Sub | |
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T | |
target = value | |
Return value | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment