private bool CheckOnQuaternionTag(BaseObject ob) { // Iterate over the object's tags for (BaseTag tag = ob.GetFirstTag(); tag != null; tag = tag.GetNext()) { // In their sheer wisdom, the elders of the C4D SDK decided to not have a class of its own for the quaternion tag. // Neither will the world need a constant declaration for the type... int tagType = tag.GetTypeC4D(); if (tagType == 100001740) { BaseContainer data = tag.GetData(); int ii = data.GetInt32(1001); // QUAT_INTER (from tquaterninon.h) switch (ii) { case 1002: // INTER_SLERP, "Linear" break; case 1003: // INTER_SQUAD, "Spline" break; case 1004: // INTER_LOSCH, "Losch" break; } return(true); /* * for (int i = 0, id = 0; -1 != (id = data.GetIndexId(i)); i++) * { * if (data.GetType(id) == C4dApi.DA_LONG) * { * int ii = data.GetInt32(id); * switch (ii) * { * case 1002: // INTER_SLERP, * break; * case 1003: // INTER_SQUAD, * break; * case 1004: // INTER_LOSCH, * break; * } * } * if (data.GetType(id) == C4dApi.DA_REAL) * { * double d = data.GetFloat(id); * } * else if (data.GetType(id) == C4dApi.DA_VECTOR) * { * double3 v = data.GetVector(id); * } * } */ } } return(false); }
/// <summary> /// This method tries to make the best out of C4Ds seldom relationship between objects with /// multiple materials which can or can not be restricted to polygon selections and one or more UV sets. /// But there are unhandled cases: /// Multple UV tags are not supported. Overlapping polygon selections are probably handled differently. /// The awkward side effects when changing the tags' order in C4D are not reproduced. /// </summary> /// <param name="ob"></param> /// <param name="snc"></param> private void VisitObject(BaseObject ob, SceneNodeContainer snc) { Collection <TextureTag> textureTags = new Collection <TextureTag>(); Dictionary <string, SelectionTag> selectionTags = new Dictionary <string, SelectionTag>(); UVWTag uvwTag = null; CAWeightTag weightTag = null; // SCRATCH // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt}; // snc.AddComponent(targetComponent); // Iterate over the object's tags for (BaseTag tag = ob.GetFirstTag(); tag != null; tag = tag.GetNext()) { // GeneralTag if (1036156 == tag.GetTypeC4D()) { var di = tag.GetDataInstance(); int anInt = di.GetInt32(10000); string aStr = di.GetString(10001); Logger.Debug("Found a GeneralTag with TheInt=" + anInt + " and TheString = \"" + aStr + "\""); // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt}; // snc.AddComponent(targetComponent); } // CAWeightTag - Save data to create the weight list later CAWeightTag wTag = tag as CAWeightTag; if (wTag != null) { weightTag = wTag; continue; } // TextureTag (Material - there might be more than one) TextureTag tex = tag as TextureTag; if (tex != null) { textureTags.Add(tex); continue; } // UVWTag - the texutre coordinates. We handle only one UVWTag uvw = tag as UVWTag; if (uvw != null) { if (uvwTag == null) { uvwTag = uvw; } else { Logger.Error("Object " + ob.GetName() + " contains more than one uv-coordinates-tag. Cannot handle this. Only the first texture tag will be recognized."); } continue; } // Selection tag. Only recognize the polygon selections as they might be referenced in a TextureTag SelectionTag selection = tag as SelectionTag; string selTagName = tag.GetName(); if (selection != null && selection.GetTypeC4D() == C4dApi.Tpolygonselection && !string.IsNullOrEmpty(selTagName)) // One Type and three TypeIDs - You C4D programmer guys really suck { selectionTags[selTagName] = selection; } // XPresso Tags - TBD XPressoTag xPresso = tag as XPressoTag; if (xPresso != null) { // Handle XPresso tag continue; } } TextureTag lastUnselectedTag = null; Collection <KeyValuePair <SelectionTag, TextureTag> > texSelList = new Collection <KeyValuePair <SelectionTag, TextureTag> >(); // Abused KeyValuePair. Should have been Pair... // Now iterate over the textureTags foreach (TextureTag texture in textureTags) { string selRef = ""; using (BaseContainer texData = texture.GetData()) { selRef = texData.GetString(C4dApi.TEXTURETAG_RESTRICTION); } if (string.IsNullOrEmpty(selRef)) { // This material is not restricted to any polygon selection lastUnselectedTag = texture; } else { SelectionTag sel; if (selectionTags.TryGetValue(selRef, out sel)) { texSelList.Add(new KeyValuePair <SelectionTag, TextureTag>(sel, texture)); } } } // At this point we have the last texture tag not restricted to a seletion. This will become the Material of this FuseeObjectContainer // no matter if this object contains geometry or not if (lastUnselectedTag != null) { AddComponent(snc, GetMaterial(lastUnselectedTag)); } // Further processing only needs to take place if the object contains any geometry at all. PolygonObject polyOb = ob as PolygonObject; // Check whether the object contains an unpolygonized mesh if (polyOb == null) { polyOb = ob.GetCache(null) as PolygonObject; } if (polyOb != null) { float3[] normalOb = polyOb.CreatePhongNormals(); // Initialize the polygon index set int nPolys = polyOb.GetPolygonCount(); HashSet <int> polyInxs = new HashSet <int>(); for (int i = 0; i < nPolys; i++) { polyInxs.Add(i); } foreach (KeyValuePair <SelectionTag, TextureTag> texSelItem in texSelList) { HashSet <int> polyInxsSubset = new HashSet <int>(); BaseSelect bs = texSelItem.Key.GetBaseSelect(); int nSegments = bs.GetSegments(); for (int iSeg = 0; iSeg < nSegments; iSeg++) { int from = bs.GetRangeA(iSeg); int to = bs.GetRangeB(iSeg); for (int iSel = from; iSel <= to; iSel++) { polyInxs.Remove(iSel); polyInxsSubset.Add(iSel); } } // Now generate Polygons for this subset if (polyInxsSubset.Count > 0) { if (snc.Children == null) { snc.Children = new List <SceneNodeContainer>(); } SceneNodeContainer subSnc = new SceneNodeContainer(); AddComponent(subSnc, new TransformComponent() { Translation = new float3(0, 0, 0), Rotation = new float3(0, 0, 0), Scale = new float3(1, 1, 1) }); AddComponent(subSnc, GetMaterial(texSelItem.Value)); subSnc.Name = snc.Name + "_" + texSelItem.Key.GetName(); AddComponent(subSnc, GetMesh(polyOb, normalOb, uvwTag, polyInxsSubset)); _weightManager.AddWeightData(subSnc, polyOb, weightTag, polyInxsSubset); snc.Children.Add(subSnc); } } // The remaining polygons directly go into the original mesh AddComponent(snc, GetMesh(polyOb, normalOb, uvwTag, polyInxs)); _weightManager.AddWeightData(snc, polyOb, weightTag, polyInxs); } else if (ob.GetTypeC4D() == C4dApi.Olight) { using (BaseContainer lightData = ob.GetData()) // Just for debugging purposes for (int i = 0, id = 0; -1 != (id = lightData.GetIndexId(i)); i++) { if (lightData.GetTypeC4D(id) == C4dApi.DA_LONG) { int iii = lightData.GetInt32(id); } if (lightData.GetTypeC4D(id) == C4dApi.DA_REAL) { double d = lightData.GetFloat(id); } else if (lightData.GetTypeC4D(id) == C4dApi.DA_VECTOR) { double3 v = lightData.GetVector(id); } } ; } }