123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package api
- import (
- "mats/db/model"
- "mats/db/repo"
- funcgraph "mats/funcGraph"
- "time"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- func UpdateStaticMeshComm(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetStaticMesh) (interface{}, error) {
- asset := body
- asset.UpdateTime = time.Now()
- id := asset.Id.Hex()
- asset.Id = primitive.NilObjectID
- collectionName := dbConf.AssetConf.Collection
- return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
- }
- func UpdateStaticMeshSource(apictx *ApiSession, dbConf *model.AssetDbConf, body *model.AssetStaticMesh) (interface{}, error) {
- asset := body
- asset.UpdateTime = time.Now()
- id := asset.Id.Hex()
- asset.Id = primitive.NilObjectID
- collectionName := dbConf.AssetConf.Collection
- return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
- }
- func ProcessPackage(apictx *ApiSession, dbConf *model.AssetDbConf, id string) (interface{}, error) {
- mesh := &model.AssetPackage{}
- ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
- Db: dbConf.Db.Name,
- CollectName: dbConf.AssetConf.Collection,
- Query: repo.Map{"_id": id},
- Project: []string{"source.geoms"},
- }, mesh)
- if err != nil {
- return nil, err
- }
- if !ok {
- return nil, NewError("模型已删除!")
- }
- if mesh.Source == nil || len(mesh.Source.Geoms) < 1 {
- return nil, NewError("数据模型异常!")
- }
- geom := mesh.Source.Geoms[0]
- meshUrl := ""
- if geom.File != nil {
- meshUrl = geom.File.Url
- }
- if geom.Glb != nil && len(geom.Glb.Url) > 0 {
- meshUrl = geom.Glb.Url
- }
- if len(meshUrl) < 1 {
- return nil, NewError("数据模型异常!")
- }
- err = funcgraph.OsgConvRequest(meshUrl, id, dbConf.Db.Name, dbConf.AssetConf.Collection)
- assetState := model.AssetState_Waiting
- if err != nil {
- assetState = model.AssetState_Failed
- }
- update := bson.M{"$set": bson.M{"assetState": assetState}}
- return repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.Db.Name, dbConf.AssetConf.Collection, id, update)
- }
- func ProcessPackageShadow(apictx *ApiSession, dbConf *model.AssetDbConf, id string, scale, width int32) (interface{}, error) {
- mesh := &model.AssetPackage{}
- ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
- Db: dbConf.Db.Name,
- CollectName: dbConf.AssetConf.Collection,
- Query: repo.Map{"_id": id},
- Project: []string{"source.geoms"},
- }, mesh)
- if err != nil {
- return nil, err
- }
- if !ok {
- return nil, NewError("模型已删除!")
- }
- if mesh.Source == nil || len(mesh.Source.Geoms) < 1 {
- return nil, NewError("数据模型异常!")
- }
- geom := mesh.Source.Geoms[0]
- meshUrl := ""
- if geom.File != nil {
- meshUrl = geom.File.Url
- }
- if geom.Glb != nil && len(geom.Glb.Url) > 0 {
- meshUrl = geom.Glb.Url
- }
- if len(meshUrl) < 1 {
- return nil, NewError("数据模型异常!")
- }
- err = funcgraph.CreateShadow(meshUrl, id, dbConf.Db.Name, dbConf.AssetConf.Collection, scale, width)
- return true, err
- }
|