Exemple #1
0
        private void ReadObject(ref XmlReadState state, System.Xml.XmlReader node)
        {
            node.Read();

            var meshname = node.GetAttribute("mesh");
            var me       = meshes[meshname];
            var ob       = new ccl.Object(Client)
            {
                Transform = state.Transform, IsShadowCatcher = state.IsShadowCatcher
            };

            ob.Mesh = me;
        }
Exemple #2
0
        private void ReadMesh(ref XmlReadState state, System.Xml.XmlReader node)
        {
            node.Read();

            var P = node.GetAttribute("P");
            var UV = node.GetAttribute("UV");
            var nverts = node.GetAttribute("nverts");
            var verts = node.GetAttribute("verts");
            if(!state.Silent) Console.WriteLine("{0}", node);

            var has_uv = !string.IsNullOrEmpty(UV);

            float[] uvfloats = null;
            if (has_uv)
            {
                uvfloats = Utilities.Instance.parse_floats(UV);
            }
            var pfloats = Utilities.Instance.parse_floats(P);
            var nvertsints = Utilities.Instance.parse_ints(nverts);
            var vertsints = Utilities.Instance.parse_ints(verts);

            var ob = new ccl.Object(Client) { Transform = state.Transform };
            var me = new Mesh(Client, state.Shader);

            ob.Mesh = me;

            me.SetVerts(ref pfloats);

            var index_offset = 0;
            /* count triangles */
            var fc = nvertsints.Aggregate(0, (total, next) =>
                                                                        next == 4 ? total + 2 : total + 1);

            float[] uvs = null;
            if(has_uv) uvs = new float[fc*3*2];
            var uvoffs = 0;
            foreach (var t in nvertsints)
            {
                for (var j = 0; j < t - 2; j++)
                {
                    var v0 = vertsints[index_offset];
                    var v1 = vertsints[index_offset + j + 1];
                    var v2 = vertsints[index_offset + j + 2];

                    if (has_uv)
                    {
                        uvs[uvoffs] = uvfloats[index_offset*2];
                        uvs[uvoffs + 1] = uvfloats[index_offset*2 + 1];
                        uvs[uvoffs + 2] = uvfloats[(index_offset + j + 1)*2];
                        uvs[uvoffs + 3] = uvfloats[(index_offset + j + 1)*2 + 1];
                        uvs[uvoffs + 4] = uvfloats[(index_offset + j + 2)*2];
                        uvs[uvoffs + 5] = uvfloats[(index_offset + j + 2)*2 + 1];

                        uvoffs += 6;
                    }

                    me.AddTri((uint)v0, (uint)v1, (uint)v2, state.Shader, state.Smooth);
                }

                index_offset += t;
            }

            if (has_uv)
            {
                me.SetUvs(ref uvs);
            }
        }
Exemple #3
0
        /// <summary>
        /// Upload object changes
        /// </summary>
        public void UploadObjectChanges()
        {
            // first delete objects
            foreach (var ob in _objectDatabase.DeletedObjects)
            {
                if (ob.cob != null)
                {
                    var cob = ob.cob;
                    // deleting we do (for now?) by marking object as hidden.
                    // we *don't* clear mesh data here, since that very mesh
                    // may be used elsewhere.
                    cob.Visibility = PathRay.Hidden;
                    cob.TagUpdate();
                }
            }

            // now combine objects and meshes, creating new objects when necessary
            foreach (var ob in _objectDatabase.NewOrUpdatedObjects)
            {
                // mesh for this object id
                var mesh = _objectDatabase.FindMeshRelation(ob.meshid);

                // hmm, no mesh. Oh well, lets get on with the next
                if (mesh == null) continue;

                // see if we already have an object here.
                // update it, otherwise create new one
                var cob = _objectDatabase.FindObjectRelation(ob.obid);

                var newcob = cob == null;

                // new object, so lets create it and record necessary stuff about it
                if (newcob)
                {
                    cob = new CclObject(_renderEngine.Client);
                    _objectDatabase.RecordObjectRelation(ob.obid, cob);
                    _objectDatabase.RecordObjectIdMeshIdRelation(ob.obid, ob.meshid);
                }

                // set mesh reference and other stuff
                cob.Mesh = mesh;
                cob.Transform = ob.Transform;
                cob.IsShadowCatcher = ob.IsShadowCatcher;
                cob.Visibility = ob.Visible ? (ob.IsShadowCatcher ? PathRay.Camera : PathRay.AllVisibility): PathRay.Hidden;
                cob.TagUpdate();
            }
        }