public void Invalidate() { MeshGroup = new MeshGroup { MeshDescriptors = MeshLoader.FromBBS(_model).MeshDescriptors, Textures = _kingdomTextures }; }
public DeleteUndoCommand(View3DWidget view3DWidget, int deletedIndex) { this.view3DWidget = view3DWidget; this.deletedIndex = deletedIndex; meshGroupThatWasDeleted = view3DWidget.MeshGroups[deletedIndex]; deletedTransform = view3DWidget.MeshGroupTransforms[deletedIndex]; deletedPlatingData = view3DWidget.MeshGroupExtraData[deletedIndex]; }
public static string[] GetStlFileLocations(string fileToSlice) { int extruderCount = ActiveSliceSettings.Instance.ExtruderCount; switch (Path.GetExtension(fileToSlice).ToUpper()) { case ".STL": case ".GCODE": return(new string[] { fileToSlice }); case ".AMF": List <MeshGroup> meshGroups = MeshFileIo.Load(fileToSlice); List <MeshGroup> extruderMeshGroups = new List <MeshGroup>(); for (int extruderIndex = 0; extruderIndex < extruderCount; extruderIndex++) { extruderMeshGroups.Add(new MeshGroup()); } int maxExtruderIndex = 0; foreach (MeshGroup meshGroup in meshGroups) { foreach (Mesh mesh in meshGroup.Meshes) { MeshMaterialData material = MeshMaterialData.Get(mesh); int extruderIndex = Math.Max(0, material.MaterialIndex - 1); maxExtruderIndex = Math.Max(maxExtruderIndex, extruderIndex); if (extruderIndex >= extruderCount) { extruderMeshGroups[0].Meshes.Add(mesh); } else { extruderMeshGroups[extruderIndex].Meshes.Add(mesh); } } } List <string> extruderFilesToSlice = new List <string>(); for (int i = 0; i < extruderMeshGroups.Count; i++) { MeshGroup meshGroup = extruderMeshGroups[i]; List <int> materialsToInclude = new List <int>(); materialsToInclude.Add(i + 1); if (i == 0) { for (int j = extruderCount + 1; j < maxExtruderIndex + 2; j++) { materialsToInclude.Add(j); } } extruderFilesToSlice.Add(SaveAndGetFilenameForMaterial(meshGroup, materialsToInclude)); } return(extruderFilesToSlice.ToArray()); default: throw new NotImplementedException(); } }
public void SetCenteringForMeshGroup(MeshGroup meshGroup) { AxisAlignedBoundingBox bounds = meshGroup.GetAxisAlignedBoundingBox(); Vector3 boundsCenter = (bounds.maxXYZ + bounds.minXYZ) / 2; centering = Matrix4X4.CreateTranslation(-boundsCenter); // and move the translation back so the part does not move translation *= Matrix4X4.CreateTranslation(boundsCenter); }
private static void Convert(string fileIn, string fileOut) { MeshGroup p = FromFbx(fileIn); Pmo pmo = MeshGroup2PMO(p); using Stream stream = File.Create(fileOut); Pmo.Write(stream, pmo); stream.Close(); }
public DefaultVRControlInterpreter(string left, string right, MeshGroup grp) { hndl = new string[] { left, right }; mesh = new Mesh[2][]; tex = new Texture[2][]; texHandles = new TextureHandle[2][]; meshGroup = grp; poses = new VRClient.PoseData[2]; }
public static void MoveMeshGroupToOpenPosition(int meshGroupToMoveIndex, List <PlatingMeshGroupData> perMeshInfo, List <MeshGroup> allMeshGroups, List <ScaleRotateTranslate> meshTransforms) { MeshGroup meshGroupToMove = allMeshGroups[meshGroupToMoveIndex]; // find a place to put it that doesn't hit anything AxisAlignedBoundingBox meshToMoveBounds = meshGroupToMove.GetAxisAlignedBoundingBox(meshTransforms[meshGroupToMoveIndex].TotalTransform); // add in a few mm so that it will not be touching meshToMoveBounds.minXYZ -= new Vector3(2, 2, 0); meshToMoveBounds.maxXYZ += new Vector3(2, 2, 0); double ringDist = Math.Min(meshToMoveBounds.XSize, meshToMoveBounds.YSize); double currentDist = 0; double angle = 0; double angleIncrement = MathHelper.Tau / 64; Matrix4X4 transform; while (true) { Matrix4X4 positionTransform = Matrix4X4.CreateTranslation(currentDist, 0, 0); positionTransform *= Matrix4X4.CreateRotationZ(angle); Vector3 newPosition = Vector3.Transform(Vector3.Zero, positionTransform); transform = Matrix4X4.CreateTranslation(newPosition); AxisAlignedBoundingBox testBounds = meshToMoveBounds.NewTransformed(transform); bool foundHit = false; for (int i = 0; i < allMeshGroups.Count; i++) { MeshGroup meshToTest = allMeshGroups[i]; if (meshToTest != meshGroupToMove) { AxisAlignedBoundingBox existingMeshBounds = meshToTest.GetAxisAlignedBoundingBox(meshTransforms[i].TotalTransform); AxisAlignedBoundingBox intersection = AxisAlignedBoundingBox.Intersection(testBounds, existingMeshBounds); if (intersection.XSize > 0 && intersection.YSize > 0) { foundHit = true; break; } } } if (!foundHit) { break; } angle += angleIncrement; if (angle >= MathHelper.Tau) { angle = 0; currentDist += ringDist; } } ScaleRotateTranslate moved = meshTransforms[meshGroupToMoveIndex]; moved.translation *= transform; meshTransforms[meshGroupToMoveIndex] = moved; }
/// <summary> /// メッシュの頂点情報の更新を行う際、MainThreadが空くため、その間にBindPoseの更新も行う /// </summary> private static void UpdateVerticesAndBindPose( MeshGroup meshGroup, int vertexCount, Mesh resultMesh) { Profiler.BeginSample("MeshImporterDivided.UpdateVerticesAndBindPose"); var disposables = new List <IDisposable>(); // JobのSchedule var vertices = new NativeArray <MeshVertex>(vertexCount, Allocator.TempJob); disposables.Add(vertices); var indexOffset = 0; JobHandle interleaveVertexJob = default; foreach (var mesh in meshGroup.Meshes) { var positions = mesh.VertexBuffer.Positions.AsNativeArray <Vector3>(Allocator.TempJob); var normals = mesh.VertexBuffer.Normals.AsNativeArray <Vector3>(Allocator.TempJob); var texCoords = mesh.VertexBuffer.TexCoords.AsNativeArray <Vector2>(Allocator.TempJob); var weights = meshGroup.Skin != null ? mesh.VertexBuffer.Weights.AsNativeArray <Vector4>(Allocator.TempJob) : default; var joints = meshGroup.Skin != null ? mesh.VertexBuffer.Joints.AsNativeArray <SkinJoints>(Allocator.TempJob) : default; if (positions.IsCreated) { disposables.Add(positions); } if (normals.IsCreated) { disposables.Add(normals); } if (texCoords.IsCreated) { disposables.Add(texCoords); } if (weights.IsCreated) { disposables.Add(weights); } if (joints.IsCreated) { disposables.Add(joints); } interleaveVertexJob = new InterleaveMeshVerticesJob( new NativeSlice <MeshVertex>(vertices, indexOffset, mesh.VertexBuffer.Count), positions, normals, texCoords,
private void AddMesh(MeshGroup mesh) { if (mesh == null) { Log.Warn("AddMesh received null"); return; } _models.Add(mesh); }
//protected MCTransformFrame m_transformFrameSP; /// <summary> /// /// </summary> public MCBaseMesh(Application app) { App = app; m_pstrName = null; m_parentID = 0; m_meshGroup = null; m_pMeshTree = null; m_changeMeshGroup = 0; m_instanceID = 0; m_infoFlg = 0; }
public static MeshGroup FromGltf(this glTFMesh x, Vrm10ImportData storage) { var group = new MeshGroup(x.name); if (x.primitives.Count == 1) { var primitive = x.primitives[0]; var mesh = primitive.FromGltf(storage, x); var materialIndex = primitive.material; mesh.Submeshes.Add( new Submesh(0, mesh.IndexBuffer.Count, materialIndex)); group.Meshes.Add(mesh); } else if (!x.AllPrimitivesHasSameVertexBuffer()) { int offset = 0; foreach (var primitive in x.primitives) { var mesh = primitive.FromGltf(storage, x); var materialIndex = primitive.material; mesh.Submeshes.Add( new Submesh(offset, mesh.IndexBuffer.Count, materialIndex)); offset += mesh.IndexBuffer.Count; group.Meshes.Add(mesh); } } else { // // obsolete // // for VRM var mesh = x.SharedBufferFromGltf(storage); int offset = 0; foreach (var primitive in x.primitives) { var materialIndex = primitive.material; var count = storage.Gltf.accessors[primitive.indices].count; mesh.Submeshes.Add( new Submesh(offset, count, materialIndex)); offset += count; } group.Meshes.Add(mesh); } return(group); }
public Node(MeshGroup mesh, List <Node> Children = null) { this.mesh = mesh; if (Children == null) { this.Children = new List <Node>(); } else { this.Children = Children; } }
public MeshGroup GetMeshGroup(string aniname) { if (mapGroupAnim.ContainsKey(aniname) == false) { if (data.GetMeshGroupMaxFrame(aniname) < 0) { return(null); } mapGroupAnim[aniname] = new MeshGroup(data, aniname); } return(mapGroupAnim[aniname]); }
public void TestPathDeform() { IMesh geom = new TextMesh("Hello World"); var curve = new CubicBezierCurve(new Vec3(0, 0, 1), new Vec3(2, 0, 0), new Vec3(9, 0, 0), new Vec3(11, 0, 1)); geom = new Geometry.Modifiers.PathDeform(Vec3.I, curve, geom); MeshGroup group = new MeshGroup(); group.Add(geom); SaveGeometry("pathdeform.modifier", group); }
public void CreateGlDataForMeshes(List <MeshGroup> meshGroupsToPrepare) { for (int i = 0; i < meshGroupsToPrepare.Count; i++) { MeshGroup meshGroupToPrepare = meshGroupsToPrepare[i]; foreach (Mesh meshToPrepare in meshGroupToPrepare.Meshes) { GLMeshTrianglePlugin glMeshPlugin = GLMeshTrianglePlugin.Get(meshToPrepare); } } }
private void trackballTumbleWidget_DrawGlContent(object sender, EventArgs e) { for (int groupIndex = 0; groupIndex < MeshGroups.Count; groupIndex++) { MeshGroup meshGroupToRender = MeshGroups[groupIndex]; int part = 0; foreach (Mesh meshToRender in meshGroupToRender.Meshes) { MeshMaterialData meshData = MeshMaterialData.Get(meshToRender); RGBA_Bytes drawColor = GetMaterialColor(meshData.MaterialIndex); if (meshGroupToRender == SelectedMeshGroup) { drawColor = GetSelectedMaterialColor(meshData.MaterialIndex); } RenderMeshToGl.Render(meshToRender, drawColor, MeshGroupTransforms[groupIndex].TotalTransform, RenderType); part++; } } foreach (InteractionVolume interactionVolume in interactionVolumes) { interactionVolume.DrawGlContent(e); } // we don't want to render the bed or bulid volume before we load a model. if (MeshGroups.Count > 0 || AllowBedRenderingWhenEmpty) { if (RenderBed) { RenderMeshToGl.Render(printerBed, this.BedColor); } if (buildVolume != null && RenderBuildVolume) { RenderMeshToGl.Render(buildVolume, this.BuildVolumeColor); } if (false) // this is code to draw a small axis indicator { double big = 10; double small = 1; Mesh xAxis = PlatonicSolids.CreateCube(big, small, small); RenderMeshToGl.Render(xAxis, RGBA_Bytes.Red); Mesh yAxis = PlatonicSolids.CreateCube(small, big, small); RenderMeshToGl.Render(yAxis, RGBA_Bytes.Green); Mesh zAxis = PlatonicSolids.CreateCube(small, small, big); RenderMeshToGl.Render(zAxis, RGBA_Bytes.Blue); } } }
public static MeshGroup FromGltf(this VrmProtobuf.Mesh x, Vrm10Storage storage, List <Material> materials) { var group = new MeshGroup(x.Name); if (x.Primitives.Count == 1) { var primitive = x.Primitives[0]; var mesh = primitive.FromGltf(storage, x); var materialIndex = primitive.Material.HasValue ? primitive.Material.Value : 0; mesh.Submeshes.Add( new Submesh(0, mesh.IndexBuffer.Count, materials[materialIndex])); group.Meshes.Add(mesh); } else if (!x.AllPrimitivesHasSameVertexBuffer()) { int offset = 0; foreach (var primitive in x.Primitives) { var mesh = primitive.FromGltf(storage, x); var materialIndex = primitive.Material.HasValue ? primitive.Material.Value : 0; mesh.Submeshes.Add( new Submesh(offset, mesh.IndexBuffer.Count, materials[materialIndex])); offset += mesh.IndexBuffer.Count; group.Meshes.Add(mesh); } } else { // for VRM var mesh = x.SharedBufferFromGltf(storage); int offset = 0; foreach (var primitive in x.Primitives) { var materialIndex = primitive.Material.HasValue ? primitive.Material.Value : 0; var count = storage.Gltf.Accessors[primitive.Indices.Value].Count.Value; mesh.Submeshes.Add( new Submesh(offset, count, materials[materialIndex])); offset += count; } group.Meshes.Add(mesh); } return(group); }
public MeshGroup this[int objId] { get { if (_meshGroups.TryGetValue(objId, out var meshGroup)) { return(meshGroup); } var objEntryName = _objEntryLookupReversed[objId]; var modelPath = Path.Combine(_objPath, objEntryName); var modelFileName = modelPath + ".mdlx"; if (File.Exists(modelFileName)) { var mdlxEntries = File.OpenRead(modelFileName).Using(Bar.Read); var modelEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Model); if (modelEntry != null) { var model = Mdlx.Read(modelEntry.Stream); ModelTexture textures = null; var textureEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.ModelTexture); if (textureEntry != null) { textures = ModelTexture.Read(textureEntry.Stream); } var modelMotion = MeshLoader.FromKH2(model); modelMotion.ApplyMotion(modelMotion.InitialPose); meshGroup = new MeshGroup { MeshDescriptors = modelMotion.MeshDescriptors, Textures = textures == null ? new IKingdomTexture[0] : textures.LoadTextures(_graphics).ToArray() }; } else { meshGroup = EmptyMeshGroup; } } else { meshGroup = EmptyMeshGroup; } _meshGroups[objId] = meshGroup; return(meshGroup); } }
public static glTFMesh ExportMeshGroup(this MeshGroup src, List <object> materials, Vrm10Storage storage, ExportArgs option) { var mesh = new glTFMesh { name = src.Name }; foreach (var x in src.Meshes) { // MeshとSubmeshがGltfのPrimitiveに相当する? x.ExportMesh(materials, storage, mesh, option); } return(mesh); }
void ungroupSelectedBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { string makingCopyLabel = LocalizedString.Get("Ungrouping"); string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel); processingProgressControl.ProcessType = makingCopyLabelFull; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; BackgroundWorker backgroundWorker = (BackgroundWorker)sender; PushMeshGroupDataToAsynchLists(TraceInfoOpperation.DO_COPY); int indexBeingReplaced = SelectedMeshGroupIndex; asynchMeshGroups[indexBeingReplaced].Transform(asynchMeshGroupTransforms[indexBeingReplaced].TotalTransform); List <Mesh> discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asynchMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) => { BackgroundWorker_ProgressChanged(progress0To1 * .5, processingState, out continueProcessing); }); asynchMeshGroups.RemoveAt(indexBeingReplaced); asynchPlatingDatas.RemoveAt(indexBeingReplaced); asynchMeshGroupTransforms.RemoveAt(indexBeingReplaced); double ratioPerDiscreetMesh = 1.0 / discreetMeshes.Count; double currentRatioDone = 0; for (int discreetMeshIndex = 0; discreetMeshIndex < discreetMeshes.Count; discreetMeshIndex++) { PlatingMeshGroupData newInfo = new PlatingMeshGroupData(); asynchPlatingDatas.Add(newInfo); asynchMeshGroups.Add(new MeshGroup(discreetMeshes[discreetMeshIndex])); int addedMeshIndex = asynchMeshGroups.Count - 1; MeshGroup addedMeshGroup = asynchMeshGroups[addedMeshIndex]; ScaleRotateTranslate transform = ScaleRotateTranslate.Identity(); transform.SetCenteringForMeshGroup(addedMeshGroup); asynchMeshGroupTransforms.Add(transform); //PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, addedMeshIndex, false); // and create selection info PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) => { BackgroundWorker_ProgressChanged(progress0To1 * .5 + .5, processingState, out continueProcessing); }); currentRatioDone += ratioPerDiscreetMesh; } }
private void DoGroup(BackgroundWorker backgroundWorker) { if (SelectedMeshGroupIndex == -1) { SelectedMeshGroupIndex = 0; } MeshGroup meshGroupWeAreKeeping = asynchMeshGroups[SelectedMeshGroupIndex]; for (int meshGroupToMoveIndex = asynchMeshGroups.Count - 1; meshGroupToMoveIndex >= 0; meshGroupToMoveIndex--) { MeshGroup meshGroupToMove = asynchMeshGroups[meshGroupToMoveIndex]; if (meshGroupToMove != meshGroupWeAreKeeping) { for (int moveIndex = 0; moveIndex < meshGroupToMove.Meshes.Count; moveIndex++) { Mesh mesh = meshGroupToMove.Meshes[moveIndex]; meshGroupWeAreKeeping.Meshes.Add(mesh); } asynchMeshGroups.RemoveAt(meshGroupToMoveIndex); asynchMeshGroupTransforms.RemoveAt(meshGroupToMoveIndex); } else { asynchMeshGroupTransforms[meshGroupToMoveIndex] = ScaleRotateTranslate.Identity(); } } asynchPlatingDatas.Clear(); double ratioPerMeshGroup = 1.0 / asynchMeshGroups.Count; double currentRatioDone = 0; for (int i = 0; i < asynchMeshGroups.Count; i++) { PlatingMeshGroupData newInfo = new PlatingMeshGroupData(); asynchPlatingDatas.Add(newInfo); MeshGroup meshGroup = asynchMeshGroups[i]; // create the selection info PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) => { ReportProgressChanged(progress0To1, processingState, out continueProcessing); }); currentRatioDone += ratioPerMeshGroup; } }
public static MeshGroup FromGltf(this GltfMesh x, GltfSerialization.GltfStorage storage, List <Material> materials) { var group = new MeshGroup(x.name); if (x.primitives.Count == 1) { var primitive = x.primitives[0]; var mesh = primitive.FromGltf(storage, x); mesh.Submeshes.Add( new Submesh(0, mesh.IndexBuffer.Count, materials[primitive.material])); group.Meshes.Add(mesh); } else if (!x.AllPrimitivesHasSameVertexBuffer()) { int offset = 0; foreach (var primitive in x.primitives) { var mesh = primitive.FromGltf(storage, x); mesh.Submeshes.Add( new Submesh(offset, mesh.IndexBuffer.Count, materials[primitive.material])); offset += mesh.IndexBuffer.Count; group.Meshes.Add(mesh); } } else { // for VRM var mesh = x.SharedBufferFromGltf(storage); int offset = 0; foreach (var primitive in x.primitives) { var count = storage.Gltf.accessors[primitive.indices].count; mesh.Submeshes.Add( new Submesh(offset, count, materials[primitive.material])); offset += count; } group.Meshes.Add(mesh); } return(group); }
private static string SaveAndGetFilenameForMaterial(MeshGroup extruderMeshGroup, List <int> materialIndexsToSaveInThisSTL) { string fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".stl"); string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; string folderToSaveStlsTo = Path.Combine(applicationUserDataPath, "data", "temp", "amf_to_stl"); if (!Directory.Exists(folderToSaveStlsTo)) { Directory.CreateDirectory(folderToSaveStlsTo); } MeshOutputSettings settings = new MeshOutputSettings(); settings.MaterialIndexsToSave = materialIndexsToSaveInThisSTL; string extruder1StlFileToSlice = Path.Combine(folderToSaveStlsTo, fileName); MeshFileIo.Save(extruderMeshGroup, extruder1StlFileToSlice, settings); return(extruder1StlFileToSlice); }
private void readMeshGroups() { int meshgroups = ReadCount(); for (int m = 0; m < meshgroups; ++m) { MeshGroup group = new MeshGroup(); byte flags = Read <byte>(); group.name = CropNull(ReadString(32)); int mtricount = ReadCount(); for (int t = 0; t < mtricount; ++t) { int tr = Read <short>(); group.tri.Add(tr); } group.material = Read <char>(); groups.Add(group); } }
public void Combine(MeshGroup meshGroup) { for (int index1 = 0; index1 < meshGroup.data.Count; ++index1) { MeshInstance meshInstance = meshGroup.data[index1]; Matrix4x4 matrix4x4 = Matrix4x4.TRS(meshInstance.position, meshInstance.rotation, meshInstance.scale); int count = this.vertices.Count; for (int index2 = 0; index2 < meshInstance.data.triangles.Length; ++index2) { this.triangles.Add(count + meshInstance.data.triangles[index2]); } for (int index2 = 0; index2 < meshInstance.data.vertices.Length; ++index2) { this.vertices.Add(((Matrix4x4) ref matrix4x4).MultiplyPoint3x4(meshInstance.data.vertices[index2])); this.positions.Add(Vector4.op_Implicit(meshInstance.position)); } for (int index2 = 0; index2 < meshInstance.data.normals.Length; ++index2) { this.normals.Add(((Matrix4x4) ref matrix4x4).MultiplyVector(meshInstance.data.normals[index2])); } for (int index2 = 0; index2 < meshInstance.data.tangents.Length; ++index2) { Vector4 tangent = meshInstance.data.tangents[index2]; Vector3 vector3_1; ((Vector3) ref vector3_1).\u002Ector((float)tangent.x, (float)tangent.y, (float)tangent.z); Vector3 vector3_2 = ((Matrix4x4) ref matrix4x4).MultiplyVector(vector3_1); this.tangents.Add(new Vector4((float)vector3_2.x, (float)vector3_2.y, (float)vector3_2.z, (float)tangent.w)); } for (int index2 = 0; index2 < meshInstance.data.colors32.Length; ++index2) { this.colors32.Add(meshInstance.data.colors32[index2]); } for (int index2 = 0; index2 < meshInstance.data.uv.Length; ++index2) { this.uv.Add(meshInstance.data.uv[index2]); } for (int index2 = 0; index2 < meshInstance.data.uv2.Length; ++index2) { this.uv2.Add(meshInstance.data.uv2[index2]); } } }
private static void AddToMeshGroup(List <MeshGroup> groups, MeshRenderer renderer, int index) { bool added = false; foreach (var group in groups) { if (group.DoesMatch(renderer)) { group.AddIndex(index); added = true; break; } } if (!added) { var group = MeshGroup.CreateFromRenderer(renderer); group.AddIndex(index); groups.Add(group); } }
public void Combine(MeshGroup meshGroup) { for (int i = 0; i < meshGroup.data.Count; i++) { MeshInstance meshInstance = meshGroup.data[i]; Matrix4x4 matrix4x = Matrix4x4.TRS(meshInstance.position, meshInstance.rotation, meshInstance.scale); int count = vertices.Count; for (int j = 0; j < meshInstance.data.triangles.Length; j++) { triangles.Add(count + meshInstance.data.triangles[j]); } for (int k = 0; k < meshInstance.data.vertices.Length; k++) { vertices.Add(matrix4x.MultiplyPoint3x4(meshInstance.data.vertices[k])); positions.Add(meshInstance.position); } for (int l = 0; l < meshInstance.data.normals.Length; l++) { normals.Add(matrix4x.MultiplyVector(meshInstance.data.normals[l])); } for (int m = 0; m < meshInstance.data.tangents.Length; m++) { Vector4 vector = meshInstance.data.tangents[m]; Vector3 vector2 = new Vector3(vector.x, vector.y, vector.z); Vector3 vector3 = matrix4x.MultiplyVector(vector2); tangents.Add(new Vector4(vector3.x, vector3.y, vector3.z, vector.w)); } for (int n = 0; n < meshInstance.data.colors32.Length; n++) { colors32.Add(meshInstance.data.colors32[n]); } for (int num = 0; num < meshInstance.data.uv.Length; num++) { uv.Add(meshInstance.data.uv[num]); } for (int num2 = 0; num2 < meshInstance.data.uv2.Length; num2++) { uv2.Add(meshInstance.data.uv2[num2]); } } }
public void Combine(MeshGroup meshGroup) { for (int i = 0; i < meshGroup.data.Count; i++) { MeshInstance item = meshGroup.data[i]; Matrix4x4 matrix4x4 = Matrix4x4.TRS(item.position, item.rotation, item.scale); int count = this.vertices.Count; for (int j = 0; j < (int)item.data.triangles.Length; j++) { this.triangles.Add(count + item.data.triangles[j]); } for (int k = 0; k < (int)item.data.vertices.Length; k++) { this.vertices.Add(matrix4x4.MultiplyPoint3x4(item.data.vertices[k])); this.positions.Add(item.position); } for (int l = 0; l < (int)item.data.normals.Length; l++) { this.normals.Add(matrix4x4.MultiplyVector(item.data.normals[l])); } for (int m = 0; m < (int)item.data.tangents.Length; m++) { Vector4 vector4 = item.data.tangents[m]; Vector3 vector3 = new Vector3(vector4.x, vector4.y, vector4.z); Vector3 vector31 = matrix4x4.MultiplyVector(vector3); this.tangents.Add(new Vector4(vector31.x, vector31.y, vector31.z, vector4.w)); } for (int n = 0; n < (int)item.data.colors32.Length; n++) { this.colors32.Add(item.data.colors32[n]); } for (int o = 0; o < (int)item.data.uv.Length; o++) { this.uv.Add(item.data.uv[o]); } for (int p = 0; p < (int)item.data.uv2.Length; p++) { this.uv2.Add(item.data.uv2[p]); } } }
public static void FindPositionForGroupAndAddToPlate(MeshGroup meshGroupToAdd, ScaleRotateTranslate meshTransform, List <PlatingMeshGroupData> perMeshInfo, List <MeshGroup> meshesGroupsToAvoid, List <ScaleRotateTranslate> meshTransforms) { if (meshGroupToAdd == null || meshGroupToAdd.Meshes.Count < 1) { return; } meshesGroupsToAvoid.Add(meshGroupToAdd); PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData(); perMeshInfo.Add(newMeshInfo); meshTransform.SetCenteringForMeshGroup(meshGroupToAdd); meshTransforms.Add(meshTransform); int meshGroupIndex = meshesGroupsToAvoid.Count - 1; MoveMeshGroupToOpenPosition(meshGroupIndex, perMeshInfo, meshesGroupsToAvoid, meshTransforms); PlaceMeshGroupOnBed(meshesGroupsToAvoid, meshTransforms, meshGroupIndex, false); }
private static MeshGroup ReadObject(XmlReader xmlTree, double scale, ProgressData progressData) { MeshGroup meshGroup = new MeshGroup(); while (xmlTree.Read()) { if (xmlTree.Name == "mesh") { using (XmlReader meshTree = xmlTree.ReadSubtree()) { ReadMesh(meshTree, meshGroup, scale, progressData); if (progressData.LoadCanceled) { return(null); } } } } return(meshGroup); }
public MeshGroup GetMeshGroup(string aniname) { if (mapGroupAnim.ContainsKey(aniname)==false) { if (data.GetMeshGroupMaxFrame(aniname) < 0) return null; mapGroupAnim[aniname] = new MeshGroup(data, aniname); } return mapGroupAnim[aniname]; }
public static bool Save(MeshGroup meshGroupToSave, string meshPathAndFileName, MeshOutputSettings outputInfo = null) { List<MeshGroup> meshGroupsToSave = new List<MeshGroup>(); meshGroupsToSave.Add(meshGroupToSave); return Save(meshGroupsToSave, meshPathAndFileName, outputInfo); }
private static void SetUpScene() { //Load the world WorldMesh = MeshGenerator.LoadOBJMulti("balancelevel.obj"); /* //Create the floor's physics mesh Body level = FarseerPhysics.Factories.BodyFactory.CreateRectangle(Utilities.PhysicsWorld, 1000, 10, 1.00f); level.Position = new Microsoft.Xna.Framework.Vector2(0, -5.0f); level.BodyType = BodyType.Static; //Walls level = FarseerPhysics.Factories.BodyFactory.CreateRectangle(Utilities.PhysicsWorld, 10, 1000, 1.00f); level.Position = new Microsoft.Xna.Framework.Vector2(-153, 0); level.BodyType = BodyType.Static; level = FarseerPhysics.Factories.BodyFactory.CreateRectangle(Utilities.PhysicsWorld, 10, 1000, 1.00f); level.Position = new Microsoft.Xna.Framework.Vector2(153, 0); level.BodyType = BodyType.Static; ent_physics pole = EntManager.Create<ent_physics>(); pole.Spawn(); pole.SetPos(Vector2.Zero); pole.SetModel(new Mesh("pole.obj")); pole.Material = Resource.GetMaterial("Models/wood_log"); //Create the physics for it pole.Physics.Body.BodyType = BodyType.Static; pole.SetPos(new Vector2(0, -pole.Model.BBox.Negative.Y)); ent_physics bar = EntManager.Create<ent_physics>(); bar.Spawn(); bar.SetPos(Vector2.Zero); bar.SetModel(new Mesh("balancebeam.obj")); bar.Material = Resource.GetMaterial("Models/balancebeam"); bar.SetPos(new Vector2(0, 30)); bar.Physics.Body.BodyType = BodyType.Dynamic; bar.Physics.Body.Mass = 2; bar.Physics.Friction = 1000; BalanceEnt = bar; */ //Turn on the lights DirectionalLight light = new DirectionalLight(); light.AmbientIntensity = 0.4f; light.DiffuseIntensity = 0.9f; light.Color = new Vector3(0.745f, 0.820f, 0.847f); //new Vector3(0.133f, 0.149f, 0.176f); light.Direction = new Vector3(-1.0f, -1.0f, 0.0f); light.Direction.Normalize(); ent_pointlight pointlight = EntManager.Create<ent_pointlight>(); pointlight.Spawn(); pointlight.AmbientIntensity = 0.4f; pointlight.DiffuseIntensity = 20.0f; //0.85f pointlight.Color = new Vector3(1.0f, 0.5f, 0.0f); pointlight.SetPos(new Vector3(-2.00f, 2.421f, -14.90f)); pointlight.Linear = 22.7f; spotlight = (ent_spotlight)EntManager.Create<ent_spotlight>(); spotlight.Spawn(); spotlight.Color = new Vector3(1.0f, 1.0f, 1.0f); spotlight.Constant = 1.0f; spotlight.Cutoff = 20.0f; //Create a radio to set the mood ent_radio radio = EntManager.Create<ent_radio>(); radio.Spawn(); radio.SetPos(new Vector3(-7.00f, 0, -14.90f)); radio.Scale = new Vector3(0.3f); LightingTechnique.SetEnvironmentLight(light); ShadowTechnique.Enable(); //Load some groovy jams with our custom music handler Music = MusicMix.Create("Resources/Audio/Music", "mix_", ".wav"); Music.Play(true); //Start waiting! SetState(LevelState.WAITING); }
private static MeshGroup ReadObject(XmlReader xmlTree, double scale, ProgressData progressData) { MeshGroup meshGroup = new MeshGroup(); while (xmlTree.Read()) { if (xmlTree.Name == "mesh") { using (XmlReader meshTree = xmlTree.ReadSubtree()) { ReadMesh(meshTree, meshGroup, scale, progressData); if (progressData.LoadCanceled) { return null; } } } } return meshGroup; }
public override void Preload() { levelmodel = MeshGenerator.LoadOBJMulti("Levels/sponza.obj"); //Levels/multi_test.obj Levels/sponza.obj //levelmodel = Resource.GetMesh("Levels/level1.obj"); //levelmodel.mat = Resource.GetMaterial("levels/level1"); //Spawn the little depth screen thingy EntManager.Create<ent_depthscreen>().Spawn(); Vector3 OlegPos = new Vector3(-2.00f, 2.421f, -14.90f); //don't forget oleg oleg = EntManager.Create<ent_static>(); oleg.Spawn(); oleg.SetModel(Resource.GetMesh("props/oleg.obj")); oleg.Name = "Oleg"; oleg.SetPos(OlegPos); oleg.Scale = new Vector3(0.75f); oleg.SetAngle(new Angle(0, 0, 14.3f)); //and the boys var ent = EntManager.Create<ent_static>(); ent.Spawn(); ent.SetModel(Resource.GetMesh("props/oleg.obj")); ent.Material = Resource.GetMaterial("engine/white"); ent.SetPos(OlegPos + new Vector3(0, 0.0f, -0.1f)); ent.Scale = new Vector3(0.75f); ent.SetParent(oleg); ent_pointlight pointlight = (ent_pointlight)EntManager.Create<ent_pointlight>(); pointlight.Spawn(); pointlight.AmbientIntensity = 0.40f; pointlight.DiffuseIntensity = 0.85f; pointlight.Color = new Vector3(1.0f, 0.5f, 0.0f); pointlight.SetPos(OlegPos); pointlight.Linear = 0.1f; pointlight.SetParent(oleg); spotlight = (ent_spotlight)EntManager.Create<ent_spotlight>(); spotlight.Spawn(); spotlight.Color = new Vector3(1.0f, 1.0f, 1.0f); spotlight.Constant = 1.0f; spotlight.Cutoff = 20.0f; //Make us some nice environmental lighting DirectionalLight light = new DirectionalLight(); light.AmbientIntensity = 0.4f; light.DiffuseIntensity = 0.9f; light.Color = new Vector3(0.133f, 0.149f, 0.176f); light.Direction = new Vector3(0.0f, -1.0f, 0.0f); LightingTechnique.SetEnvironmentLight(light); ShadowTechnique.Enable(); //Gimme some skyboxes! SkyboxTechnique.SetSkyGradientMaterial(Resource.GetMaterial("skybox/skygradient_default")); SkyboxTechnique.PreDrawSkybox += new Action(SkyboxTechnique_PreDrawSkybox); dome = Resource.GetMesh("engine/skybox.obj"); starBox = Resource.GetMaterial("skybox/skybox_starrynight"); //Some fog! FogTechnique.SetFogParameters(new FogParams() { Color = new Vector3(0.37254f, 0.368627f, 0.427450f), Start = 20, End = 200, Density = 0.03f, Type = FogParams.FogType.Exp2, }); FogTechnique.Enabled = true; Utilities.ForcedFrametime = 0.002604167; Utilities.engine.Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown); }
private static void ReadMesh(XmlReader xmlTree, MeshGroup meshGroup, double scale, ProgressData progressData) { List<Vector3> vertices = new List<Vector3>(); while (xmlTree.Read()) { switch (xmlTree.Name) { case "vertices": using (XmlReader verticesTree = xmlTree.ReadSubtree()) { ReadVertices(verticesTree, vertices, scale, progressData); if (progressData.LoadCanceled) { return; } } break; case "volume": string materialId = xmlTree["materialid"]; Mesh loadedMesh = null; using (XmlReader volumeTree = xmlTree.ReadSubtree()) { loadedMesh = ReadVolume(volumeTree, vertices, progressData); if (progressData.LoadCanceled) { return; } meshGroup.Meshes.Add(loadedMesh); } if (loadedMesh != null && materialId != null) { MeshMaterialData material = MeshMaterialData.Get(loadedMesh); material.MaterialIndex = int.Parse(materialId); } break; } } }