private QuadTerrainRenderMesh GetRenderMesh(MeshType meshType) { var renderMesh = RenderMeshes[(int)meshType]; if (renderMesh != null) { return(renderMesh); } renderMesh = new QuadTerrainRenderMesh(); renderMesh.Mesh = QuadTerrainConfig.Instance.GetMesh(meshType); renderMesh.Props = new MaterialPropertyBlock(); renderMesh.Matrices = new Matrix4x4[1023]; renderMesh.RenderingLayers = new Vector4[1023]; int flags = 0xff; // enable all light layers float flagsFloat = BitConverter.ToSingle(BitConverter.GetBytes(flags), 0); for (int i = 0; i < renderMesh.RenderingLayers.Length; i++) { renderMesh.RenderingLayers[i] = new Vector4(flagsFloat, 0, 0, 0); } renderMesh.Props.SetVectorArray("unity_RenderingLayer", renderMesh.RenderingLayers); RenderMeshes[(int)meshType] = renderMesh; return(renderMesh); }
void HandleBackwardCompatibility(int serializedVersion, int newVersion) { if (serializedVersion == -1) { return; // freshly new spawned entity: nothing to do } if (serializedVersion == newVersion) { return; // same version: nothing to do } if (serializedVersion < 1301) { // quadratic attenuation is a new feature of 1.3 attenuationEquation = AttenuationEquation.Linear; } if (serializedVersion < 1501) { // custom mesh is a new feature of 1.5 geomMeshType = MeshType.Custom; geomCustomSegments = 5; } if (serializedVersion < 1610) { // intensity global/advanced mode is a feature of 1.61 intensityFromLight = false; intensityModeAdvanced = !Mathf.Approximately(intensityInside, intensityOutside); } Utils.MarkCurrentSceneDirty(); }
private Mesh LoadMesh(MeshType meshType) { string meshName = meshType.ToString() + "Mesh.mesh"; string pathMesh = PackagePath + "Meshes/" + meshName; return(AssetDatabase.LoadAssetAtPath <Mesh>(pathMesh)); }
public static Mesh BuildMesh(Chunk chunk, MeshType meshType) { MeshBuilder.chunk = chunk; Mesh mesh = null; switch (meshType) { case MeshType.Basic: mesh = BasicMesh(); break; case MeshType.AmbientOcclusion: mesh = AmbientOcclusionMesh(); break; case MeshType.Gradient: mesh = GradientMesh(); break; default: throw new ArgumentOutOfRangeException("meshType", meshType, null); } Clean(); return(mesh); }
public void GetMeshBound(MeshType meshType, string name) { GameObject[] obj = Selection.gameObjects; for (int i = 0; i < obj.Length; i++) { MeshFilter render = obj[i].GetComponent <MeshFilter>(); if (render == null || render.sharedMesh == null) { continue; } LineRenderer lineRender = obj[i].GetComponent <LineRenderer>(); Mesh mesh = render.sharedMesh; List <List <Vector3> > vertices = MeshTools.TrianglesAndVerticesEdge(mesh.vertices, mesh.triangles); int index = 0; int maxCount = 0; for (int j = 0; j < vertices.Count; j++) { if (maxCount < vertices[j].Count) { index = j; maxCount = vertices[j].Count; } } CreateMesh(vertices[index], obj[i], obj[i].transform.parent, name, meshType); } }
public void RegenerateMesh() { Debug.Assert(this.m_Master); base.gameObject.layer = Config.Instance.geometryLayerID; base.gameObject.tag = Config.Instance.geometryTag; if (this.coneMesh && this.m_CurrentMeshType == MeshType.Custom) { UnityEngine.Object.DestroyImmediate(this.coneMesh); } this.m_CurrentMeshType = this.m_Master.geomMeshType; MeshType mMaster = this.m_Master.geomMeshType; if (mMaster == MeshType.Shared) { this.coneMesh = GlobalMesh.mesh; this.meshFilter.sharedMesh = this.coneMesh; } else if (mMaster != MeshType.Custom) { Debug.LogError("Unsupported MeshType"); } else { this.coneMesh = MeshGenerator.GenerateConeZ_Radius(1f, 1f, 1f, this.m_Master.geomCustomSides, this.m_Master.geomCustomSegments, this.m_Master.geomCap); this.coneMesh.hideFlags = Consts.ProceduralObjectsHideFlags; this.meshFilter.mesh = this.coneMesh; } this.UpdateMaterialAndBounds(); }
public static Mesh MakeMesh(int width, int height, MeshType type, int difficulty) { Mesh mesh = new Mesh(width, height, type); mesh.ConsiderMultipleLoops = difficulty > 0; mesh.IterativeRecMaxDepth = 1; if (difficulty > 1) { mesh.UseCellColoring = true; mesh.UseCellColoringTrials = true; mesh.UseColoring = true; mesh.UseEdgeRestricts = true; mesh.UseDerivedColoring = true; mesh.UseMerging = true; mesh.UseCellPairsTopLevel = true; } if (difficulty < 5) { mesh.IterativeSolverDepth = Math.Max(0, difficulty - 2); } else { mesh.SolverMethod = SolverMethod.Recursive; } mesh.GenerateBoringFraction = 0.01; return(mesh); }
public override void Deserialize(BinaryReader stream) { MeshType type = (MeshType)stream.ReadInt32(); if (type == MeshType.Cube) { Value = new Cube(stream.ReadSingle(), stream.ReadInt32()); } else if (type == MeshType.Sphere) { Value = new Sphere(stream.ReadSingle()); } else if (type == MeshType.Square) { Value = new Square(stream.ReadSingle()); } else if (type == MeshType.Spline) { int ptCount = stream.ReadInt32(); Spline.Point[] pts = new Spline.Point[ptCount]; for (int i = 0; i < ptCount; i++) { pts[i] = new Spline.Point(new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()), new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()), new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle())); } Value = new Spline(pts); } else if (type == MeshType.HexGrid) { Value = new HexGrid(stream.ReadInt32(), stream.ReadInt32(), stream.ReadInt32()); } else { throw new NotImplementedException("Mesh type " + type + " doesn't have a deserializer defined."); } }
public static int GetVerticesPerObject(MeshType type) { switch (type) { case MeshType.None: return(0); case MeshType.Billboard8: return(8); case MeshType.Billboard16: return(16); case MeshType.Convex13: return(13); case MeshType.Convex25: return(25); case MeshType.Bond8: return(8); case MeshType.Convex85: return(convexHighVerts.Length); case MeshType.Billboard24: return(24); case MeshType.TrueSphere: return(515); default: throw new NotImplementedException("Unsupported mesh type " + type); } }
void HandleBackwardCompatibility(int serializedVersion, int newVersion) { if (serializedVersion == -1) { return; // freshly new spawned entity: nothing to do } if (serializedVersion == newVersion) { return; // same version: nothing to do } if (serializedVersion < 1301) { // quadratic attenuation is a new feature of 1.3 attenuationEquation = AttenuationEquation.Linear; } if (serializedVersion < 1501) { // custom mesh is a new feature of 1.5 geomMeshType = MeshType.Custom; geomCustomSegments = 5; } Utils.MarkCurrentSceneDirty(); }
public void Reset() { colorMode = Consts.ColorModeDefault; color = Consts.FlatColor; colorFromLight = true; intensityFromLight = true; intensityModeAdvanced = false; intensityInside = Consts.IntensityDefault; intensityOutside = Consts.IntensityDefault; blendingMode = Consts.BlendingModeDefault; shaderAccuracy = Consts.ShaderAccuracyDefault; spotAngleFromLight = true; spotAngle = Consts.SpotAngleDefault; coneRadiusStart = Consts.ConeRadiusStart; geomMeshType = Consts.GeomMeshType; geomCustomSides = Consts.GeomSidesDefault; geomCustomSegments = Consts.GeomSegmentsDefault; geomCap = Consts.GeomCap; attenuationEquation = Consts.AttenuationEquationDefault; attenuationCustomBlending = Consts.AttenuationCustomBlending; fallOffEndFromLight = true; fallOffStart = Consts.FallOffStart; fallOffEnd = Consts.FallOffEnd; depthBlendDistance = Consts.DepthBlendDistance; cameraClippingDistance = Consts.CameraClippingDistance; glareFrontal = Consts.GlareFrontal; glareBehind = Consts.GlareBehind; fresnelPow = Consts.FresnelPow; noiseMode = Consts.NoiseModeDefault; noiseIntensity = Consts.NoiseIntensityDefault; noiseScaleUseGlobal = true; noiseScaleLocal = Consts.NoiseScaleDefault; noiseVelocityUseGlobal = true; noiseVelocityLocal = Consts.NoiseVelocityDefault; sortingLayerID = 0; sortingOrder = 0; fadeOutBegin = Consts.FadeOutBeginDefault; fadeOutEnd = Consts.FadeOutEndDefault; dimensions = Consts.DimensionsDefault; tiltFactor = Consts.TiltDefault; skewingLocalForwardDirection = Consts.SkewingLocalForwardDirectionDefault; clippingPlaneTransform = Consts.ClippingPlaneTransformDefault; trackChangesDuringPlaytime = false; m_EditorDirtyFlags = EditorDirtyFlags.Everything; }
public void GenerateAndSaveMesh(MeshType meshType) { Mesh mesh = null; switch (meshType) { case MeshType.Quad: mesh = GenerateQuadMesh(_MeshSideVerticesCount, _Size); break; case MeshType.Circle: mesh = GenerateCircleMesh(_MeshSideVerticesCount, _Size); break; case MeshType.ParabolicCircle: mesh = GenerateParabolicCircleMesh(_MeshSideVerticesCount, _Size); break; } var verts = mesh.vertices; var uvs = new Vector2[verts.Length]; for (int j = 0; j < verts.Length; j++) { uvs[j] = ((Vector2)verts[j] + _Size * Vector2.one) / (2 * _Size); } mesh.uv = uvs; AssetDatabase.CreateAsset(mesh, _MeshPath); AssetDatabase.SaveAssets(); }
public DynamicMesh CreateMesh(MeshType type = MeshType.Tris) { DynamicMesh mesh = new DynamicMesh(RenderDevice); switch (type) { case MeshType.Tris: mesh.Fragment = DefaultFragment; mesh.Projection = Mesh.ProjectionType.Unit; break; case MeshType.Text: mesh.Fragment = TextFragment; mesh.Projection = Mesh.ProjectionType.Pixel; break; case MeshType.Lines: mesh.Fragment = DefaultFragment; mesh.Projection = Mesh.ProjectionType.Unit; mesh.Geometry = Mesh.GeometryType.Lines; break; default: break; } return(mesh); }
public void RegenerateMesh() { Debug.Assert(Object.op_Implicit((Object)this.m_Master)); ((Component)this).get_gameObject().set_layer(Config.Instance.geometryLayerID); ((Component)this).get_gameObject().set_tag(Config.Instance.geometryTag); if (Object.op_Implicit((Object)this.coneMesh) && this.m_CurrentMeshType == MeshType.Custom) { Object.DestroyImmediate((Object)this.coneMesh); } this.m_CurrentMeshType = this.m_Master.geomMeshType; switch (this.m_Master.geomMeshType) { case MeshType.Shared: this.coneMesh = GlobalMesh.mesh; this.meshFilter.set_sharedMesh(this.coneMesh); break; case MeshType.Custom: this.coneMesh = MeshGenerator.GenerateConeZ_Radius(1f, 1f, 1f, this.m_Master.geomCustomSides, this.m_Master.geomCustomSegments, this.m_Master.geomCap); ((Object)this.coneMesh).set_hideFlags(Consts.ProceduralObjectsHideFlags); this.meshFilter.set_mesh(this.coneMesh); break; default: Debug.LogError((object)"Unsupported MeshType"); break; } this.UpdateMaterialAndBounds(); }
public static Mesh Flatten(this IEnumerable <Mesh> meshes, MeshType type) { var indices = new List <uint>(); var vertices = new List <Vector3>(); var normals = new List <Vector3>(); foreach (var mesh in meshes) { if (mesh == null) { continue; } var vo = (uint)vertices.Count; if (mesh.Vertices != null) { vertices.AddRange(mesh.Vertices); } if (mesh.Normals != null) { normals.AddRange(mesh.Normals); } if (mesh.Indices != null) { indices.AddRange(mesh.Indices.Select(i => vo + i)); } } return(new Mesh { Type = type, Indices = indices.ToArray(), Vertices = vertices.ToArray(), Normals = normals.ToArray(), }); }
public MeshCacheItem(Mesh mesh) { type = MeshType.Mesh; this.mesh = mesh; rows = 0; quantizedHeight = 0; }
public MeshDataThreadInfo(Vector2 position, float[,] heightMap, MeshData meshData, MeshType type) { this.position = position; this.heightMap = heightMap; this.meshData = meshData; this.type = type; }
/// <summary> /// Num allocated instances for a particular type /// </summary> /// <param name="m"></param> /// <returns></returns> public int NumInstancesAllocatedForMeshType(MeshType m) { lock (this._instance_lock) { return((int)this.mesh._delta_buffer.NumInstancesForGroup(m.groupID)); } }
public override void Enable() { borderColorTop = element.style.BorderColorTop; borderColorRight = element.style.BorderColorRight; borderColorBottom = element.style.BorderColorBottom; borderColorLeft = element.style.BorderColorLeft; backgroundColor = element.style.BackgroundColor; backgroundTint = element.style.BackgroundTint; backgroundImage = element.style.BackgroundImage; borderRadiusTopLeft = element.style.BorderRadiusTopLeft; borderRadiusTopRight = element.style.BorderRadiusTopRight; borderRadiusBottomLeft = element.style.BorderRadiusBottomLeft; borderRadiusBottomRight = element.style.BorderRadiusBottomRight; cornerBevelTopLeft = element.style.CornerBevelTopLeft; cornerBevelTopRight = element.style.CornerBevelTopRight; cornerBevelBottomRight = element.style.CornerBevelBottomRight; cornerBevelBottomLeft = element.style.CornerBevelBottomLeft; shadowColor = element.style.ShadowColor; materialId = element.style.Material; opacity = element.style.Opacity; meshType = element.style.MeshType; meshFillAmount = element.style.MeshFillAmount; meshFillDirection = element.style.MeshFillDirection; meshFillOrigin = element.style.MeshFillOrigin; }
public static QuickPolygon Create(string name, MeshType meshIndex, Vector3 position, Quaternion rotation, bool isUI) { GameObject polygon = new GameObject(); if (!string.IsNullOrEmpty(name)) { polygon.name = name; } else { polygon.name = meshIndex.ToString(); } polygon.transform.position = position; polygon.transform.rotation = rotation; #if UNITY_EDITOR if (!Application.isPlaying) { Undo.RegisterCreatedObjectUndo(polygon, "Shape Created"); Selection.activeObject = polygon; } #endif QuickPolygon newPolygon = polygon.AddComponent <QuickPolygon>(); newPolygon.ShapeMeshIndex = meshIndex; newPolygon.IsUI = isUI; newPolygon.Reset(); newPolygon.RecalculateMesh(); return(newPolygon); }
private void Initialize(MeshType meshType) { if (null == _mesh) { _mesh = new Mesh(); } var ovrpMesh = new OVRPlugin.Mesh(); if (OVRPlugin.GetMesh((OVRPlugin.MeshType)_meshType, out ovrpMesh)) { var vertices = new Vector3[ovrpMesh.NumVertices]; for (int i = 0; i < ovrpMesh.NumVertices; ++i) { vertices[i] = ovrpMesh.VertexPositions[i].FromFlippedXVector3f(); } _mesh.vertices = vertices; var uv = new Vector2[ovrpMesh.NumVertices]; for (int i = 0; i < ovrpMesh.NumVertices; ++i) { uv[i] = new Vector2(ovrpMesh.VertexUV0[i].x, -ovrpMesh.VertexUV0[i].y); } _mesh.uv = uv; var triangles = new int[ovrpMesh.NumIndices]; for (int i = 0; i < ovrpMesh.NumIndices; ++i) { triangles[i] = ovrpMesh.Indices[ovrpMesh.NumIndices - i - 1]; } _mesh.triangles = triangles; var normals = new Vector3[ovrpMesh.NumVertices]; for (int i = 0; i < ovrpMesh.NumVertices; ++i) { normals[i] = ovrpMesh.VertexNormals[i].FromFlippedXVector3f(); } _mesh.normals = normals; var boneWeights = new BoneWeight[ovrpMesh.NumVertices]; for (int i = 0; i < ovrpMesh.NumVertices; ++i) { var currentBlendWeight = ovrpMesh.BlendWeights[i]; var currentBlendIndices = ovrpMesh.BlendIndices[i]; boneWeights[i].boneIndex0 = (int)currentBlendIndices.x; boneWeights[i].weight0 = currentBlendWeight.x; boneWeights[i].boneIndex1 = (int)currentBlendIndices.y; boneWeights[i].weight1 = currentBlendWeight.y; boneWeights[i].boneIndex2 = (int)currentBlendIndices.z; boneWeights[i].weight2 = currentBlendWeight.z; boneWeights[i].boneIndex3 = (int)currentBlendIndices.w; boneWeights[i].weight3 = currentBlendWeight.w; } _mesh.boneWeights = boneWeights; IsInitialized = true; } }
public Plane CreatePlane(byte faceIndex, bool redrawCall) { if (planes == null) { planes = new Dictionary <byte, Plane>(); } else { if (planes.ContainsKey(faceIndex)) { return(planes[faceIndex]); } } var pos = myBlock.pos; Plane p; if (faceIndex < 4) { MeshType mtype = MeshType.Quad; var f = Random.value; if (f < 0.8f) { if (f < 0.4f) { mtype = MeshType.StorageEntrance; } else { mtype = MeshType.StorageSide; } } else { mtype = MeshType.DoubleWindows; } var mp = new MultimaterialPlane(this, mtype, faceIndex, 0); mp.SetActivationStatus(isActive); p = mp; } else { if (faceIndex == Block.UP_FACE_INDEX && pos.y == Chunk.chunkSize - 1) { p = MeshMaster.GetRooftop(this, Random.value < 0.1f, true); } else { p = new Plane(this, MeshType.Quad, PoolMaster.MATERIAL_ADVANCED_COVERING_ID, faceIndex, 0); } } // planes.Add(faceIndex, p); if (redrawCall) { myBlock.myChunk.RefreshBlockVisualising(myBlock, faceIndex); } return(p); }
/// <summary> /// メッシュを生成する何か /// </summary> /// <param name="gen">作ったフラクタル</param> /// <param name="type">生成するメッシュの種類</param> /// <param name="magnitude">隆起の倍率</param> public MeshGenerator(LyapunovGenerator gen, MeshType type, float magnitude) { this.gen = gen; this.type = type; this.mesh = new Mesh(); this.magnitude = magnitude; CreateMesh(); }
private static int GetHashCode(MeshType type, int count) { if (type == MeshType.None) { return(0); } return(unchecked (1611625597 * (int)type + 1611624229 * count)); }
public void SetMeshType(MeshType meshType, bool recalculate = false) { ShapeMeshIndex = meshType; if (recalculate) { RecalculateMesh(); } }
public BlockpartVisualizeInfo(ChunkPos i_pos, MeshVisualizeInfo i_meshVI, MeshType i_meshType, int i_materialID, byte i_meshRotation) { pos = i_pos; meshInfo = i_meshVI; meshType = i_meshType; materialID = i_materialID; meshRotation = i_meshRotation; }
/// <summary> /// For creating shape objects /// </summary> /// <param name="type">the name of the object you wish to create</param> public MeshClass(MeshType type) { if (type == MeshType.Cube) { objectMesh = Mesh.CreateBox(DeviceManager.LocalDevice, 1f, 1f, 1f); objectMesh.ComputeNormals(); objectMesh.Optimize(MeshOptimizeFlags.Compact); ApplyColor(Color.White); } else if (type == MeshType.Triangle) { var ShapeVertices = new CustomVertex.VertexPositionColor[] { new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, 1f) }, new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, 1f) }, new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, -1f) }, new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, -1f) }, new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(0f, 1f, 0f) }, }; var ShapeIndices = new short[] { 0, 2, 1, // base 1, 2, 3, 0, 1, 4, // sides 1, 3, 4, 3, 2, 4, 2, 0, 4, }; objectMesh = new Mesh(DeviceManager.LocalDevice, ShapeIndices.Length, ShapeVertices.Length, MeshFlags.Managed, VertexFormat.Position | VertexFormat.Diffuse); objectMesh.LockVertexBuffer(LockFlags.None).WriteRange<CustomVertex.VertexPositionColor>(ShapeVertices); objectMesh.UnlockVertexBuffer(); objectMesh.LockIndexBuffer(LockFlags.None).WriteRange<short>(ShapeIndices); objectMesh.UnlockIndexBuffer(); Mesh other = objectMesh.Clone(DeviceManager.LocalDevice, MeshFlags.Managed, objectMesh.VertexFormat | VertexFormat.Normal | VertexFormat.Texture2); objectMesh.Dispose(); objectMesh = null; other.ComputeNormals(); objectMesh = other.Clone(DeviceManager.LocalDevice, MeshFlags.Managed, other.VertexFormat); other.Dispose(); objectMesh.Optimize(MeshOptimizeFlags.Compact); } ObjectPosition = Vector3.Zero; ObjectRotate = Vector3.Zero; ObjectScale = new Vector3(1, 1, 1); world = Matrix.Translation(ObjectPosition); Name = type.ToString(); IsShapeObject = true; }
void Update() { if (Input.GetMouseButtonDown(0)) { selectedFunc = LevelDesignUIManager.Instance.GetSelectedFunc(); ray = Camera.main.ScreenPointToRay(Input.mousePosition); // send out raycast to detect objects. if (Physics.Raycast(ray, out hit)) { mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePos = new Vector3(mousePos.x, 0, mousePos.z);//assign the create position. string tag = hit.transform.gameObject.tag; int carId = LevelDesignUIManager. Instance.GetSelectedCarId(); //Get selected mesh type MeshType meshType = LevelDesignUIManager. Instance.GetSelectedMeshType(); if (tag == Tags.PLANE) // check if raycast hitting user created object. { if (selectedFunc == FunctionType.Create) { if (meshType == MeshType.Car) { CreateCarMesh(mousePos, carId); } else { CreateObstacleMesh(mousePos, meshType); } } } else if (tag == Tags.WALL) { if (selectedFunc == FunctionType.Create) { CreateTargetMeshs(mousePos, carId); } } else if (tag == Tags.OBSTACLE) { if (selectedFunc == FunctionType.Delete) { DeleteObstacleMesh(hit.collider.gameObject); } } else if (tag == Tags.CAR || tag == Tags.TARGET) { if (selectedFunc == FunctionType.Delete) { DeleteCarOrTargetMesh(tag, carId); } } } } }
//------------------------------------------------------------------------- public static Mesh GenerateMesh(MeshType meshType, MeshQuality meshQuality, float density, int width, int height) { SilverMesh mesh = new SilverMesh(); silverGenerateMesh(meshType, meshQuality, density, width, height, out mesh); Mesh finalMesh = SilverMeshToUnityMesh(mesh); return(finalMesh); }
private void RemoveItem(MeshType type, uint steps) { itemsController.ChangeSelection(0); items.RemoveAt((int)items.Count - 1); OnEachViewDo(view => view.Invalidate()); // simple test for undo/redo undo.PrepareUndo(string.Format("Add {0}", type.ToDisplayString()), Invocation.Create(type, steps, AddItem)); }
private void AddItemDialog(MeshType type) { using (AddItemWithStepsDialog dlg = new AddItemWithStepsDialog()) { if (dlg.ShowDialog() == DialogResult.OK) { AddItem(type, dlg.Steps); } } }
public static Mesh GetMesh(MeshType mtype, int materialID) { Mesh m = Object.Instantiate(GetMeshSourceLink(mtype)); if (materialID != PoolMaster.FIXED_UV_BASIC) { SetMeshUVs(ref m, materialID); } return(m); }
public Mesh(OpenGL gl, MeshType type) { this.gl = gl; this.bufferCount = 0; Type = type; uint[] arrs = new uint[1]; gl.GenVertexArrays(1, arrs); ID = arrs[0]; }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void UpdateMesh(MeshType pType, MeshBuilder pMeshBuild, float pAmount=1) { if ( pType == MeshType.Edge ) { MeshUtil.BuildBorderMesh(pMeshBuild, vMeshW, vMeshH, EdgeThick); pMeshBuild.Commit(); return; } float inset = (pType != MeshType.Background ? EdgeThick*2 : 0); MeshUtil.BuildRectangleMesh(pMeshBuild, Math.Max(0, vMeshW-inset), Math.Max(0, vMeshH-inset), pAmount); pMeshBuild.Commit(); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void UpdateMesh(MeshType pType, MeshBuilder pMeshBuild, float pAmount=1) { if ( pType == MeshType.Edge ) { float edgeInner = (DrawOuterEdge ? vRadOuter : vRadInner-EdgeThick); float edgeOuter = (DrawOuterEdge ? vRadOuter+EdgeThick : vRadInner); MeshUtil.BuildRingMesh(pMeshBuild, edgeInner, edgeOuter, vAngle0, vAngle1, vMeshSteps); pMeshBuild.Commit(); return; } float radOuter = vRadInner+(vRadOuter-vRadInner)*pAmount; MeshUtil.BuildRingMesh(pMeshBuild, vRadInner, radOuter, vAngle0, vAngle1, vMeshSteps); pMeshBuild.Commit(); }
/*--------------------------------------------------------------------------------------------*/ protected abstract void UpdateMesh(MeshType pType, MeshBuilder pMeshBuild, float pAmount=1);
/// <summary> /// For creating shape objects /// </summary> /// <param name="type">the name of the object you wish to create</param> public MeshClass(MeshType type = MeshType.Cube) { if (type == MeshType.Cube) { ObjectMesh = Mesh.CreateBox(Engine.GameEngine.LocalDevice.ThisDevice, 1f, 1f, 1f); ObjectMesh.ComputeNormals(); ObjectMesh.Optimize(MeshOptimizeFlags.Compact); ApplyColor(Color.White); } else if (type == MeshType.Sphere) { ObjectMesh = Mesh.CreateSphere(Engine.GameEngine.LocalDevice.ThisDevice, .1f, 10, 10); ObjectMesh.ComputeNormals(); ObjectMesh.Optimize(MeshOptimizeFlags.Compact); ApplyColor(Color.White); } else if (type == MeshType.Teapot) { ObjectMesh = Mesh.CreateTeapot(Engine.GameEngine.LocalDevice.ThisDevice); ObjectMesh.ComputeNormals(); ObjectMesh.OptimizeInPlace(MeshOptimizeFlags.Compact); ApplyColor(Color.White); } else if (type == MeshType.Triangle) { VertexPositionColor[] ShapeVertices = new VertexPositionColor[] { new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, 1f) }, new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, 1f) }, new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, -1f) }, new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, -1f) }, new VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(0f, 1f, 0f) }, }; var ShapeIndices = new short[] { 0, 2, 1, // base 1, 2, 3, 0, 1, 4, // sides 1, 3, 4, 3, 2, 4, 2, 0, 4, }; ObjectMesh = new Mesh(Engine.GameEngine.LocalDevice.ThisDevice, ShapeIndices.Length, ShapeVertices.Length, MeshFlags.Managed, VertexPositionColor.Format); ObjectMesh.LockVertexBuffer(LockFlags.None).WriteRange<VertexPositionColor>(ShapeVertices); ObjectMesh.UnlockVertexBuffer(); ObjectMesh.LockIndexBuffer(LockFlags.None).WriteRange<short>(ShapeIndices); ObjectMesh.UnlockIndexBuffer(); Mesh other = ObjectMesh.Clone(Engine.GameEngine.LocalDevice.ThisDevice, MeshFlags.Managed, ObjectMesh.VertexFormat | VertexFormat.Normal | VertexFormat.Texture2); ObjectMesh.Dispose(); ObjectMesh = null; //other.ComputeNormals(); ObjectMesh = other.Clone(Engine.GameEngine.LocalDevice.ThisDevice, MeshFlags.Managed, other.VertexFormat); other.Dispose(); ObjectMesh.Optimize(MeshOptimizeFlags.Compact); ApplyColor(Color.White); } ObjectPosition = Vector3.Zero; ObjectRotate = Vector3.Zero; ObjectScale = new Vector3(1, 1, 1); _world = Matrix.Translation(ObjectPosition); IsShapeObject = true; }
public static bool ParseSize(string val, MeshType type, out int width, out int height) { val = val.Trim(); width = 10; height = 10; if (val.Length == 0) { if (type == MeshType.Octagon) { width = 5; height = 5; } else if (type == MeshType.Square2) { width = 5; height = 5; } else if (type == MeshType.Hexagonal) { width = 5; height = 10; } else if (type == MeshType.Hexagonal2) { width = 6; height = 6; } else if (type == MeshType.Hexagonal3) { width = 4; height = 4; } else if (type == MeshType.Triangle) { width = 6; height = 6; } else if (type == MeshType.Pentagon) { width = 6; height = 6; } return true; } string[] bits = val.Split('x'); if (bits.Length == 2) { if (!int.TryParse(bits[0], out width)) return false; if (!int.TryParse(bits[1], out height)) return false; return true; } else if (bits.Length == 1) { if (!int.TryParse(bits[0], out width)) return false; height = width; return true; } return false; }
public List<DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, ManType manType, string animationPath, bool needExporter) { var result = new List<DynamicRenderMesh>(); var objModel = ObjLoader.LoadObjFile(path, needExporter); if (objModel == null) { ProgramCore.EchoToLog(string.Format("Can't load obj model '{0}'", path), EchoMessageType.Error); return result; } switch (type) { case MeshType.Hair: { var fi = new FileInfo(path); var objModelNull = ObjLoader.LoadObjFile(Path.Combine(fi.DirectoryName, fi.Name.Replace(fi.Extension, string.Format("_null{0}", fi.Extension)))); if (objModelNull != null && (objModelNull.Groups.Count != objModel.Groups.Count || objModel.Vertices.Count != objModelNull.Vertices.Count)) // objModel.TextureCoords.Count != objModelNull.TextureCoords.Count)) objModelNull = null; result = LoadHairMeshes(objModel, objModelNull, fromDragAndDrop, manType, MeshType.Hair); foreach (var renderMesh in result) HairMeshes.Add(renderMesh); break; } case MeshType.Accessory: result.AddRange(objModel.accessoryByHeadShop ? LoadSpecialAccessoryMesh(objModel) : new List<DynamicRenderMesh> { LoadAccessoryMesh(objModel) }); break; case MeshType.Head: { var tempPluginTexture = string.Empty; if (ProgramCore.PluginMode) { var folderPath = Path.Combine(Application.StartupPath, "Models\\Model", manType.GetObjDirPath()); switch (ProgramCore.Project.ManType) { case ManType.Male: tempPluginTexture = Path.Combine(folderPath, "Maps", "RyNevio_faceB.jpg"); break; case ManType.Female: tempPluginTexture = Path.Combine(folderPath, "Maps", "RyBelle_face.jpg"); break; case ManType.Child: tempPluginTexture = Path.Combine(folderPath, "Maps", "AC_KidsRRHBy.jpg"); break; default: tempPluginTexture = Path.Combine(Application.StartupPath, "Plugin", "fsRndColor.png"); break; } } foreach (var mesh in HeadMeshes) mesh.Destroy(); HeadMeshes.Clear(); var objModelFull = animationPath == string.Empty ? null : ObjLoader.LoadObjFile(animationPath); if (objModelFull != null && (objModelFull.Groups.Count != objModel.Groups.Count || objModel.Vertices.Count != objModelFull.Vertices.Count || objModel.TextureCoords.Count != objModelFull.TextureCoords.Count)) objModelFull = null; LastTriangleIndex = 0; result = LoadHairMeshes(objModel, objModelFull, fromDragAndDrop, manType, MeshType.Head); var meshPartInfos = new List<MeshPartInfo>(); var a = new Vector3(99999.0f, 99999.0f, 99999.0f); var b = new Vector3(-99999.0f, -99999.0f, -99999.0f); foreach (var renderMesh in result) { HeadMeshes.Add(renderMesh); if (ProgramCore.PluginMode && ProgramCore.MainForm.PluginUvGroups.Contains(renderMesh.Material.Name)) { if (string.IsNullOrEmpty(renderMesh.Material.DiffuseTextureMap)) renderMesh.Material.DiffuseTextureMap = tempPluginTexture; else if (!File.Exists(renderMesh.Material.DiffuseTextureMap)) renderMesh.Material.DiffuseTextureMap = tempPluginTexture; } var meshPartInfo = new MeshPartInfo { VertexPositions = renderMesh.GetVertices(), TextureCoords = renderMesh.GetTexCoords(), PartName = renderMesh.Title, Color = renderMesh.Material.DiffuseColor, Texture = renderMesh.Material.Texture, TransparentTexture = renderMesh.Material.TransparentTexture, TextureName = renderMesh.Material.DiffuseTextureMap, TransparentTextureName = renderMesh.Material.TransparentTextureMap }; // создаем инфу о голове. для работы с headshop GetAABB(ref a, ref b, meshPartInfo.VertexPositions); meshPartInfos.Add(meshPartInfo); } var dv = Vector3.Zero; foreach (var meshPartInfo in meshPartInfos) { dv = MoveToPosition(ref meshPartInfo.VertexPositions, a, b, Vector3.Zero); ProgramCore.MainForm.ctrlRenderControl.headMeshesController.CreateMeshPart(meshPartInfo); } ObjExport = objModel.ObjExport; if (ObjExport != null) ObjExport.Delta = -dv; ProgramCore.MainForm.ctrlRenderControl.headMeshesController.FinishCreating(); // ProgramCore.MainForm.ctrlRenderControl.headMeshesController.InitializeTexturing(HeadController.GetDots(ProgramCore.Project.ManType), HeadController.GetIndices(ProgramCore.Project.ManType)); break; } default: return result; } foreach (var item in result) item.Path = path; return result; }
private void AddItem(MeshType type, uint steps) { Item item = new Item(); item.GetMesh().MakeMesh(type, steps); itemsController.ChangeSelection(0); item.Selected = 1; items.AddItem(item); itemsController.UpdateSelection(); OnEachViewDo(view => view.Invalidate()); undo.PrepareUndo(string.Format("Add {0}", type.ToDisplayString()), Invocation.Create(type, steps, RemoveItem)); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void UpdateMesh(MeshType pType, Mesh pMesh, float pAmount=1) { MeshUtil.BuildRectangleMesh(pMesh, vMeshW, vMeshH, pAmount); }
/// <summary> /// Obtains a reference to a specified type of mesh for this extrusion. /// </summary> /// <param name="meshType">The mesh type.</param> /// <returns>A mesh.</returns> public Mesh GetMesh(MeshType meshType) { IntPtr ptr_const_this = ConstPointer(); IntPtr ptr_const_mesh = UnsafeNativeMethods.ON_Extrusion_GetMesh(ptr_const_this, (int)meshType); if (IntPtr.Zero == ptr_const_mesh) return null; return CreateGeometryHelper(ptr_const_mesh, new MeshHolder(this, meshType)) as Mesh; }
public GenerateResponse(int messageNumber, Connection connection, byte[] messageBody) : base(MessageType.GenerateResponse, messageNumber, connection) { MemoryStream stream = new MemoryStream(messageBody); BinaryReader reader = new BinaryReader(stream); MeshType = (MeshType)reader.ReadInt32(); int startCount = reader.ReadInt32(); StartLines = new string[startCount]; for (int i = 0; i < startCount; i++) { StartLines[i] = reader.ReadString(); } int endCount = reader.ReadInt32(); EndLines = new string[endCount]; for (int i = 0; i < endCount; i++) { EndLines[i] = reader.ReadString(); } }
public static void SaveObjFile(string filePath, List<MeshInfo> meshInfos, MeshType type, ObjExport objExport, bool saveBrushesToTexture, bool isCollada) { if (objExport == null) { SaveObjFile(filePath, meshInfos, type, saveBrushesToTexture, isCollada); return; } var fi = new FileInfo(filePath); if (fi.Exists) fi.Delete(); if (fi.DirectoryName == null) return; var mtlPath = Path.Combine(fi.DirectoryName, Path.GetFileNameWithoutExtension(fi.Name) + ".mtl"); var fiMtl = new FileInfo(mtlPath); //if (fiMtl.Exists) // fiMtl.Delete(); var groupIndex = 0; var materials = new Dictionary<string, ObjMaterial>(); var startPositionIndex = 1; var startTexIndex = 1; var startNormalIndex = 1; var indicesPositions = new List<int>(); var indicesTexCoords = new List<int>(); var indicesNormals = new List<int>(); var positions = new List<Vector3>(); var normals = new List<Vector3>(); var texCoords = new List<Vector2>(); foreach (var meshInfo in meshInfos) // faces should write differently { if (meshInfo.IndicesNormals.Count == 0) continue; String groupTitle; if (string.IsNullOrEmpty(meshInfo.Title)) { groupTitle = "Element_" + groupIndex; while (materials.ContainsKey(groupTitle)) { ++groupIndex; groupTitle = "Element_" + groupIndex; } ++groupIndex; } else groupTitle = meshInfo.Title; materials.Add(groupTitle, meshInfo.Material); for (var i = 0; i < meshInfo.IndicesTexCoords.Count; i++) { indicesPositions.Add(startPositionIndex + meshInfo.IndicesPositions[i]); indicesTexCoords.Add(startTexIndex + meshInfo.IndicesTexCoords[i]); indicesNormals.Add(startNormalIndex + meshInfo.IndicesNormals[i]); } startPositionIndex += (meshInfo.IndicesPositions.Max() + 1); startTexIndex += (meshInfo.IndicesTexCoords.Max() + 1); startNormalIndex += (meshInfo.IndicesNormals.Max() + 1); positions.AddRange(meshInfo.Positions); normals.AddRange(meshInfo.Normals); texCoords.AddRange(meshInfo.TexCoords); } foreach (var face in objExport.Faces) { var index = face.TriangleIndex0 * 3; for (var l = 0; l < 3; l++) { var v = positions[indicesPositions[index + l] - 1]; var vn = normals[indicesNormals[index + l] - 1]; var vt = texCoords[indicesTexCoords[index + l] - 1]; objExport.SetData(v, vt, vn, face, l); } if (face.VertexCount == 4) { index = face.TriangleIndex1 * 3; var v = positions[indicesPositions[index + 1] - 1]; var vn = normals[indicesNormals[index + 1] - 1]; var vt = texCoords[indicesTexCoords[index + 1] - 1]; objExport.SetData(v, vt, vn, face, 3); } } using (var sw = new StreamWriter(filePath, false, Encoding.Default)) { sw.WriteLine("#Produced by HeadShop"); sw.WriteLine(type == MeshType.Accessory ? "#Accessories" : "#HeadShop Model"); sw.WriteLine("#" + DateTime.Now.ToShortDateString()); sw.WriteLine("mtllib " + fiMtl.Name); sw.WriteLine(); foreach (var v in objExport.Vertices) { var resStr = "v " + v.X.ToString(ProgramCore.Nfi) + " " + v.Y.ToString(ProgramCore.Nfi) + " " + v.Z.ToString(ProgramCore.Nfi); sw.WriteLine(resStr); } foreach (var vt in objExport.TexCoords) { var resStr = "vt " + vt.X.ToString(ProgramCore.Nfi) + " " + vt.Y.ToString(ProgramCore.Nfi); sw.WriteLine(resStr); } foreach (var vn in objExport.Normals) { var resStr = "vn " + vn.X.ToString(ProgramCore.Nfi) + " " + vn.Y.ToString(ProgramCore.Nfi) + " " + vn.Z.ToString(ProgramCore.Nfi); sw.WriteLine(resStr); } var prevGroup = String.Empty; foreach (var materialGroup in objExport.MaterialsGroups) { if (materialGroup.Groups.Count == 0 || !materialGroup.Groups[0].IsValid) continue; for (var i = 0; i < materialGroup.Groups.Count; i++) { var group = materialGroup.Groups[i]; if (!group.IsValid) continue; if (!prevGroup.Equals(group.Group)) { sw.WriteLine("g " + group.Group); prevGroup = group.Group; } if (i == 0) sw.WriteLine("usemtl " + materialGroup.Material); for (var j = group.StartFaceIndex; j <= group.EndFaceIndex; j++) { var face = objExport.Faces[j]; var resStr = "f "; foreach (var vertex in face.FaceVertices) { resStr += (vertex.VertexIndex).ToString(ProgramCore.Nfi); if (objExport.TexCoords.Count > 0) resStr += "/" + (vertex.TextureIndex).ToString(ProgramCore.Nfi); if (objExport.Normals.Count > 0) resStr += "/" + (vertex.NormalIndex).ToString(ProgramCore.Nfi); resStr += " "; } sw.WriteLine(resStr.Remove(resStr.Length - 1)); } } } } // SaveMaterial(mtlPath, materials, fi); }
public static void SaveObjFile(string filePath, List<MeshInfo> meshInfos, MeshType type, bool saveBrushesToTexture, bool isCollada) { if (meshInfos.Count == 0) return; var fi = new FileInfo(filePath); if (fi.Exists) fi.Delete(); var mtlPath = Path.Combine(fi.DirectoryName, Path.GetFileNameWithoutExtension(fi.Name) + ".mtl"); var fiMtl = new FileInfo(mtlPath); if (fiMtl.Exists) fiMtl.Delete(); var materials = new Dictionary<string, ObjMaterial>(); // group title, diffuse color, texture path using (var sw = new StreamWriter(filePath, false, Encoding.Default)) { sw.WriteLine("#Produced by HeadShop"); if (type == MeshType.Accessory) sw.WriteLine("#Accessories"); else sw.WriteLine("#HeadShop Model"); sw.WriteLine("#" + DateTime.Now.ToShortDateString()); sw.WriteLine("mtllib " + fiMtl.Name); sw.WriteLine(); SaveVerticles(meshInfos, sw, Matrix4.Zero); SaveTextureCoords(meshInfos, sw); SaveNormals(meshInfos, sw, Matrix4.Zero); var groupIndex = 0; var startPositionIndex = 1; var startTexIndex = 1; var startNormalIndex = 1; foreach (var meshInfo in meshInfos) // faces should write differently { if (meshInfo.IndicesNormals.Count == 0) continue; var groupTitle = string.Empty; if (string.IsNullOrEmpty(meshInfo.Title)) { groupTitle = "Element_" + groupIndex; while (materials.ContainsKey(groupTitle)) { ++groupIndex; groupTitle = "Element_" + groupIndex; } ++groupIndex; } else groupTitle = meshInfo.Title; materials.Add(groupTitle, meshInfo.Material); sw.WriteLine("g " + groupTitle); sw.WriteLine("usemtl " + groupTitle); #region Faces var resStr = "f "; var index = 0; for (var i = 0; i < meshInfo.IndicesTexCoords.Count; i++) { resStr += (startPositionIndex + meshInfo.IndicesPositions[i]).ToString(ProgramCore.Nfi) + "/"; resStr += (startTexIndex + meshInfo.IndicesTexCoords[i]).ToString(ProgramCore.Nfi) + "/"; resStr += (startNormalIndex + meshInfo.IndicesNormals[i]).ToString(ProgramCore.Nfi) + " "; ++index; if (index == 3) { index = 0; sw.WriteLine(resStr.Remove(resStr.Length - 1)); resStr = "f "; } } startPositionIndex += (meshInfo.IndicesPositions.Max() + 1); startTexIndex += (meshInfo.IndicesTexCoords.Max() + 1); startNormalIndex += (meshInfo.IndicesNormals.Max() + 1); #endregion } } SaveMaterial(mtlPath, materials, fi, saveBrushesToTexture, isCollada); }
public static void SaveObjFile(string filePath, DynamicRenderMeshes meshes, MeshType type, float scale, bool saveBrushesToTexture = false, bool isCollada = false) { var meshInfos = new List<MeshInfo>(); foreach (var mesh in meshes) { var meshInfo = mesh.GetMeshInfo(scale); meshInfos.Add(meshInfo); } SaveObjFile(filePath, meshInfos, type, saveBrushesToTexture, isCollada); }
public static void SaveObjFile(string filePath, RenderMesh mesh, MeshType type, ObjExport objExport, bool saveBrushesToTexture = false, bool isCollada = false) { var meshInfos = new List<MeshInfo>(); foreach (var part in mesh.Parts) meshInfos.Add(new MeshInfo(part, mesh.MorphScale)); SaveObjFile(filePath, meshInfos, type, objExport, saveBrushesToTexture, isCollada); }
public static void SaveObjFile(string filePath, RenderMesh mesh, MeshType type, bool saveBrushesToTexture = false) { SaveObjFile(filePath, mesh, type, null, saveBrushesToTexture); }
public BoardDetailsBroadcast(int messageNumber, Connection connection, byte[] messageBody) : base(MessageType.BoardDetailsBroadcast, messageNumber, connection) { MemoryStream stream = new MemoryStream(messageBody); BinaryReader reader = new BinaryReader(stream); MeshType = (MeshType)reader.ReadInt32(); int startCount = reader.ReadInt32(); StartLines = new string[startCount]; for (int i = 0; i < startCount; i++) { StartLines[i] = reader.ReadString(); } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ protected override void UpdateMesh(MeshType pType, MeshBuilder pMeshBuild, float pAmount=1) { MeshUtil.BuildRectangleMesh(pMeshBuild, vMeshW, vMeshH, pAmount); pMeshBuild.Commit(); }
internal void InitialBoardDataReceived(string[] startLines, MeshType meshType) { if (InitialBoardDataBroadcast != null) InitialBoardDataBroadcast(this, new BoardDataEventArgs(startLines, meshType)); }
/// <summary> /// Transforms all vertices in a given mesh to their correct positions. /// </summary> /// <param name="Msh">The mesh to transform.</param> /// <param name="bone">The bone to transform to.</param> private void TransformVertices(Mesh Msh, Bone bone, MeshType MshType) { switch (MshType) { case MeshType.Head: for (int i = 0; i < Msh.TotalVertexCount; i++) { //Transform the head vertices' position by the absolute transform //for the headbone (which is always bone 17) to render the head in place. Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position, Skel.Bones[16].AbsoluteMatrix); Msh.TransformedVertices[i].TextureCoordinate = Msh.RealVertices[i].TextureCoordinate; //Transform the head normals' position by the absolute transform //for the headbone (which is always bone 17) to render the head in place. Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal, Skel.Bones[16].AbsoluteMatrix); } return; case MeshType.Body: BoneBinding boneBinding = Msh.BoneBindings.FirstOrDefault(x => Msh.Bones[(int)x.BoneIndex] == bone.Name); if (boneBinding != null) { for (int i = 0; i < boneBinding.RealVertexCount; i++) { int vertexIndex = (int)boneBinding.FirstRealVertexIndex + i; VertexPositionNormalTexture relativeVertex = Msh.RealVertices[vertexIndex]; Matrix translatedMatrix = Matrix.CreateTranslation(new Vector3(relativeVertex.Position.X, relativeVertex.Position.Y, relativeVertex.Position.Z)) * bone.AbsoluteMatrix; Msh.TransformedVertices[vertexIndex].Position = Vector3.Transform(Vector3.Zero, translatedMatrix); Msh.TransformedVertices[vertexIndex].TextureCoordinate = relativeVertex.TextureCoordinate; //Normals... translatedMatrix = Matrix.CreateTranslation(new Vector3(relativeVertex.Normal.X, relativeVertex.Normal.Y, relativeVertex.Normal.Z)) * bone.AbsoluteMatrix; Msh.TransformedVertices[vertexIndex].Normal = Vector3.Transform(Vector3.Zero, translatedMatrix); } } foreach (var child in bone.Children) TransformVertices(Msh, child, MshType); break; case MeshType.LHand: for (int i = 0; i < Msh.TotalVertexCount; i++) { //Transform the left hand vertices' position by the absolute transform //for the left handbone (which is always bone 10) to render the left hand in place. Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position, Skel.Bones[9].AbsoluteMatrix); //Transform the left hand normals' position by the absolute transform //for the left handbone (which is always bone 10) to render the left hand in place. Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal, Skel.Bones[9].AbsoluteMatrix); } return; case MeshType.RHand: for (int i = 0; i < Msh.TotalVertexCount; i++) { //Transform the right hand vertices' position by the absolute transform //for the right handbone (which is always bone 15) to render the right hand in place. Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position, Skel.Bones[14].AbsoluteMatrix); //Transform the right hand normals' position by the absolute transform //for the right handbone (which is always bone 15) to render the right hand in place. Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal, Skel.Bones[14].AbsoluteMatrix); } return; } }
public BoardDataEventArgs(string[] lines, MeshType meshType) { this.Lines = lines; this.MeshType = meshType; }
public List<DynamicRenderMesh> AddMehes(string path, MeshType type, bool fromDragAndDrop, ManType manType, bool needExporter) { return AddMehes(path, type, fromDragAndDrop, manType, string.Empty, needExporter); }
internal static string StringFromMeshType(MeshType value) { switch (value) { case MeshType.Square: return "Square"; case MeshType.SquareSymmetrical: return "Square Symmetrical"; case MeshType.Triangle: return "Triangle"; case MeshType.Hexagonal: return "Hexagon"; case MeshType.Hexagonal2: return "Hexagon2"; case MeshType.Hexagonal3: return "Hexagon3"; case MeshType.Octagon: return "Octagon"; case MeshType.Square2: return "Square2"; case MeshType.Pentagon: return "Pentagon"; } return "Square"; }
public void LoadModel(string path, bool needClean, ManType manType, MeshType type) { if (needClean) CleanProjectMeshes(); pickingController.AddMehes(path, type, false, manType, false); }
private List<DynamicRenderMesh> LoadHairMeshes(ObjItem objModel, ObjItem objModelNull, bool fromDragAndDrop, ManType manType, MeshType meshType) { var result = new List<DynamicRenderMesh>(); var vertexPositions = new List<float>(); var vertexNormals = new List<float>(); var vertexTextureCoordinates = new List<float>(); var vertexBoneIndices = new List<float>(); var vertexBoneWeights = new List<float>(); var indeces = new List<uint>(); var vertexPositionsNull = new List<float>(); var vertexNormalsNull = new List<float>(); var vertexTextureCoordinatesNull = new List<float>(); var vertexBoneIndicesNull = new List<float>(); var vertexBoneWeightsNull = new List<float>(); var indecesNull = new List<uint>(); var groupsNull = objModelNull == null ? new Dictionary<ObjMaterial, ObjGroup>.Enumerator() : objModelNull.Groups.GetEnumerator(); ObjGroup groupNull; foreach (var modelGroup in objModel.Groups) // one group - one mesh { vertexPositions.Clear(); vertexNormals.Clear(); vertexTextureCoordinates.Clear(); vertexBoneIndices.Clear(); vertexBoneWeights.Clear(); indeces.Clear(); foreach (var face in modelGroup.Value.Faces) // combine all meshes in group - to one mesh. GetObjFace(face, objModel, ref vertexPositions, ref vertexNormals, ref vertexTextureCoordinates, ref vertexBoneWeights, ref vertexBoneIndices, ref indeces); var renderMesh = new DynamicRenderMesh(meshType); renderMesh.groupName = modelGroup.Value.Name; if (!objModel.modelByHeadShop) { for (var i = 0; i < vertexPositions.Count / 3; i++) vertexPositions[i * 3 + 1] = vertexPositions[i * 3 + 1] - 0.0060975609f; } ProgramCore.EchoToLog(String.Format("RenderMesh: {0}", modelGroup.Value.Name), EchoMessageType.Information); ProgramCore.EchoToLog( String.Format("renderMesh.Create: {0}, {1}, {2}, {3}, {4}", vertexPositions.Count, vertexTextureCoordinates.Count, vertexBoneIndices.Count, vertexBoneWeights.Count, indeces.Count), EchoMessageType.Information); if (renderMesh.Create(vertexPositions, vertexTextureCoordinates, vertexBoneIndices, vertexBoneWeights, indeces, string.Empty, string.Empty)) { if (objModelNull != null) { groupsNull.MoveNext(); groupNull = groupsNull.Current.Value; vertexPositionsNull.Clear(); vertexNormalsNull.Clear(); vertexTextureCoordinatesNull.Clear(); vertexBoneWeightsNull.Clear(); vertexBoneIndicesNull.Clear(); indecesNull.Clear(); foreach (var face in groupNull.Faces) { GetObjFace(face, objModelNull, ref vertexPositionsNull, ref vertexNormalsNull, ref vertexTextureCoordinatesNull, ref vertexBoneWeightsNull, ref vertexBoneIndicesNull, ref indecesNull); } renderMesh.SetNullPoints(vertexPositionsNull, vertexNormalsNull, vertexTextureCoordinatesNull); } renderMesh.Title = modelGroup.Key.Name == "default" ? string.Empty : modelGroup.Key.Name; renderMesh.Material = modelGroup.Key; renderMesh.Material.DiffuseColor = new Vector4(modelGroup.Key.DiffuseColor.X, modelGroup.Key.DiffuseColor.Y, modelGroup.Key.DiffuseColor.Z, modelGroup.Key.Transparency); if (!string.IsNullOrEmpty(modelGroup.Key.DiffuseTextureMap)) renderMesh.Material.DiffuseTextureMap = modelGroup.Key.DiffuseTextureMap; if (!string.IsNullOrEmpty(modelGroup.Key.TransparentTextureMap)) renderMesh.Material.TransparentTextureMap = modelGroup.Key.TransparentTextureMap; var scale = meshType == MeshType.Head ? GetHeadScale(manType) : GetHairScale(manType); // перегруз сделан потому, что на этапе загрузки проекта самого проекта еще может не быть. поэтому лучше передавать renderMesh.Transform = Matrix4.CreateScale(scale); var center = Vector3.Zero; var count = vertexPositions.Count / 3; for (var i = 0; i < count; i++) { center.X += vertexPositions[i * 3] * scale; center.Y += vertexPositions[i * 3 + 1] * scale; center.Z += vertexPositions[i * 3 + 2] * scale; } if (fromDragAndDrop) { center /= count; renderMesh.Transform = Matrix4.CreateScale(scale); renderMesh.Transform[3, 0] = -center.X; renderMesh.Transform[3, 1] = -center.Y; renderMesh.Transform[3, 2] = -center.Z; renderMesh.Position = center; } if (vertexTextureCoordinates.Count > 0 && vertexTextureCoordinates.All(x => x == 0)) renderMesh.UpdateTextureCoordinates(0, 1); if (renderMesh.vertexArray.Length > 0) result.Add(renderMesh); } } return result; }
/*--------------------------------------------------------------------------------------------*/ protected abstract void UpdateMesh(MeshType pType, Mesh pMesh, float pAmount=1);