Exemple #1
0
        public EffectModel(Context context, Neutrino.EffectModel effectModel)
        {
            context_             = context;
            neutrinoEffectModel_ = effectModel;

            uint numTextures = (uint)effectModel.textures().Length;

            textures_ = new Texture[numTextures];
            for (uint texIndex = 0; texIndex < numTextures; ++texIndex)
            {
                textures_[texIndex] = new Texture(context_.texturesBasePath() + effectModel.textures()[texIndex]);
            }
        }
Exemple #2
0
        private void initNeutrino()
        {
            //Debug.Log("initNeutrino()");

            neutrinoEffectModel_ = createModel();

            Mesh mesh = new Mesh();

            gameObject.GetComponent <MeshFilter>().mesh = mesh;
            renderBuffer_ = new NeutrinoRenderBuffer(mesh);

            neutrinoEffect_ = new Neutrino.Effect(neutrinoEffectModel_, renderBuffer_,
                                                  simulateInWorldSpace ?
                                                  Neutrino._math.vec3_(gameObject.transform.position.x / gameObject.transform.localScale.x,
                                                                       gameObject.transform.position.y / gameObject.transform.localScale.y,
                                                                       gameObject.transform.position.z / gameObject.transform.localScale.z) :
                                                  Neutrino._math.vec3_(0, 0, 0),
                                                  simulateInWorldSpace ?
                                                  Neutrino._math.quat_(transform.rotation.w, transform.rotation.x, transform.rotation.y, transform.rotation.z) :
                                                  Neutrino._math.quat_(1, 0, 0, 0));

            deserializeToEffect();

            // preparing materials
            {
                string[]      textures     = neutrinoEffectModel_.textures();
                RenderStyle[] renderStyles = neutrinoEffectModel_.renderStyles();

                materials_ = new Material[renderStyles.Length];

                for (int i = 0; i < renderStyles.Length; ++i)
                {
                    Material material;

                    switch (neutrinoEffectModel_.materials()[renderStyles[i].material_])
                    {
                    default:
                        material = new Material(NeutrinoContext.Instance.shaderNormal());
                        break;

                    case Neutrino.RenderMaterial.Add:
                        material = new Material(NeutrinoContext.Instance.shaderAdd());
                        break;

                    case Neutrino.RenderMaterial.Multiply:
                        material = new Material(NeutrinoContext.Instance.shaderMultiply());
                        break;
                    }

                    string filename = Path.GetFileNameWithoutExtension(
                        textures[renderStyles[i].textureIndex_[0]]);

                    if (string.IsNullOrEmpty(filename))
                    {
                        Debug.LogError("Texture file name is empty or incorrect " +
                                       textures[renderStyles[i].textureIndex_[0]]);
                        return;
                    }

                    Texture texture = Resources.Load(filename) as Texture;
                    if (texture == null)
                    {
                        Debug.LogError("Unable to load texture from Resources: " + filename);
                        return;
                    }

                    material.name = filename;
                    material.SetTexture("_MainTex", texture);

                    materials_[i] = material;
                }
            }

            neutrinoInited_ = true;

                        #if UNITY_EDITOR
            lastFrameTime_ = Time.realtimeSinceStartup;
                        #else
            lastFrameTime_ = Time.time;
                        #endif

                        #if UNITY_EDITOR
            EditorApplication.update += Update;
                        #endif
        }