Last active
May 10, 2024 08:39
-
-
Save aspose-3d-gists/9563193e834f0087b554c83130fcf7c7 to your computer and use it in GitHub Desktop.
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
This Gist contains C# 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. | |
// 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 | |
var output = RunExamples.GetOutputFilePath("test.fbx"); | |
scene.Save(output, 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 data directory | |
string dataDir = RunExamples.GetDataDir(); | |
// Initialize scene object | |
Scene scene = new Scene(); | |
// Set Vector | |
scene.RootNode.CreateChildNode(new Plane() { Up = new Vector3(1, 1, 3) }); | |
//This will generate a plane that has customized orientation | |
scene.Save(dataDir + "ChangePlaneOrientation.obj", 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 | |
// Load a scene | |
Scene scene = new Scene(); | |
var box = new Box(); | |
var tr = scene.RootNode.CreateChildNode(box).Transform; | |
tr.Scale = new Vector3(12, 12, 12); | |
tr.Translation = new Vector3(10, 0, 0); | |
tr = scene.RootNode.CreateChildNode(box).Transform; | |
// Scale transform | |
tr.Scale = new Vector3(5, 5, 5); | |
// Set Euler Angles | |
tr.EulerAngles = new Vector3(50, 10, 0); | |
scene.RootNode.CreateChildNode(); | |
scene.RootNode.CreateChildNode().CreateChildNode(box); | |
scene.RootNode.CreateChildNode().CreateChildNode(box); | |
// Save compressed AMF file | |
scene.Save(RunExamples.GetOutputFilePath("Aspose.amf"), new AmfSaveOptions() { 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(); | |
// 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 input file | |
string input = RunExamples.GetDataFilePath("camera.3ds"); | |
// Initialize scene object | |
Scene scene = new Scene(); | |
scene.Open(input, FileFormat.Discreet3DS); | |
var output = RunExamples.GetOutputFilePath( "FlipCoordinateSystem.obj"); | |
scene.Save(output, 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 | |
// load a 3D file | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath("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 | |
string dataDir = RunExamples.GetDataDir(); | |
Scene scene = new Scene(dataDir+ "EmbeddedTexture.fbx"); | |
Material material = scene.RootNode.ChildNodes[0].Material; | |
PropertyCollection props = material.Properties; | |
//List all properties using foreach | |
foreach (var prop in props) | |
{ | |
Console.WriteLine("{0} = {1}", prop.Name, prop.Value); | |
} | |
//or using ordinal for loop | |
for (int i = 0; i < props.Count; i++) | |
{ | |
var prop = props[i]; | |
Console.WriteLine("{0} = {1}", prop.Name, prop.Value); | |
} | |
//Get property value by name | |
var diffuse = props["Diffuse"]; | |
Console.WriteLine(diffuse); | |
//modify property value by name | |
props["Diffuse"] = new Vector3(1, 0, 1); | |
//Get property instance by name | |
Property pdiffuse = props.FindProperty("Diffuse"); | |
Console.WriteLine(pdiffuse); | |
//Since Property is also inherited from A3DObject | |
//It's possible to get the property of the property | |
Console.WriteLine("Property flags = {0}", pdiffuse.GetProperty("flags")); | |
//and some properties that only defined in FBX file: | |
Console.WriteLine("Label = {0}", pdiffuse.GetProperty("label")); | |
Console.WriteLine("Type Name = {0}", pdiffuse.GetProperty("typeName")); | |
//so traversal on property's property is possible | |
foreach (var pp in pdiffuse.Properties) | |
{ | |
Console.WriteLine("Diffuse.{0} = {1}", pp.Name, pp.Value); | |
} |
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 | |
// Load an existing 3D scene | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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 | |
// Load an existing 3D scene | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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 bind point based on translation property | |
BindPoint bindPoint = new BindPoint(scene, translation); | |
// Create the animation curve on X component of the scale | |
bindPoint.BindKeyframeSequence("X", new KeyframeSequence() | |
{ | |
// 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 | |
bindPoint.BindKeyframeSequence("Z", new KeyframeSequence() | |
{ | |
// 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 output = RunExamples.GetOutputFilePath("PropertyToDocument.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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(); | |
// 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"); | |
var output = RunExamples.GetOutputFilePath("camera-test.3ds"); | |
scene.Save(output, 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.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 saved file | |
var output = RunExamples.GetOutputFilePath("InformationToScene.fbx"); | |
// Save scene to 3D supported file formats | |
scene.Save(output, 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 the base shape to be extruded | |
var shape = Shape.FromControlPoints( | |
new Vector3(1, 1, 0), | |
new Vector3(-1, 1, 0), | |
new Vector3(-1, -1, 0), | |
new Vector3(1, -1, 0) | |
); | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(5, 0, 0); | |
// If Center property is true, the extrusion range is from -Height/2 to Height/2, otherwise the extrusion is from 0 to Height | |
// Perform linear extrusion on left node using center and slices property | |
left.CreateChildNode(new LinearExtrusion(shape, 2) { Center = false, Slices = 3 }); | |
// Set ground plane for reference | |
left.CreateChildNode(new Box(0.01, 3, 3)); | |
// Perform linear extrusion on left node using center and slices property | |
right.CreateChildNode(new LinearExtrusion(shape, 2) { Center = true, Slices = 3 }); | |
// Set ground plane for reference | |
right.CreateChildNode(new Box(0.01, 3, 3)); | |
// Save 3D scene | |
scene.Save(MyDir + "CenterInLinearExtrusion.obj", 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 source file that needs to be compressed and the output file after saving | |
string file = "template.3ds"; | |
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".fbx"; | |
// create an instance of Scene | |
Scene scene = new Scene(file); | |
// create an instance of AmfSaveOptions | |
var options = new Aspose.ThreeD.Formats.FbxSaveOptions(FileFormat.FBX7400ASCII); | |
//Save the file in the format you want | |
scene.Save(output, options); |
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 the base shape to be extruded | |
var shape = Shape.FromControlPoints( | |
new Vector3(1, 1, 0), | |
new Vector3(-1, 1, 0), | |
new Vector3(-1, -1, 0), | |
new Vector3(1, -1, 0) | |
); | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(8, 0, 0); | |
// Direction property defines the direction of the extrusion. | |
// Perform linear extrusion on left node using twist and slices property | |
left.CreateChildNode(new LinearExtrusion(shape, 10) { Twist = 360, Slices = 100 }); | |
// Perform linear extrusion on right node using twist, slices, and direction property | |
right.CreateChildNode(new LinearExtrusion(shape, 10) { Twist = 360, Slices = 100, Direction = new Vector3(0.3, 0.2, 1) }); | |
// Save 3D scene | |
scene.Save(MyDir + "DirectionInLinearExtrusion.obj", 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
Scene scene = Scene.FromFile("input.glb"); | |
var opt = new ObjSaveOptions(); | |
opt.ExportTextures = true; | |
scene.Save("output.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 | |
//Source files that need to extract assets | |
string file = "template.3ds"; | |
Scene scene = new Scene(file); | |
//The output is in a compressed file format, and Directory represents the name of an existing folder | |
var zipOutput = Path.Combine("Directory", "OutputFile.zip"); | |
using var output = new FileStream(zipOutput, FileMode.Create); | |
using var za = new Zip(output); | |
//Call the Extract method to perform asset extraction operations | |
Extract(scene, za, true); | |
//Callable Extract method,The parameter texture indicates: whether to extract the texture | |
private void Extract(Scene scene, Zip za, bool texture) | |
{ | |
var extractor = new Extractor(za, texture); | |
extractor.Extract(scene); | |
} | |
//Create a compressed file processing class | |
class Zip : IDisposable | |
{ | |
private ZipArchive archive; | |
private HashSet<string> entries = new HashSet<string>(); | |
public Zip(Stream stream) | |
{ | |
archive = new ZipArchive(stream, ZipArchiveMode.Create); | |
} | |
public void Dispose() | |
{ | |
archive.Dispose(); | |
} | |
public void Add(string fileName, byte[] content, bool enableCompression) | |
{ | |
var entryName = PickName(fileName); | |
var compressionLevel = enableCompression ? CompressionLevel.Fastest : CompressionLevel.NoCompression; | |
var entry = archive.CreateEntry(entryName, compressionLevel); | |
using var stream = entry.Open(); | |
stream.Write(content, 0, content.Length); | |
} | |
private string PickName(string fileName) | |
{ | |
if (!entries.Contains(fileName)) | |
{ | |
entries.Add(fileName); | |
return fileName; | |
} | |
var baseName = Path.GetFileNameWithoutExtension(fileName); | |
var ext = Path.GetExtension(fileName); | |
for (var idx = 2; ; idx++) | |
{ | |
var newName = baseName + "_" + idx; | |
if (!string.IsNullOrEmpty(ext)) | |
newName += ext; | |
if (entries.Contains(newName)) | |
continue; | |
entries.Add(newName); | |
return newName; | |
} | |
} | |
} | |
//Create an asset extraction processing class | |
class Extractor | |
{ | |
private Zip zip; | |
private bool texture; | |
HashSet<A3DObject> visited = new HashSet<A3DObject>(); | |
public Extractor(Zip zip, bool texture) | |
{ | |
this.zip = zip; | |
this.texture = texture; | |
} | |
private bool CanVisit(A3DObject obj) | |
{ | |
if (visited.Contains(obj)) | |
return false; | |
visited.Add(obj); | |
return true; | |
} | |
public void Extract(Scene scene) | |
{ | |
if (scene.Library != null && scene.Library.Count > 0) | |
{ | |
foreach (var obj in scene.Library) | |
{ | |
Visit(obj); | |
} | |
} | |
VisitNode(scene.RootNode); | |
} | |
private void VisitNode(Node node) | |
{ | |
if (!CanVisit(node)) | |
return; | |
if (texture) | |
{ | |
foreach (var mat in node.Materials) | |
{ | |
VisitMaterial(mat); | |
} | |
} | |
foreach (var entity in node.Entities) | |
{ | |
if (entity is Mesh) | |
Save((Mesh)entity, node.Name); | |
} | |
foreach (var child in node.ChildNodes) | |
{ | |
VisitNode(child); | |
} | |
} | |
private void VisitMaterial(Material mat) | |
{ | |
if (!CanVisit(mat)) | |
return; | |
if (!texture) | |
return; | |
foreach (var tslot in mat) | |
{ | |
if (tslot.Texture is Texture) | |
{ | |
Save((Texture)tslot.Texture); | |
} | |
} | |
} | |
private void Visit(A3DObject obj) | |
{ | |
if (texture && obj is Texture) | |
{ | |
Save((Texture)obj); | |
} | |
else if (obj is Mesh) | |
{ | |
Save((Mesh)obj, null); | |
} | |
else if (obj is Node) | |
{ | |
VisitNode((Node)obj); | |
} | |
} | |
private void Save(Mesh mesh, string? nodeName) | |
{ | |
if (!CanVisit(mesh)) | |
return; | |
Scene scene = new Scene(mesh); | |
using (var ms = new MemoryStream()) | |
{ | |
scene.Save(ms, FileFormat.FBX7400ASCII); | |
var name = nodeName; | |
if (string.IsNullOrEmpty(name)) | |
name = mesh.Name; | |
if (string.IsNullOrEmpty(name)) | |
name = "mesh"; | |
var ext = ".fbx"; | |
zip.Add(name + ext, ms.ToArray(), true); | |
} | |
} | |
private void Save(Texture tex) | |
{ | |
if (tex.Content == null || !CanVisit(tex)) | |
return; | |
var fileName = tex.FileName != null ? Path.GetFileName(tex.FileName) : null; | |
zip.Add(fileName, tex.Content, 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 | |
// 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 USDZ format | |
scene.Save(RunExamples.GetOutputFilePath("PBR_Material_Box_Out.usdz")); |
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 | |
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); | |
var output = RunExamples.GetOutputFilePath("test_out.fbx"); | |
// Save to file | |
scene.Save(output, 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. | |
var output = RunExamples.GetOutputFilePath("CubeScene.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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 node | |
var n = new Node(); | |
// Get Geometric Translation | |
n.Transform.GeometricTranslation = new Vector3(10, 0, 0); | |
// The first Console.WriteLine will output the transform matrix that includes the geometric transformation | |
// while the second one will not. | |
Console.WriteLine(n.EvaluateGlobalTransform(true)); | |
Console.WriteLine(n.EvaluateGlobalTransform(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 | |
// 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. | |
// Set local file path | |
diffuse.FileName = RunExamples.GetOutputFilePath("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(RunExamples.GetDataFilePath("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; | |
var output = RunExamples.GetOutputFilePath("MaterialToCube.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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 output = RunExamples.GetOutputFilePath("NodeHierarchy.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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. | |
var output = RunExamples.GetOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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. | |
var output = RunExamples.GetOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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. | |
var output = RunExamples.GetOutputFilePath("TransformationToNode.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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. | |
// Initialize scene object | |
Scene scene = new Scene(); | |
scene.Open(RunExamples.GetDataFilePath("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; | |
}); | |
var output = RunExamples.GetOutputFilePath("document.fbx"); | |
scene.Save(output, 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 original image that needs to be uploaded and the 3d file output after saving | |
string file = "template.bmp"; | |
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".fbx"; | |
//Create some new parameters | |
var td = TextureData.FromFile(file); | |
const float nozzleSize = 0.9f;//0.2mm | |
const float layerHeight = 0.2f; | |
var grayscale = ToGrayscale(td); | |
const float width = 120.0f;//canvas width is 200.0mm | |
float height = width / td.Width * td.Height; | |
float thickness = 10.0f;//10mm thickness | |
float layers = thickness / layerHeight; | |
int widthSegs = (int)Math.Floor(width / nozzleSize); | |
int heightSegs = (int)Math.Floor(height / nozzleSize); | |
//Perform computational operations on Mesh objects | |
var mesh = new Mesh(); | |
for (int y = 0; y < heightSegs; y++) | |
{ | |
float dy = (float)y / heightSegs; | |
for (int x = 0; x < widthSegs; x++) | |
{ | |
float dx = (float)x / widthSegs; | |
float gray = Sample(grayscale, td.Width, td.Height, dx, dy); | |
float v = (1 - gray) * thickness; | |
mesh.ControlPoints.Add(new Vector4(dx * width, dy * height, v)); | |
} | |
} | |
for (int y = 0; y < heightSegs - 1; y++) | |
{ | |
int row = (y * heightSegs); | |
int ptr = row; | |
for (int x = 0; x < widthSegs - 1; x++) | |
{ | |
mesh.CreatePolygon(ptr, ptr + widthSegs, ptr + 1); | |
mesh.CreatePolygon(ptr + 1, ptr + widthSegs, ptr + widthSegs + 1); | |
ptr++; | |
} | |
} | |
//Generate 3d scene and save objects | |
var scene = new Scene(mesh); | |
scene.Save(output, FileFormat.FBX7400ASCII); | |
//The sample method to call | |
static float Sample(float[,] data, int w, int h, float x, float y) | |
{ | |
return data[(int)(x * w), (int)(y * h)]; | |
} | |
//ToGrayscale method to call | |
static float[,] ToGrayscale(TextureData td) | |
{ | |
var ret = new float[td.Width, td.Height]; | |
var stride = td.Stride; | |
var data = td.Data; | |
var bytesPerPixel = td.BytesPerPixel; | |
for (int y = 0; y < td.Height; y++) | |
{ | |
int ptr = y * stride; | |
for (int x = 0; x < td.Width; x++) | |
{ | |
var v = (data[ptr] * 0.21f + data[ptr + 1] * 0.72f + data[ptr + 2] * 0.07f) / 255.0f; | |
ret[x, y] = v; | |
ptr += bytesPerPixel; | |
} | |
} | |
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 | |
CancellationTokenSource cts = new CancellationTokenSource(); | |
Scene scene = new Scene(); | |
cts.CancelAfter(1000); | |
try | |
{ | |
scene.Open(RunExamples.GetOutputFilePath("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. | |
var output = RunExamples.GetOutputFilePath("document.fbx"); | |
// Create an object of the Scene class | |
Scene scene = new Scene(); | |
// Save 3D scene document | |
scene.Save(output, 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 | |
// Detect the format of a 3D file | |
FileFormat inputFormat = FileFormat.Detect(RunExamples.GetDataFilePath("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 | |
byte[] password = null; | |
List<Scene> scenes = FileFormat.PDF.ExtractScene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath(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. | |
byte[] password = null; | |
// Extract 3D contents | |
List<byte[]> contents = FileFormat.PDF.Extract(RunExamples.GetDataFilePath("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 dataDir = 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[] { dataDir }); |
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 | |
string dataDir = RunExamples.GetDataDir(); | |
//This will output all properties defined in GlobalSettings in FBX file. | |
Scene scene = new Scene(); | |
var opt = new FbxLoadOptions() { KeepBuiltinGlobalSettings = true }; | |
scene.Open(dataDir + "test.FBX", opt); | |
foreach (Property property in scene.RootNode.AssetInfo.Properties) | |
{ | |
Console.WriteLine(property); | |
} |
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(); | |
// 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( dataDir + "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 dataDir = 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.Add(dataDir); |
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(); | |
// 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(RunExamples.GetDataFilePath("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 dataDir = 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[] { dataDir }); |
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(); | |
// 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[] { dataDir }); |
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(); | |
// 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(RunExamples.GetDataFilePath("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 | |
// 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(RunExamples.GetOutputFilePath("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 | |
// 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(RunExamples.GetDataFilePath("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. | |
// Initialize a Scene class object | |
Scene scene = new Scene(); | |
// Load an existing 3D document | |
scene.Open(RunExamples.GetDataFilePath("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 | |
string dataDir = RunExamples.GetDataDir(); | |
Scene scene = new Scene(RunExamples.GetDataFilePath("att-test.rvm")); | |
FileFormat.RvmBinary.LoadAttributes(scene, RunExamples.GetDataFilePath("att-test.att")); |
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 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(RunExamples.GetOutputFilePath("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 | |
// Load a 3D document into Aspose.3D | |
Scene scene = new Scene(RunExamples.GetDataFilePath("document.fbx")); | |
scene.Save(RunExamples.GetOutputFilePath("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 | |
// Load a 3D document into Aspose.3D | |
Scene scene = new Scene(); | |
// Open an existing 3D scene | |
scene.Open("document.fbx"); | |
// Save Scene to a stream | |
MemoryStream dstStream = new MemoryStream(); | |
scene.Save(dstStream, FileFormat.FBX7500ASCII); | |
// Save Scene to a local path | |
scene.Save("output_out.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 | |
string dataDir = 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[] { dataDir }); |
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. | |
// 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(RunExamples.GetOutputFilePath("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 dataDir = 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[] { dataDir }); | |
// 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 | |
// 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(RunExamples.GetOutputFilePath("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 dataDir = 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[] { dataDir }); | |
// 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 | |
// 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(RunExamples.GetOutputFilePath("glTFSaveOptions_out.gltf"), opt); | |
// Save a binary glTF file using KHR_binary_glTF extension | |
scene.Save(RunExamples.GetOutputFilePath("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(RunExamples.GetOutputFilePath("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 | |
// Initialize 3D scene | |
var scene = new Scene(); | |
// Create a child node | |
var node = scene.RootNode.CreateChildNode(new Cylinder()); | |
// Set child node properites | |
node.Material = new LambertMaterial() { DiffuseColor = new Vector3(Color.Chartreuse) }; | |
scene.RootNode.CreateChildNode(new Light() { LightType = LightType.Point }).Transform.Translation = new Vector3(10, 0, 10); | |
// Create a Html5SaveOptions | |
var opt = new Html5SaveOptions(); | |
//Turn off the grid | |
opt.ShowGrid = false; | |
//Turn off the user interface | |
opt.ShowUI = false; | |
// Save 3D to HTML5 | |
scene.Save(RunExamples.GetDataDir() + "D:\\HtmlSaveOption.html", 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(); | |
// 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[] { dataDir }); | |
// 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 | |
// Initialize 3D scene | |
Scene scene = new Scene(new Sphere()); | |
// Initialize GltfSaveOptions | |
GltfSaveOptions opt = new GltfSaveOptions(FileFormat.GLTF2); | |
// The JSON content of GLTF file is indented for human reading, default value is false | |
opt.PrettyPrint = true; | |
// Save 3D Scene | |
scene.Save(RunExamples.GetDataDir() + "prettyPrintInGltfSaveOption.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 | |
string dataDir = RunExamples.GetDataDir(); | |
Scene scene = new Scene(); | |
var node = scene.RootNode.CreateChildNode("Box", new Box()); | |
node.SetProperty("rvm:Refno", "=3462123"); | |
node.SetProperty("rvm:Description", "This is the description of the box"); | |
//The RVM attribute's prefix is rvm:, all properties that starts with rvm: will be exported to .att file(the prefix will be removed) | |
var opt = new RvmSaveOptions() { AttributePrefix = "rvm:", ExportAttributes = true }; | |
scene.Save(dataDir + "test.rvm", 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 LocalFileSystem class to save dependencies to the local directory. | |
string dataDir = 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(dataDir); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("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. | |
// 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(RunExamples.GetOutputFilePath("SavingDependenciesInMemoryFileSystem_out.obj"), opt); | |
// Get the test.mtl file content | |
byte[] mtl = mfs.GetFileContent("SavingDependenciesInMemoryFileSystem_out.mtl"); | |
File.WriteAllBytes(RunExamples.GetOutputFilePath("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 dataDir = 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[] { dataDir }); |
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(); | |
// 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[] { dataDir }); | |
// 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 | |
//Multiple source files that need to be merged | |
string[] files = { "template.3ds", "template2.3ds" }; | |
//Process file merge to generate usdz file | |
Scene scene = new Scene(); | |
int i = 0; | |
foreach (var file in files) | |
{ | |
using var fs = new FileStream(file, FileMode.Open, FileAccess.Read); | |
FileFormat fmt = FileFormat.Detect(fs, files[i]); | |
var subNode = scene.RootNode.CreateChildNode(files[i]); | |
i++; | |
try | |
{ | |
Scene subScene = new Scene(); | |
var opt = fmt.CreateLoadOptions(); | |
subScene.Open(fs, opt); | |
subNode.Entity = PolygonModifier.MergeMesh(subScene); | |
MoveTo(subScene.RootNode, subNode); | |
} | |
catch (Exception) | |
{ | |
} | |
} | |
var reviewFile = "result.usdz"; | |
var usdz = new UsdSaveOptions(FileFormat.USDZ) | |
{ | |
PrimitiveToMesh = false, | |
ExportMetaData = true | |
}; | |
scene.Save(reviewFile, usdz); | |
//Process usdz files and save them in the format you want | |
var scene2 = new Scene(); | |
var physicalFile = reviewFile; | |
using var fs2 = new FileStream(physicalFile, FileMode.Open, FileAccess.Read); | |
var fmt2 = FileFormat.Detect(fs2, "result"); | |
var subScene2 = new Scene(); | |
var opt2 = fmt2.CreateLoadOptions(); | |
subScene2.Open(fs2, opt2); | |
var newNode = scene2.RootNode.CreateChildNode(""); | |
double[] value = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; | |
newNode.Transform.TransformMatrix = new Matrix4(value); | |
MoveTo(subScene2.RootNode, newNode); | |
var output = "merger.fbx"; | |
scene2.Save(output, FileFormat.FBX7400ASCII); | |
//MoveTo class for call processing | |
public static void MoveTo(Node subScene, Node parent) | |
{ | |
while (subScene.ChildNodes.Count > 0) | |
{ | |
var node = subScene.ChildNodes[0]; | |
subScene.ChildNodes.RemoveAt(0); | |
parent.AddChildNode(node); | |
} | |
} |
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 the base shape to be extruded | |
var shape = Shape.FromControlPoints( | |
new Vector3(1, 1, 0), | |
new Vector3(-1, 1, 0), | |
new Vector3(-1, -1, 0), | |
new Vector3(1, -1, 0) | |
); | |
// Perform Linear extrusion by passing a 2D shape as input and extend the shape in the 3rd dimension | |
var extrusion = new LinearExtrusion(shape, 10) { Slices = 100, Center = true, Twist = 360, TwistOffset = new Vector3(10, 0, 0) }; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create a child node by passing extrusion | |
scene.RootNode.CreateChildNode(extrusion); | |
// Save 3D scene | |
scene.Save(MyDir + "LinearExtrusion.obj", 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 source file that needs to generate the point cloud | |
string file = "template.3ds";//If it is other 3D file format, the suffix needs to be changed to its 3D file type | |
//create an instance of Scene | |
Scene scene = new Scene(file); | |
//Get pointcloud object of Aspose.3D and generate a point cloud | |
var pc = new PointCloud(); | |
scene.RootNode.Accept((Node n) => | |
{ | |
if (n.Entities.Count > 0) | |
{ | |
var transform = n.EvaluateGlobalTransform(true); | |
foreach (var entity in n.Entities) | |
{ | |
if (entity is Geometry g) | |
{ | |
Merge(pc, g, transform); | |
} | |
else if (entity is IMeshConvertible mc) | |
{ | |
var mesh = mc.ToMesh(); | |
Merge(pc, mesh, transform); | |
} | |
} | |
} | |
return true; | |
}); | |
//Merge method for generating point clouds | |
private void Merge(PointCloud pc, Geometry g, Matrix4 transform) | |
{ | |
var tmp = PointCloud.FromGeometry(g, 10); | |
for (int i = 0; i < tmp.ControlPoints.Count; i++) | |
{ | |
var pt = transform * tmp.ControlPoints[i]; | |
pc.ControlPoints.Add(pt); | |
} | |
} | |
// create an instance of newScene | |
var newScene = new Scene(pc); | |
//When saving, you need to create a SaveOptions object of the save format | |
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".ply"; | |
PlySaveOptions ply = new PlySaveOptions(); | |
ply.PointCloud = true; | |
newScene.Save(output, ply); |
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 | |
// Load an existing 3D file | |
Scene scene = new Scene(RunExamples.GetDataFilePath("document.fbx")); | |
// Triangulate a scene | |
PolygonModifier.Triangulate(scene); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("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 | |
Scene scene = new Scene(); | |
//since all primitive entities in Aspose.3D will have builtin UV generation | |
//here we manually remove it to assume we have a mesh without UV data | |
var mesh = (new Box()).ToMesh(); | |
mesh.VertexElements.Remove(mesh.GetElement(VertexElementType.UV)); | |
//then we can manually generate UV for it | |
var uv = PolygonModifier.GenerateUV(mesh); | |
//generated UV data is not associated with the mesh, we should manually do this | |
mesh.AddElement(uv); | |
//put it to the scene | |
var node = scene.RootNode.CreateChildNode(mesh); | |
//then save it | |
scene.Save(RunExamples.GetOutputFilePath("Aspose.obj"), 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 | |
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, RunExamples.GetOutputFilePath("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 | |
// Load scene from file | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetDataDir() + "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, RunExamples.GetOutputFilePath("Render3DModelImageFromCamera.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. | |
//load the scene | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath("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 | |
//load the scene | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath("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 | |
//load the scene | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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 = RunExamples.GetOutputFilePath("right.png"), | |
Left = RunExamples.GetOutputFilePath("left.png"), | |
Back = RunExamples.GetOutputFilePath("back.png"), | |
Front = RunExamples.GetOutputFilePath("front.png"), | |
Bottom = RunExamples.GetOutputFilePath("bottom.png"), | |
Top = RunExamples.GetOutputFilePath("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() | |
{ | |
//load the scene | |
Scene scene = new Scene(RunExamples.GetDataFilePath("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(RunExamples.GetOutputFilePath("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(); | |
// Initialize the base shape to be extruded | |
var shape = Shape.FromControlPoints( | |
new Vector3(1, 1, 0), | |
new Vector3(-1, 1, 0), | |
new Vector3(-1, -1, 0), | |
new Vector3(1, -1, 0) | |
); | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(5, 0, 0); | |
// Slices parameter defines the number of intermediate points along the path of the extrusion | |
// Perform linear extrusion on left node using slices property | |
left.CreateChildNode(new LinearExtrusion(shape, 2) { Slices = 2 }); | |
// Perform linear extrusion on right node using slices property | |
right.CreateChildNode(new LinearExtrusion(shape, 2) { Slices = 10 }); | |
// Save 3D scene | |
scene.Save(MyDir + "SlicesInLinearExtrusion.obj", 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
var tex = new TextureData(128, 128, PixelFormat.A8R8G8B8); | |
using (var mapping = tex.MapPixels(PixelMapMode.WriteOnly)) | |
{ | |
var pixels = mapping.Data; | |
var p = 0; | |
for(var y = 0; y < 128; y++) | |
{ | |
for (var x = 0; x < 128; x++) | |
{ | |
pixels[p + 0] = 255;//alpha | |
pixels[p + 1] = 255;//red | |
pixels[p + 2] = 0;//green | |
pixels[p + 3] = 0;//blue | |
p += 4;//next pixel | |
} | |
} | |
} | |
tex.Save("red.png");//save to png file(Need codec registered) |
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
var tex = TextureData.FromFile("test.png"); | |
tex.TransformPixelFormat(PixelFormat.G8);//now the texture data only contains green channel in pixel. |
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 the base shape to be extruded | |
var shape = Shape.FromControlPoints( | |
new Vector3(1, 1, 0), | |
new Vector3(-1, 1, 0), | |
new Vector3(-1, -1, 0), | |
new Vector3(1, -1, 0) | |
); | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create rifht node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(5, 0, 0); | |
// Twist property defines the degree of the rotation while extruding the shape | |
// Perform linear extrusion on left node using twist and slices property | |
left.CreateChildNode(new LinearExtrusion(shape, 10) { Twist = 0, Slices = 100 }); | |
// Perform linear extrusion on right node using twist and slices property | |
right.CreateChildNode(new LinearExtrusion(shape, 10) { Twist = 90, Slices = 100 }); | |
// Save 3D scene | |
scene.Save(MyDir + "TwistInLinearExtrusion.obj", 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(); | |
// Initialize the base shape to be extruded | |
var shape = Shape.FromControlPoints( | |
new Vector3(1, 1, 0), | |
new Vector3(-1, 1, 0), | |
new Vector3(-1, -1, 0), | |
new Vector3(1, -1, 0) | |
); | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(8, 0, 0); | |
// TwistOffset property is the translate offset while rotating the extrusion. | |
// Perform linear extrusion on left node using twist and slices property | |
left.CreateChildNode(new LinearExtrusion(shape, 10) { Twist = 360, Slices = 100 }); | |
// Perform linear extrusion on right node using twist, twist offset and slices property | |
right.CreateChildNode(new LinearExtrusion(shape, 10) { Twist = 360, Slices = 100, TwistOffset = new Vector3(3, 0, 0) }); | |
// Save 3D scene | |
scene.Save(MyDir + "TwistOffsetInLinearExtrusion.obj", 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 | |
//Source files that need to be watermarked for verification | |
string file = "template.3ds";//If it is other 3D file format, the suffix needs to be changed to its 3D file type | |
// create an instance of Scene | |
Scene scene = new Scene(file); | |
string text = null; | |
//Add password to verify watermark by DecodeWatermark method | |
try | |
{ | |
scene.RootNode.Accept((Node node) => | |
{ | |
var mesh = node.GetEntity<Mesh>(); | |
if (mesh != null) | |
{ | |
text = Watermark.DecodeWatermark(mesh, "1234"); | |
if (text != null) | |
return false; | |
} | |
return true; | |
}); | |
} | |
catch (UnauthorizedAccessException) | |
{ | |
return "Password error"; | |
} | |
//Returns null if this file has no watermark,If there is a watermark, return the watermark content | |
return text; |
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 | |
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".html"; | |
// load 3DS scene via an instance of Scene | |
var scene = new ThreeD.Scene("template.3ds"); | |
// create an object of Html5SaveOptions and set properties for formatting | |
var options = new ThreeD.Formats.Html5SaveOptions() | |
{ | |
// turn off the grid | |
ShowGrid = false, | |
// turn off the user interface | |
ShowUI = false | |
}; | |
// save 3D scene as HTML5 | |
scene.Save(output, options); | |
// load resultant HTML in default browser | |
System.Diagnostics.Process.Start(output); |
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
var scene = Scene.FromFile("test.fbx"); | |
var visitedTextures = new HashSet<TextureBase>(); | |
//Visit all nodes | |
scene.RootNode.Accept((Node node) => { | |
//Check all materials associated with the nodes | |
foreach(var mat in node.Materials) | |
{ | |
//Check all textures associated with the materials | |
foreach (var textureSlot in mat) | |
{ | |
//skip invalid texture or visited textures | |
if (textureSlot.Texture == null || visitedTextures.Contains(textureSlot.Texture)) | |
continue; | |
visitedTextures.Add(textureSlot.Texture); | |
if(textureSlot.Texture is Texture tex) | |
{ | |
if (tex.Content != null)//you can access raw bytes of the embeded textures in tex.Content | |
{ | |
//it's embedded texture | |
Console.WriteLine($"Embedded textures with {tex.Content.Length} bytes found"); | |
} | |
else if(string.IsNullOrEmpty(tex.FileName)) | |
{ | |
var fileInfo = new FileInfo(tex.FileName); | |
if(fileInfo.Exists)//it's external texture | |
{ | |
Console.WriteLine($"External textures with {fileInfo.Length} bytes found"); | |
} | |
} | |
} | |
} | |
} | |
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 | |
//create a 3D file for testing | |
new Scene(new Cylinder()).Save("watermark-test.obj"); | |
//--------Encode a watermark--------- | |
//Load mesh from 3D file | |
var scene = Scene.FromFile("watermark-test.obj"); | |
var mesh = (Mesh)scene.RootNode.ChildNodes[0].Entity; | |
//apply a blindwatermark to mesh | |
var watermarkedMesh = Watermark.EncodeWatermark(mesh, "Aspose.3D", "password"); | |
//save it to scene for later decoding | |
new Scene(watermarkedMesh).Save("watermark-test.obj"); | |
//--------Decode watermark--------- | |
//decode the watermark from 3D file: | |
scene = Scene.FromFile("watermark-test.obj"); | |
mesh = (Mesh)scene.RootNode.ChildNodes[0].Entity; | |
var watermark = Watermark.DecodeWatermark(mesh, "password"); | |
Console.WriteLine("Watermark:" + watermark); |
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 the base profile to be extruded | |
var profile = new RectangleShape() | |
{ | |
RoundingRadius = 0.3 | |
}; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(5, 0, 0); | |
// If Center property is true, the extrusion range is from -Height/2 to Height/2, otherwise the extrusion is from 0 to Height | |
// Perform linear extrusion on left node using center and slices property | |
left.CreateChildNode(new LinearExtrusion(profile, 2) { Center = false, Slices = 3 }); | |
// Set ground plane for reference | |
left.CreateChildNode(new Box(0.01, 3, 3)); | |
// Perform linear extrusion on left node using center and slices property | |
right.CreateChildNode(new LinearExtrusion(profile, 2) { Center = true, Slices = 3 }); | |
// Set ground plane for reference | |
right.CreateChildNode(new Box(0.01, 3, 3)); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("CenterInLinearExtrusion.obj"), 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 | |
// Initialize the base profile to be extruded | |
var profile = new RectangleShape() | |
{ | |
RoundingRadius = 0.3 | |
}; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(8, 0, 0); | |
// Direction property defines the direction of the extrusion. | |
// Perform linear extrusion on left node using twist and slices property | |
left.CreateChildNode(new LinearExtrusion(profile, 10) { Twist = 360, Slices = 100 }); | |
// Perform linear extrusion on right node using twist, slices, and direction property | |
right.CreateChildNode(new LinearExtrusion(profile, 10) { Twist = 360, Slices = 100, Direction = new Vector3(0.3, 0.2, 1) }); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("DirectionInLinearExtrusion.obj"), 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 | |
// Initialize the base profile to be extruded | |
var profile = new RectangleShape() | |
{ | |
RoundingRadius = 0.3 | |
}; | |
// Perform Linear extrusion by passing a 2D profile as input and extend the shape in the 3rd dimension | |
var extrusion = new LinearExtrusion(profile, 10) { Slices = 100, Center = true, Twist = 360, TwistOffset = new Vector3(10, 0, 0) }; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create a child node by passing extrusion | |
scene.RootNode.CreateChildNode(extrusion); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath( "LinearExtrusion.obj"), 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 | |
// Initialize the base profile to be extruded | |
var profile = new RectangleShape() | |
{ | |
RoundingRadius = 0.3 | |
}; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(15, 0, 0); | |
// Slices parameter defines the number of intermediate points along the path of the extrusion | |
// Perform linear extrusion on left node using slices property | |
left.CreateChildNode(new LinearExtrusion(profile, 2) { Slices = 2 }); | |
// Perform linear extrusion on right node using slices property | |
right.CreateChildNode(new LinearExtrusion(profile, 2) { Slices = 10 }); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("SlicesInLinearExtrusion.obj"), 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 | |
// Load font from bytes | |
var font = FontFile.Parse(File.ReadAllBytes(@"test-font.otf")); | |
// Create a Text profile | |
var text = new Text() | |
{ | |
Font = font, | |
Content = "Hello World", | |
FontSize = 10 | |
}; | |
// Extrude the profile to give it a thickness. | |
var linear = new LinearExtrusion(text, 10).ToMesh(); | |
// create a scene from the mesh and save it to stl file | |
var scene = new Scene(linear); | |
scene.Save(@"test.stl"); |
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 the base profile to be extruded | |
var profile = new RectangleShape() | |
{ | |
RoundingRadius = 0.3 | |
}; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create rifht node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(15, 0, 0); | |
// Twist property defines the degree of the rotation while extruding the profile | |
// Perform linear extrusion on left node using twist and slices property | |
left.CreateChildNode(new LinearExtrusion(profile, 10) { Twist = 0, Slices = 100 }); | |
// Perform linear extrusion on right node using twist and slices property | |
right.CreateChildNode(new LinearExtrusion(profile, 10) { Twist = 90, Slices = 100 }); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("TwistInLinearExtrusion.obj"), 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 | |
// Initialize the base profile to be extruded | |
var profile = new RectangleShape() | |
{ | |
RoundingRadius = 0.3 | |
}; | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create left node | |
var left = scene.RootNode.CreateChildNode(); | |
// Create right node | |
var right = scene.RootNode.CreateChildNode(); | |
left.Transform.Translation = new Vector3(18, 0, 0); | |
// TwistOffset property is the translate offset while rotating the extrusion. | |
// Perform linear extrusion on left node using twist and slices property | |
left.CreateChildNode(new LinearExtrusion(profile, 10) { Twist = 360, Slices = 100 }); | |
// Perform linear extrusion on right node using twist, twist offset and slices property | |
right.CreateChildNode(new LinearExtrusion(profile, 10) { Twist = 360, Slices = 100, TwistOffset = new Vector3(3, 0, 0) }); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("TwistOffsetInLinearExtrusion.obj"), 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 | |
// Load an existing 3D file | |
Scene scene = new Scene(RunExamples.GetDataFilePath("document.fbx")); | |
// Triangulate a scene | |
PolygonModifier.BuildTangentBinormal(scene); | |
// Save 3D scene | |
scene.Save(RunExamples.GetOutputFilePath("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 output = RunExamples.GetOutputFilePath("SphereToTriangleMeshCustomMemoryLayoutScene.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.Save(output, 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 " + output); | |
} |
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
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET | |
Mesh mesh = new Mesh(); | |
mesh.CreatePolygon(new int[] { 0, 1, 2 }); //The old CreatePolygon needs to create a temporary array for holding the face indices | |
mesh.CreatePolygon(0, 1, 2); //The new overloads doesn't need extra allocation, and it's optimized internally. | |
//Or You can create a polygon using 4 vertices(quad) | |
//mesh.CreatePolygon(0, 1, 2, 3); |
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 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(RunExamples.GetOutputFilePath("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 | |
// Load a 3ds file, 3ds file doesn't have normal data, but it has smoothing group | |
Scene s = new Scene(RunExamples.GetDataFilePath("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 input = RunExamples.GetDataFilePath("test.fbx"); | |
// Load a 3D file | |
Scene scene = new Scene(input); | |
// Split all meshes | |
PolygonModifier.SplitMesh(scene, SplitMeshPolicy.CloneData); | |
// Save file | |
var output = RunExamples.GetOutputFilePath("test-splitted.fbx"); | |
scene.Save(output, 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 | |
// Create a Scene | |
Scene scene = new Scene(); | |
// Set Sphere Radius (Using Radius property you can get or set radius of Sphere) | |
scene.RootNode.CreateChildNode(new Sphere() { Radius = 10 }); | |
// Save scene | |
scene.Save(RunExamples.GetDataDir() +"sphere.obj", 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 | |
//Create a scene for testing | |
Scene s = new Scene(); | |
var a = s.RootNode.CreateChildNode("a"); | |
a.CreateChildNode("a1"); | |
a.CreateChildNode("a2"); | |
s.RootNode.CreateChildNode("b"); | |
var c = s.RootNode.CreateChildNode("c"); | |
c.CreateChildNode("c1").AddEntity(new Camera("cam")); | |
c.CreateChildNode("c2").AddEntity(new Light("light")); | |
/*The hierarchy of the scene looks like: | |
- Root | |
- a | |
- a1 | |
- a2 | |
- b | |
- c | |
- c1 | |
- cam | |
- c2 | |
- light | |
*/ | |
//select objects that has type Camera or name is 'light' whatever it's located. | |
var objects = s.RootNode.SelectObjects("//*[(@Type = 'Camera') or (@Name = 'light')]"); | |
//Select single camera object under the child nodes of node named 'c' under the root node | |
var c1 = s.RootNode.SelectSingleObject("/c/*/<Camera>"); | |
// Select node named 'a1' under the root node, even if the 'a1' is not a directly child node of the | |
var obj = s.RootNode.SelectSingleObject("a1"); | |
//Select the node itself, since the '/' is selected directly on the root node, so the root node is selected. | |
obj = s.RootNode.SelectSingleObject("/"); |
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 Scene | |
Scene scene = new Scene(); | |
// Create a cylinder | |
var fan = new Cylinder(2, 2, 10, 20, 1, false); | |
// Set GenerateGanCylinder to true | |
fan.GenerateFanCylinder = true; | |
// Set ThetaLength | |
fan.ThetaLength = MathUtils.ToRadian(270); | |
// Create ChildNode | |
scene.RootNode.CreateChildNode(fan).Transform.Translation = new Vector3(10, 0, 0); | |
// Create a cylinder without a fan | |
var nonfan = new Cylinder(2, 2, 10, 20, 1, false); | |
// Set GenerateGanCylinder to false | |
nonfan.GenerateFanCylinder = false; | |
// Set ThetaLengeth | |
nonfan.ThetaLength = MathUtils.ToRadian(270); | |
// Create ChildNode | |
scene.RootNode.CreateChildNode(nonfan); | |
// Save scene | |
scene.Save(RunExamples.GetDataDir() + "CreateFanCylinder.obj", 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 | |
// Create a scene | |
Scene scene = new Scene(); | |
// Initialize cylinder | |
var cylinder1 = new Cylinder(2, 2, 10, 20, 1, false); | |
// Set OffsetTop | |
cylinder1.OffsetTop = new Vector3(5, 3, 0); | |
// Create ChildNode | |
scene.RootNode.CreateChildNode(cylinder1).Transform.Translation = new Vector3(10, 0, 0); | |
// Intialze second cylinder without customized OffsetTop | |
var cylinder2 = new Cylinder(2, 2, 10, 20, 1, false); | |
// Create ChildNode | |
scene.RootNode.CreateChildNode(cylinder2); | |
// Save | |
scene.Save(RunExamples.GetDataDir()+ "CustomizedOffsetTopCylinder.obj", 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 | |
// Create a scene | |
Scene scene = new Scene(); | |
// Create cylinder 1 | |
var cylinder1 = new Cylinder(2, 2, 10, 20, 1, false); | |
// Customized shear bottom for cylinder 1 | |
cylinder1.ShearBottom = new Vector2(0, 0.83);// shear 47.5deg in xy plane(z-axis) | |
// Add cylinder 1 to the scene | |
scene.RootNode.CreateChildNode(cylinder1).Transform.Translation = new Vector3(10, 0, 0); | |
// Create cylinder 2 | |
var cylinder2 = new Cylinder(2, 2, 10, 20, 1, false); | |
// Add cylinder to without a ShearBottom to the scene | |
scene.RootNode.CreateChildNode(cylinder2); | |
// Save scene | |
scene.Save(RunExamples.GetDataDir() + "CustomizedShearBottomCylinder.obj", 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 | |
var pointCloud = (PointCloud)FileFormat.Draco.Decode(RunExamples.GetDataDir() + "point_cloud_no_qp.drc"); |
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 | |
var geom = FileFormat.PLY.Decode(RunExamples.GetDataDir() + "sphere.ply"); |
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 | |
var geom = FileFormat.PLY.Decode(RunExamples.GetDataDir() + "sphere.ply"); |
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 | |
FileFormat.Draco.Encode(new Sphere(), RunExamples.GetDataDir() + "sphere.drc"); |
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 | |
FileFormat.PLY.Encode(new Sphere(), "sphere.ply"); |
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 | |
FileFormat.Draco.Encode(new Sphere(), RunExamples.GetDataDir() + "sphere.drc", new DracoSaveOptions() { PointCloud = 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 | |
var scene = new Scene(new Sphere()); | |
scene.Save(RunExamples.GetDataDir() + "Export3DSceneAsPointCloud.obj", new ObjSaveOptions() { PointCloud = 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 | |
FileFormat.PLY.Encode(new Sphere(), RunExamples.GetDataDir() + "sphere.ply", new PlySaveOptions() { PointCloud = 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 | |
string text = null; | |
try | |
{ | |
scene.RootNode.Accept((Node node) => | |
{ | |
var mesh = node.GetEntity<Mesh>(); | |
if (mesh != null) | |
{ | |
text = Watermark.DecodeWatermark(mesh, "1234"); | |
if (text != null) | |
return false; | |
} | |
return true; | |
}); | |
} | |
catch (UnauthorizedAccessException) | |
{ | |
return "Password error"; | |
} | |
return text; |
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 Scene | |
Scene scene = new Scene(); | |
// Open Virtual Reality Modeling Language (VRML) file format | |
scene.Open(RunExamples.GetDataDir() + "test.wrl"); | |
// Work with VRML file format... | |
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 | |
string file = "template.3ds"; | |
Scene scene = new Scene(file); |
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 | |
var numMeshes = 0; | |
scene.RootNode.Accept((Node node) => | |
{ | |
var mesh = node.GetEntity<Mesh>(); | |
if (mesh != null) | |
{ | |
numMeshes++; | |
mesh = Watermark.EncodeWatermark(mesh, "HelloWorld", "1234"); | |
if (mesh != null) | |
{ | |
node.Entity = mesh; | |
} | |
} | |
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 | |
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".fbx"; | |
scene.Save(output, 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 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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using Aspose.ThreeD.Utilities; | |
using Aspose.ThreeD.Render; | |
using SixLabors.ImageSharp; | |
using SixLabors.ImageSharp.PixelFormats; | |
using System.Runtime.InteropServices; | |
using SixLabors.ImageSharp.Formats; | |
namespace Aspose.ThreeD | |
{ | |
/// <summary> | |
/// Uses ImageSharp for encoding/decoding textures for Aspose.3D textures. | |
/// </summary> | |
public class ImageSharpCodec : ITextureCodec, ITextureDecoder | |
{ | |
class Encoder<T> : ITextureEncoder where T:IImageEncoder, new() | |
{ | |
public string FileExtension { get; } | |
public Encoder(string ext) | |
{ | |
FileExtension = ext; | |
} | |
public void Encode(TextureData texture, Stream stream) | |
{ | |
var bmp = ToBitmap(texture); | |
var encoder = new T(); | |
bmp.Save(stream, encoder); | |
} | |
} | |
/// <summary> | |
/// Convert TextureData to Image | |
/// </summary> | |
/// <param name="td"></param> | |
/// <returns></returns> | |
public unsafe static Image<Bgra32> ToBitmap(TextureData td) | |
{ | |
using(var map = td.MapPixels(PixelMapMode.ReadOnly, PixelFormat.A8R8G8B8)) | |
{ | |
var ret = new Image<Bgra32>(td.Width, td.Height); | |
ret.ProcessPixelRows(accessor => | |
{ | |
fixed (byte* p = map.Data) | |
{ | |
for (int y = 0; y < ret.Height; y++) | |
{ | |
var offset = y * map.Stride; | |
var src = new Span<Bgra32>(p + offset, map.Stride); | |
var dst = accessor.GetRowSpan(y); | |
src.CopyTo(dst); | |
} | |
} | |
}); | |
return ret; | |
} | |
} | |
/// <summary> | |
/// Convert Image to TextureData | |
/// </summary> | |
/// <param name="img"></param> | |
/// <param name="reverseY"></param> | |
/// <returns></returns> | |
public unsafe static TextureData ToTextureData(Image<Bgra32> img, bool reverseY) | |
{ | |
var ret = new TextureData(img.Width, img.Height, PixelFormat.A8R8G8B8); | |
using (var map = ret.MapPixels(PixelMapMode.WriteOnly)) | |
{ | |
img.ProcessPixelRows(accessor => | |
{ | |
fixed (byte* src = map.Data) | |
{ | |
for (int y = 0; y < img.Height; y++) | |
{ | |
var offset = 0; | |
if (reverseY) | |
offset = (map.Height - y - 1) * map.Stride; | |
else | |
offset = y * map.Stride; | |
var dst = new Span<Bgra32>(src + offset, map.Stride); | |
var row = accessor.GetRowSpan(y); | |
row.CopyTo(dst); | |
} | |
} | |
}); | |
} | |
return ret; | |
} | |
/// <summary> | |
/// Decode texture from stream, return null if failed to decode. | |
/// </summary> | |
/// <param name="stream">Texture data source stream</param> | |
/// <param name="reverseY">Flip the texture</param> | |
/// <returns>Decoded texture data or null if not supported.</returns> | |
public unsafe TextureData Decode(Stream stream, bool reverseY) | |
{ | |
using (var img = Image.Load<Bgra32>(stream)) | |
{ | |
return ToTextureData(img, reverseY); | |
} | |
} | |
/// <summary> | |
/// Gets supported texture decoders. | |
/// </summary> | |
/// <returns></returns> | |
public ITextureDecoder[] GetDecoders() | |
{ | |
return new ITextureDecoder[] { this }; | |
} | |
/// <summary> | |
/// Gets supported texture encoders. | |
/// </summary> | |
/// <returns></returns> | |
public ITextureEncoder[] GetEncoders() | |
{ | |
List<ITextureEncoder> ret = new List<ITextureEncoder>(); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Bmp.BmpEncoder>("bmp")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Png.PngEncoder>("png")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder>("jpg")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder>("jpeg")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Pbm.PbmEncoder>("pbm")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Gif.GifEncoder>("gif")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Tga.TgaEncoder>("tga")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Tiff.TiffEncoder>("tif")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Tiff.TiffEncoder>("tiff")); | |
ret.Add(new Encoder<SixLabors.ImageSharp.Formats.Webp.WebpEncoder>("webp")); | |
return ret.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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using Aspose.ThreeD.Render; | |
using System.Runtime.InteropServices; | |
using SkiaSharp; | |
namespace Aspose.ThreeD | |
{ | |
/// <summary> | |
/// Uses SkiaSharp for encoding/decoding textures for Aspose.3D textures. | |
/// </summary> | |
public class SkiaSharpCodec : ITextureCodec, ITextureDecoder | |
{ | |
class SkiaSharpEncoder : ITextureEncoder | |
{ | |
SKEncodedImageFormat format; | |
public string FileExtension { get; } | |
public SkiaSharpEncoder(string ext, SKEncodedImageFormat format) | |
{ | |
FileExtension = ext; | |
this.format = format; | |
} | |
public void Encode(TextureData texture, Stream stream) | |
{ | |
var bmp = ToBitmap(texture); | |
using (var tmp = bmp.Encode(format, 100).AsStream()) | |
{ | |
tmp.CopyTo(stream); | |
} | |
} | |
} | |
/// <summary> | |
/// Convert TextureData to Image | |
/// </summary> | |
/// <param name="td"></param> | |
/// <returns></returns> | |
public unsafe static SKBitmap ToBitmap(TextureData td) | |
{ | |
var info = new SKImageInfo(td.Width, td.Height, SKColorType.Rgba8888); | |
var ret = new SKBitmap(info); | |
var pixels = new SKColor[td.Width * td.Height]; | |
var pout = 0; | |
using (var map = td.MapPixels(PixelMapMode.ReadOnly, PixelFormat.A8R8G8B8)) | |
{ | |
var bytes = map.Data; | |
for (int y = 0; y < map.Height; y++) | |
{ | |
int p = map.Stride * y; | |
for (int x = 0; x < map.Width; x++, p += 4) | |
{ | |
byte a = bytes[p+0]; | |
byte r = bytes[p+1]; | |
byte g = bytes[p+2]; | |
byte b = bytes[p+3]; | |
pixels[pout++] = new SKColor(r, g, b, a); | |
} | |
} | |
} | |
ret.Pixels = pixels; | |
return ret; | |
} | |
/// <summary> | |
/// Convert Image to TextureData | |
/// </summary> | |
/// <param name="img"></param> | |
/// <param name="reverseY"></param> | |
/// <returns></returns> | |
public unsafe static TextureData ToTextureData(SKBitmap img, bool reverseY) | |
{ | |
var ret = new TextureData(img.Width, img.Height, PixelFormat.A8R8G8B8); | |
if (img.ColorType == SKColorType.Rgba8888) | |
CopyTo(img, ret, reverseY); | |
else | |
{ | |
using (var tmp = new SKBitmap(img.Width, img.Height, SKColorType.Bgra8888, SKAlphaType.Opaque)) | |
{ | |
using (var canvas = new SKCanvas(tmp)) | |
{ | |
canvas.DrawBitmap(img, SKPoint.Empty); | |
} | |
CopyTo(tmp, ret, reverseY); | |
} | |
} | |
return ret; | |
} | |
private unsafe static void CopyTo(SKBitmap bitmap, TextureData td, bool reverseY) | |
{ | |
var src = bitmap.GetPixels(); | |
using (var map = td.MapPixels(PixelMapMode.WriteOnly, PixelFormat.A8R8G8B8)) | |
{ | |
var stride = 4 * bitmap.Width; | |
var rows = map.Height; | |
for (int y = 0; y < rows; y++) | |
{ | |
var sRow = src + stride * y; | |
var dRow = reverseY ? (rows - 1 - y) * stride : y * stride; | |
Marshal.Copy(sRow, map.Data, dRow, stride); | |
} | |
} | |
} | |
/// <summary> | |
/// Decode texture from stream, return null if failed to decode. | |
/// </summary> | |
/// <param name="stream">Texture data source stream</param> | |
/// <param name="reverseY">Flip the texture</param> | |
/// <returns>Decoded texture data or null if not supported.</returns> | |
public unsafe TextureData Decode(Stream stream, bool reverseY) | |
{ | |
using (var bmp = SKBitmap.Decode(stream)) | |
{ | |
return ToTextureData(bmp, reverseY); | |
} | |
} | |
/// <summary> | |
/// Gets supported texture decoders. | |
/// </summary> | |
/// <returns></returns> | |
public ITextureDecoder[] GetDecoders() | |
{ | |
return new ITextureDecoder[] { this }; | |
} | |
/// <summary> | |
/// Gets supported texture encoders. | |
/// </summary> | |
/// <returns></returns> | |
public ITextureEncoder[] GetEncoders() | |
{ | |
List<ITextureEncoder> ret = new List<ITextureEncoder>(); | |
ret.Add(new SkiaSharpEncoder("bmp", SKEncodedImageFormat.Bmp)); | |
ret.Add(new SkiaSharpEncoder("dng", SKEncodedImageFormat.Dng)); | |
ret.Add(new SkiaSharpEncoder("webp", SKEncodedImageFormat.Webp)); | |
ret.Add(new SkiaSharpEncoder("avif", SKEncodedImageFormat.Avif)); | |
ret.Add(new SkiaSharpEncoder("heif", SKEncodedImageFormat.Heif)); | |
ret.Add(new SkiaSharpEncoder("png", SKEncodedImageFormat.Png)); | |
ret.Add(new SkiaSharpEncoder("jpg", SKEncodedImageFormat.Jpeg)); | |
ret.Add(new SkiaSharpEncoder("jpeg", SKEncodedImageFormat.Jpeg)); | |
ret.Add(new SkiaSharpEncoder("astc", SKEncodedImageFormat.Astc)); | |
ret.Add(new SkiaSharpEncoder("ktx", SKEncodedImageFormat.Ktx)); | |
ret.Add(new SkiaSharpEncoder("gif", SKEncodedImageFormat.Gif)); | |
ret.Add(new SkiaSharpEncoder("ico", SKEncodedImageFormat.Ico)); | |
ret.Add(new SkiaSharpEncoder("pkm", SKEncodedImageFormat.Pkm)); | |
ret.Add(new SkiaSharpEncoder("wbmp", SKEncodedImageFormat.Wbmp)); | |
return ret.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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
using Aspose.ThreeD.Render; | |
using System.Runtime.InteropServices; | |
namespace Aspose.ThreeD | |
{ | |
/// <summary> | |
/// Uses System.Drawing for encoding/decoding textures for Aspose.3D textures. | |
/// </summary> | |
public class GdiPlusCodec : ITextureCodec, ITextureDecoder | |
{ | |
class GdiPlusEncoder : ITextureEncoder | |
{ | |
public string FileExtension { get; } | |
private ImageCodecInfo encoder; | |
public GdiPlusEncoder(ImageCodecInfo encoder, string ext) | |
{ | |
this.encoder = encoder; | |
FileExtension = ext; | |
} | |
public void Encode(TextureData texture, Stream stream) | |
{ | |
var bmp = ToBitmap(texture); | |
bmp.Save(stream, encoder, null); | |
} | |
} | |
/// <summary> | |
/// Convert <see cref="TextureData"/> to <see cref="Bitmap"/> | |
/// </summary> | |
/// <param name="td"></param> | |
/// <returns></returns> | |
public static Bitmap ToBitmap(TextureData td) | |
{ | |
using (var map = td.MapPixels(PixelMapMode.ReadOnly, Render.PixelFormat.A8R8G8B8)) | |
{ | |
var ret = new Bitmap(td.Width, td.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); | |
var bits = ret.LockBits(new Rectangle(0, 0, td.Width, td.Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); | |
for (int y = 0; y < td.Height; y++) | |
{ | |
var srcOffset = y * map.Stride; | |
var destination = bits.Scan0 + y * bits.Stride; | |
Marshal.Copy(map.Data, srcOffset, destination, map.Stride); | |
} | |
ret.UnlockBits(bits); | |
return ret; | |
} | |
} | |
/// <summary> | |
/// Convert <see cref="Bitmap"/> to <see cref="TextureData"/> | |
/// </summary> | |
/// <param name="img"></param> | |
/// <param name="reverseY"></param> | |
/// <returns></returns> | |
public static TextureData ToTextureData(Bitmap img, bool reverseY) | |
{ | |
var ret = new TextureData(img.Width, img.Height, Render.PixelFormat.A8R8G8B8); | |
var bits = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); | |
using (var map = ret.MapPixels(PixelMapMode.WriteOnly)) | |
{ | |
for (int y = 0; y < map.Height; y++) | |
{ | |
IntPtr srcPtr = bits.Scan0; | |
if(reverseY) | |
srcPtr += (map.Height - y - 1) * bits.Stride; | |
else | |
srcPtr += y * bits.Stride; | |
var dstOffset = y * map.Stride; | |
Marshal.Copy(srcPtr, map.Data, dstOffset, map.Stride); | |
} | |
} | |
img.UnlockBits(bits); | |
return ret; | |
} | |
/// <summary> | |
/// Decode texture from stream, return null if failed to decode. | |
/// </summary> | |
/// <param name="stream">Texture data source stream</param> | |
/// <param name="reverseY">Flip the texture</param> | |
/// <returns>Decoded texture data or null if not supported.</returns> | |
public TextureData Decode(Stream stream, bool reverseY) | |
{ | |
using (var img = (Bitmap)Image.FromStream(stream)) | |
{ | |
var ret = ToTextureData(img, reverseY); | |
return ret; | |
} | |
} | |
/// <summary> | |
/// Gets supported texture decoders. | |
/// </summary> | |
/// <returns></returns> | |
public ITextureDecoder[] GetDecoders() | |
{ | |
return new ITextureDecoder[] { this }; | |
} | |
/// <summary> | |
/// Gets supported texture encoders. | |
/// </summary> | |
/// <returns></returns> | |
public ITextureEncoder[] GetEncoders() | |
{ | |
List<ITextureEncoder> ret = new List<ITextureEncoder>(); | |
foreach (var encoder in ImageCodecInfo.GetImageEncoders()) | |
{ | |
if (encoder.FilenameExtension == null) | |
continue; | |
var exts = encoder.FilenameExtension.Split(';'); | |
foreach(var fileExt in exts) | |
{ | |
var ext = fileExt; | |
int p = ext.IndexOf('.'); | |
if (p != -1) | |
ext = ext.Substring(p + 1); | |
ret.Add(new GdiPlusEncoder(encoder, ext.ToLowerInvariant())); | |
} | |
} | |
return ret.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 | |
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