Example #1
0
 public Model(obj_data obj, PassthroughGP passGP, TopologyIP topoIP, MaterialGroup matg, Object3D parent)
     : this(obj.object_name, (uint)obj.verts.Count, (uint)obj.faces.Count, passGP, topoIP, matg, parent)
 {
 }
Example #2
0
        public override void Execute(ScriptState state)
        {
            var source = state.Data.SectionsOfType <S.Model>()
                         .Where(i => i.Name == Source)
                         .FirstOrDefault();

            if (source == null)
            {
                throw new Exception($"Source model {Source} not found");
            }
            if (source.version != 3)
            {
                throw new Exception($"Can't duplicate non-v3 model {Source}");
            }

            var destinationExists = state.Data.SectionsOfType <S.Model>()
                                    .Any(i => i.Name == Destination);

            if (destinationExists)
            {
                throw new Exception($"Destination model {Destination} not found");
            }

            S.TopologyIP    newTopoIp;
            S.PassthroughGP newPgp;
            if (Instance)
            {
                newPgp    = source.PassthroughGP;
                newTopoIp = source.TopologyIP;
            }
            else
            {
                var newGeom = source.PassthroughGP.Geometry.Clone();
                newGeom.HashName = new HashName($"{Destination}.Geometry");

                var newTopology = source.TopologyIP.Topology.Clone(Destination);

                newPgp    = new S.PassthroughGP(newGeom, newTopology);
                newTopoIp = new S.TopologyIP(newTopology);

                state.Data.AddSection(newGeom);
                state.Data.AddSection(newTopology);
                state.Data.AddSection(newPgp);
                state.Data.AddSection(newTopoIp);
            }

            S.MaterialGroup newMatGroup = source.MaterialGroup;
            if (NewMaterials != null)
            {
                newMatGroup = new S.MaterialGroup(NewMaterials.Select(i =>
                {
                    var nm = new S.Material(i);
                    state.Data.AddSection(nm);
                    return(nm);
                }));
            }

            var newModel = new S.Model(Destination,
                                       (uint)newTopoIp.Topology.facelist.Count,
                                       newPgp.Geometry.vert_count,
                                       newPgp, newTopoIp, newMatGroup, source.Parent);

            newModel.version = source.version;
            newModel.RenderAtoms.AddRange(source.RenderAtoms.Select(i => i.Clone()));
            newModel.lightset_ID       = source.lightset_ID;
            newModel.properties_bitmap = source.properties_bitmap;
            newModel.unknown13         = source.unknown13;
            newModel.SkinBones         = source.SkinBones;

            newModel.UpdateBounds();

            state.Data.AddSection(newModel);
        }
Example #3
0
        public Model(string object_name, uint triangleCount, uint vertexCount, PassthroughGP passGP, TopologyIP topoIP, MaterialGroup matg, Object3D parent)
            : base(object_name, parent)
        {
            this.size = 0;
            // TODO: Get rid of all referring to things by section ID outside of read/write of model files so we don't have to do this.
            SectionId = (uint)object_name.GetHashCode();

            this.version       = 3;
            this.PassthroughGP = passGP;
            this.TopologyIP    = topoIP;
            this.RenderAtoms   = new List <RenderAtom>();
            RenderAtom nmi = new RenderAtom
            {
                BaseVertex          = 0,
                TriangleCount       = triangleCount,
                BaseIndex           = 0,
                GeometrySliceLength = vertexCount,
                MaterialId          = 0
            };

            this.RenderAtoms.Add(nmi);

            //this.unknown9 = 0;
            this.MaterialGroup     = matg;
            this.lightset_ID       = 0;
            this.properties_bitmap = 0;
            this.BoundingRadius    = 1;
            this.unknown13         = 6;
            this.SkinBones         = null;
        }