Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool PolygonizeHierarchy(BaseObject* origin, HierarchyHelp* hh,
- VirtualObjectConnection*& desthead,
- VirtualObjectConnection*& desttail,
- BaseObject** destroot, AllocatorProc allocator) {
- // Ensure we can actually convert the object to geometry. Therefore, we
- // have to check if the object is a generator, not a spline and when it
- // is using it's input (OBJECT_INPUT flag) it must also be handled
- // seperately.
- LONG info = origin->GetInfo();
- bool isgenerator = info & OBJECT_GENERATOR;
- bool isspline = info & OBJECT_ISSPLINE;
- bool ispolygonal = info & OBJECT_POLYGONOBJECT;
- // This flag is only set in connection with OBJECT_GENERATOR
- bool isinput = info & OBJECT_INPUT;
- if (!(isgenerator && !isspline) && !ispolygonal) {
- return NULL;
- }
- // The reference to the new polygonized object is stored in this variable.
- BaseObject* new_object;
- // When the object is already a PolygonObject, we will create a copy of it.
- if (ispolygonal) {
- COPYFLAGS cloneflag = COPYFLAGS_NO_HIERARCHY | COPYFLAGS_NO_ANIMATION;
- new_object = (BaseObject*) origin->GetClone(cloneflag, NULL);
- if (!new_object) return NULL;
- // The object may have been "touched" before and may also have some
- // bit's that we don't want it to have. (E.g. BIT_ACTIVE will make
- // the object being highlighted as it was selected, although it
- // actually exists in the virtual-hierarchy of a Generator object).
- new_object->SetAllBits(0);
- }
- // Now, as we have already excluded the object being a spline or not
- // generator, we can safely obtain the internal ObjectData from the object
- // an create it's virtual objects which will also be convertex.
- else {
- ObjectData* data = (ObjectData*) origin->GetNodeData();
- new_object = data->GetVirtualObjects(origin, hh);
- if (!new_object) return NULL;
- if (!new_object->IsInstanceOf(Opolygon)) {
- // We have to create a temporary object, as after conversion,
- // we will have to free the object we've obtained by
- // ObjectData::GetVirtualObjects().
- // Note that we don't check if the object could be a spline or
- // similar, because this is done by the call to
- // PolygonizeHierarchy(). Yes, yes. It's well thought out. :)
- BaseObject* temp = NULL;
- PolygonizeHierarchy(new_object, hh, desthead, desttail, &temp,
- allocator);
- BaseObject::Free(new_object);
- new_object = temp;
- }
- }
- // The object obtained from the call to PolygonizeHierarchy() after
- // obtaining an object from the ObjectData could be NULL. ;)
- if (new_object) {
- // We will fill the value pointed by *destroot* with the current object
- // when the pointer is not NULL. Afterwards, we will set it to be NULL
- // so it's not overwritten by following calls to this function.
- if (destroot) {
- *destroot = new_object;
- destroot = NULL;
- }
- // Well, the virtual object doesn't actually have the same position
- // as the original, so we need to adjust that.
- new_object->SetMl(origin->GetMl());
- // And now comes the tricky thing about generator objects that accept
- // objects as input. If the object is an input generator, we will NOT
- // go down it's actual hierarchy recursively, because they've been
- // touched by the original generator.
- if (!isinput) {
- BaseObject* temp;
- BaseObject* new_child;
- for (temp=origin->GetDown(); temp; temp=temp->GetNext()) {
- new_child = NULL;
- PolygonizeHierarchy(temp, hh, desthead, desttail, &new_child,
- allocator);
- if (new_child) new_child->InsertUnder(new_object);
- }
- }
- // Ok, we're almost done. The last thing we will need to do, is to
- // establish the connection of the original object with the new, virtual
- // object.
- VirtualObjectConnection* new_connection = (VirtualObjectConnection*)
- allocator(sizeof(VirtualObjectConnection));
- if (!new_connection) return FALSE;
- if (!desttail) desttail = new_connection;
- else {
- desttail->next = new_connection;
- desttail = desttail->next;
- }
- if (!desthead) desthead = desttail;
- new_connection->origin = origin;
- new_connection->cache = new_object;
- new_connection->normals = NULL;
- new_connection->seqinfo = NULL;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement