Ejemplo n.º 1
0
        private GameObject FindOrCreate(string name)
        {
            var        childTransform = generated.transform.Find(name);
            GameObject res;

            if (childTransform == null)
            {
                res = UOUtility.Create(name,
                                       generated,
                                       typeof(MeshFilter),
                                       typeof(MeshRenderer),
                                       typeof(MeshBender),
                                       typeof(MeshCollider));
                res.isStatic = true;
            }
            else
            {
                res = childTransform.gameObject;
            }
            res.GetComponent <MeshRenderer>().material = material;
            res.GetComponent <MeshCollider>().material = physicMaterial;
            MeshBender mb = res.GetComponent <MeshBender>();

            mb.Source = SourceMesh.Build(mesh)
                        .Translate(translation)
                        .Rotate(Quaternion.Euler(rotation))
                        .Scale(scale);
            mb.Mode = mode;
            return(res);
        }
Ejemplo n.º 2
0
        private void Init()
        {
            string generatedName     = "generated by " + GetType().Name;
            var    generatedTranform = transform.Find(generatedName);

            generated = generatedTranform != null ? generatedTranform.gameObject : UOUtility.Create(generatedName, gameObject,
                                                                                                    typeof(MeshFilter),
                                                                                                    typeof(MeshRenderer),
                                                                                                    typeof(MeshBender));

            generated.GetComponent <MeshRenderer>().material = material;

            if (generated.GetComponent <DecrepitEffect>() == null)
            {
                generated.AddComponent <DecrepitEffect>();
            }
            meshBender = generated.GetComponent <MeshBender>();
            spline     = GetComponent <Spline>();

            meshBender.Source = SourceMesh.Build(mesh)
                                .Rotate(Quaternion.Euler(rotation))
                                .Scale(scale);
            meshBender.Mode = MeshBender.FillingMode.StretchToInterval;
            meshBender.SetInterval(spline, 0, 0.01f);
        }
Ejemplo n.º 3
0
        private GameObject FindOrCreate(string name)
        {
            var        childTransform = generated.transform.Find(name);
            GameObject res;

            if (childTransform == null)
            {
                res = UOUtility.Create(name,
                                       generated,
                                       typeof(MeshFilter),
                                       typeof(MeshRenderer),
                                       typeof(MeshBender),
                                       typeof(MeshCollider));
                res.isStatic = !updateInPlayMode;
            }
            else
            {
                res = childTransform.gameObject;
            }
            res.GetComponent <MeshRenderer>().material = material;
            res.GetComponent <MeshCollider>().material = physicMaterial;
            MeshBender mb = res.GetComponent <MeshBender>();

            mb.Source = SourceMesh.Build(mesh)
                        .Translate(translation)
                        .Rotate(Quaternion.Euler(rotation))
                        .Scale(scale);
            if (null != extraMeshes && 0 < extraMeshes.Length)
            {
                List <Material> materials = new List <Material>();
                materials.Add(material);

                SourceMesh[] extraSourceMeshes = new SourceMesh[extraMeshes.Length];
                for (int i = 0; i < extraMeshes.Length; ++i)
                {
                    var T = translation;
                    var R = rotation;
                    var S = scale;
                    if (extraMeshes[i].useCustomTRS)
                    {
                        T = extraMeshes[i].customTranslation;
                        R = extraMeshes[i].customRotation;
                    }
                    extraSourceMeshes[i] = SourceMesh.Build(extraMeshes[i].mesh)
                                           .Translate(T)
                                           .Rotate(Quaternion.Euler(R))
                                           .Scale(S);
                    extraSourceMeshes[i].placeType   = extraMeshes[i].placeType;
                    extraSourceMeshes[i].placeWeight = extraMeshes[i].placeWeight;
                    materials.Add(extraMeshes[i].material);
                }
                Array.Sort(extraSourceMeshes, (x, y) => (int)x.placeType - (int)y.placeType);
                mb.ExtraSources = extraSourceMeshes;
                res.GetComponent <MeshRenderer>().materials = materials.ToArray();
            }
            mb.Mode = mode;
            return(res);
        }
Ejemplo n.º 4
0
        public void CreateMeshes()
        {
            List <GameObject> used = new List <GameObject>();

            for (int i = 0; i < spline.GetCurves().Count; i++)
            {
                var curve = spline.GetCurves()[i];
                foreach (var tm in segments[i].transformedMeshes)
                {
                    if (tm.mesh == null)
                    {
                        // if there is no mesh specified for this segment, we ignore it.
                        continue;
                    }

                    // we try to find a game object previously generated. this avoids destroying/creating
                    // game objects at each update, wich is faster.
                    var        childName      = "segment " + i + " mesh " + segments[i].transformedMeshes.IndexOf(tm);
                    var        childTransform = generated.transform.Find(childName);
                    GameObject go;
                    if (childTransform == null)
                    {
                        go = UOUtility.Create(childName,
                                              generated,
                                              typeof(MeshFilter),
                                              typeof(MeshRenderer),
                                              typeof(MeshBender),
                                              typeof(MeshCollider));
                        go.isStatic = true;
                    }
                    else
                    {
                        go = childTransform.gameObject;
                    }
                    go.GetComponent <MeshRenderer>().material = tm.material;
                    go.GetComponent <MeshCollider>().material = tm.physicMaterial;

                    // we update the data in the bender. It will decide itself if the bending must be recalculated.
                    MeshBender mb = go.GetComponent <MeshBender>();
                    mb.Source      = tm.mesh;
                    mb.Curve       = curve;
                    mb.Translation = tm.translation;
                    mb.Rotation    = Quaternion.Euler(tm.rotation);
                    mb.Scale       = tm.scale;
                    mb.ComputeIfNeeded();
                    used.Add(go);
                }
            }

            // finally, we destroy the unused objects
            foreach (var go in generated.transform
                     .Cast <Transform>()
                     .Select(child => child.gameObject).Except(used))
            {
                UOUtility.Destroy(go);
            }
        }
        private void Init()
        {
            for (int i = 0; i < meshes.Count; i++)
            {
                string generatedName     = i + ". generated by " + GetType().Name;
                var    generatedTranform = transform.Find(generatedName);

                GameObject generated = generatedTranform != null ? generatedTranform.gameObject : UOUtility.Create(generatedName, gameObject,
                                                                                                                   typeof(MeshFilter),
                                                                                                                   typeof(MeshRenderer),
                                                                                                                   typeof(MeshBender));

                // some harmless bug TODO
                if (generatedList.Count < i + 1)
                {
                    generatedList.Add(generated);
                }
                else
                {
                    generatedList[i] = generated;
                }

                generatedList[i].GetComponent <MeshRenderer>().material = materials[i];

                MeshBender meshBender = generatedList[i].GetComponent <MeshBender>();

                if (meshBenders.Count < i + 1)
                {
                    meshBenders.Add(meshBender);
                }
                else
                {
                    meshBenders[i] = meshBender;
                }

                meshBenders[i] = generatedList[i].GetComponent <MeshBender>();
                spline         = GetComponent <Spline>();

                meshBenders[i].Source = SourceMesh.Build(meshes[i])
                                        .Translate(translations[i])
                                        .Rotate(Quaternion.Euler(rotations[i]))
                                        .Scale(scales[i]);
                meshBenders[i].Mode = MeshBender.FillingMode.Repeat;
                meshBenders[i].SetInterval(spline, 0);
            }

            // First mesh determines lenght of generation
            contortionLength = meshBenders[0].Source.Length * ((float)(Repeat) + 0.1f);
        }
Ejemplo n.º 6
0
        public void CreateMeshes()
        {
            UOUtility.DestroyChildren(generated);

            int i = 0;

            foreach (CubicBezierCurve curve in spline.GetCurves())
            {
                GameObject go = UOUtility.Create("SplineMesh" + i++, generated,
                                                 typeof(MeshFilter),
                                                 typeof(MeshRenderer),
                                                 typeof(MeshBender));
                go.GetComponent <MeshRenderer>().material = material;
                MeshBender mb = go.GetComponent <MeshBender>();
                mb.Source   = mesh;
                mb.Rotation = Quaternion.Euler(rotation);
                mb.Curve    = curve;
                mb.ComputeIfNeeded();
            }
        }
Ejemplo n.º 7
0
        private GameObject FindOrCreateRender(string parentName, string name)
        {
            var childTransform = generated.transform.Find(name);

            if (collider)
            {
                var parentTransform = generated.transform.Find(parentName);
                childTransform = parentTransform.Find(name);
            }
            GameObject res;

            if (childTransform == null)
            {
                res = UOUtility.Create(name,
                                       generated,
                                       typeof(MeshFilter),
                                       typeof(MeshRenderer),
                                       typeof(MeshBender));
                res.isStatic = true;
            }
            else
            {
                res = childTransform.gameObject;
            }
            res.GetComponent <MeshRenderer>().material = material;
            MeshBender mb = res.GetComponent <MeshBender>();

            mb.Source = SourceMesh.Build(mesh)
                        .Translate(translation)
                        .Rotate(Quaternion.Euler(rotation))
                        .Scale(scale);
            if (mode == MeshBender.FillingMode.CustomIntervals)
            {
                mb.SetCustomInterval(customIntervalStart, customIntervalEnd);
            }
            mb.Mode = mode;
            return(res);
        }