public MaterialColorMorph( IMeshObject parent, MaterialColorMorphDefinition definition, ILoggerFactory loggerFactory) : base(definition, loggerFactory) { Ensure.That(parent, nameof(parent)).IsNotNull(); Parent = parent; }
public static AABB CalculateBounds(this IMeshObject source) { Ensure.That(source, nameof(source)).IsNotNull(); Debug.Assert(source.Meshes != null, "source.Meshes != null"); return(source.Meshes.Any() ? source.Meshes.Map(m => m.GetAabb()).Aggregate((b1, b2) => b1.Merge(b2)) : new AABB(source.Origin(), Vector3.Zero)); }
public BlendShapeMorph( IMeshObject parent, BlendShapeMorphDefinition definition, ILoggerFactory loggerFactory) : base(definition, loggerFactory) { Ensure.That(parent, nameof(parent)).IsNotNull(); Parent = parent; BlendShapePaths = definition.BlendShapes.Map(v => "blend_shapes/" + v).Freeze(); }
public bool AddObject(IMeshObject obj, bool updateBuffers) { // check if we have too much vertices if (_vertices + obj.Vertices.Count > 65535) return false; _vertices += obj.Vertices.Count; _groundMeshs.First().AddObject(obj, updateBuffers); return true; }
// Use this for initialization void Start() { o = GetComponent <IMeshObject>(); id = counter++; //o = new IMeshObject //{ // gameObject = gameObject, // mode = MeshMode.MeshFilterMode, // transform = transform, //}; DefaultVoxManager.objs.Add(o); Debug.Log("mover" + o); }
public void AddObject(IMeshObject obj, bool updateBuffers = true ) { if (_vertices.Count == 0) { _vertices = obj.Vertices; _indices = obj.Indices; } else { var maxVertexIndex = (short)_vertices.Count; _vertices.AddRange(obj.Vertices); obj.Indices.ForEach(idx => _indices.Add((short)(idx + maxVertexIndex))); } if (updateBuffers) UpdateBuffers(); }
private void CalcTexture(float width = 1.0f, float height = 1.0f) { w = (int)(Screen.width * width); h = (int)(Screen.height * height); Camera c = new GameObject("Camera").AddComponent <Camera>(); c.CopyFrom(Camera); c.clearFlags = CameraClearFlags.Nothing; c.cullingMask = 64; c.allowMSAA = false; renders.Clear(); int count = 0; foreach (ISelectObject o in SelectObjects) { if (count > 65534) { break; } if (1 - Vector3.Dot((o.transform.position - c.transform.position).normalized, c.transform.forward) < c.fieldOfView / 180) { renders._Add(o); IMeshObject m = o as IMeshObject; if (m != null) { for (int i = 0; i < m.Meshs.Length; i++) { Mesh mesh = m.Meshs[i].sharedMesh; if (mesh != null) { for (int _i = 0; _i < mesh.subMeshCount; _i++) { Graphics.DrawMesh(mesh, m.Meshs[i].transform.localToWorldMatrix, drawObject.Object, 6, c, _i, blocks[count], false, false, false); } } } } ISkinObject s = o as ISkinObject; if (s != null) { for (int i = 0; i < s.Skins.Length; i++) { Mesh _s = new Mesh(); s.Skins[i].BakeMesh(_s); for (int _i = 0; _i < _s.subMeshCount; _i++) { Graphics.DrawMesh(_s, s.Skins[i].transform.localToWorldMatrix, drawObject.Object, 6, c, _i, blocks[count], false, false, false); } GameObject.Destroy(_s); } } IIconObject n = o as IIconObject; if (n != null) { if (n.Icon != null) { Quaternion rota = Quaternion.LookRotation(Vector3.Normalize(n.transform.position - Camera.transform.position), Vector3.up); Graphics.DrawMesh(Tools.Quad, n.transform.position, rota, drawObject.Object, 6, c, 0, blocks[count], false, false, false); } } count++; } } RenderTexture rtex = new RenderTexture(w, h, 0); c.targetTexture = rtex; c.Render(); RenderTexture current = RenderTexture.active; RenderTexture.active = c.activeTexture; if (tex != null) { GameObject.Destroy(tex); tex = null; } tex = new Texture2D(w, h); tex.ReadPixels(new Rect(0, 0, w, h), 0, 0); tex.Apply(); RenderTexture.active = current; GameObject.Destroy(rtex); GameObject.Destroy(c.gameObject); }
void Start() { impl = new MeshNormalObjectImpl(transform); }
public void AddObject(int index, IMeshObject obj, bool updateBuffers = true) { //log.InfoFormat("AddTexture({0}, ...)", index); TiledMeshItem item = _items.LastOrDefault(); if (!item.AddObject(obj, updateBuffers)) { TiledMeshItem newItem = new TiledMeshItem(_manager, _internCounter); newItem.AddObject(obj, updateBuffers); _items.Add(newItem); } }
void vox(IMeshObject obj) { Mesh mesh = null; Material[] mats = null; mesh = obj.MeshObjectGetMesh(); mats = obj.MeshObjectGetMaterials(); // tris int[] tris = mesh.triangles; int lentris = mesh.triangles.Length; for (int i = 0; i < lentris; i++) { unsafe { tribuf[numtris + i] = numverts + tris[i]; } } numtris += lentris; // vertices var vertices = mesh.vertices; int vertidx = 0; int vertslen = vertices.Length; for (int i = 0; i < vertslen; i++) { Vector3 vert1 = obj.MeshObjectTransformPoint(vertices[i]); // + translationFromZeroCenter; vertidx = 3 * (numverts + i); unsafe { vertbuf[vertidx + 0] = vert1.x; vertbuf[vertidx + 1] = vert1.y; vertbuf[vertidx + 2] = vert1.z; } } numverts += vertices.Length; // trimats or color from texture if (mats[0].mainTexture == null) { int lensubmats = mesh.subMeshCount; for (int i = 0; i < lensubmats; i++) { int[] indices = mesh.GetIndices(i); int indicesLen = indices.Length / 3; for (int j = 0; j < indicesLen; j++) { unsafe { trimatbuf[j + numtrimats] = nummats + i; } } numtrimats += indicesLen; } } else { int lensubmats = mesh.subMeshCount; for (int i = 0; i < lensubmats; i++) { Texture2D t2d = mats[i].mainTexture as Texture2D; Vector2[] uv = mesh.uv; Vector2 target = new Vector2(); lentris /= 3; Color targetColor; int c; int[] indices = mesh.GetIndices(i); int indicesLen = indices.Length / 3; for (int j = 0; j < indicesLen; j++) { target = uv[indices[3 * j + 0]] + uv[indices[3 * j + 1]] + uv[indices[3 * j + 2]]; target /= 3; targetColor = t2d.GetPixelBilinear(target.x, target.y); c = ((int)(255f * targetColor.r)) << 16; c |= ((int)(255f * targetColor.g)) << 8; c |= ((int)(255f * targetColor.b)); unsafe { trimatbuf[j + numtrimats] = 0x7f000000 | c; } } numtrimats += indicesLen; } } // mats int intcolor, lenmats = mats.Length; Color color; for (int i = 0; i < lenmats; i++) { color = mats[i].color; intcolor = 0; intcolor |= ((int)(color.r * 255)) << 16; intcolor |= ((int)(color.g * 255)) << 8; intcolor |= ((int)(color.b * 255)); unsafe { colorbuf[nummats + i + 1] = intcolor; } } nummats += mats.Length; }
void Start() { impl = new MeshSkinObjectImpl(transform); }
public static AABB CalculateBounds([NotNull] this IMeshObject source) { Ensure.Any.IsNotNull(source, nameof(source)); return(source.Meshes.Select(m => m.GetAabb()).Aggregate((b1, b2) => b1.Merge(b2))); }